'createGlossaryCategory' and 'createGlossaryCategories' method is used to create a glossary category.
Signature
public AtlasGlossaryCategory createGlossaryCategory(AtlasGlossaryCategory glossaryCategory) throws AtlasServiceException
public List<AtlasGlossaryCategory> createGlossaryCategories(List<AtlasGlossaryCategory> glossaryCategories) throws AtlasServiceException
Example
AtlasGlossaryCategory glossaryCategory = new AtlasGlossaryCategory();
glossaryCategory.setName("myGlosary2_category1");
glossaryCategory.setShortDescription("Demo category");
glossaryCategory.setLongDescription("Demo Category....");
AtlasGlossaryHeader atlasGlossaryHeader = new AtlasGlossaryHeader();
atlasGlossaryHeader.setGlossaryGuid(persistedGlossary.getGuid());
glossaryCategory.setAnchor(atlasGlossaryHeader);
AtlasGlossaryCategory persistedGlossaryCategory = atlasClient.createGlossaryCategory(glossaryCategory);
Create atlas-application.properties file under src/main/resources folder.
atlas-application.properties
atlas.client.readTimeoutMSecs=30000 atlas.client.connectTimeoutMSecs=30000
JsonUtil.java
package com.sample.app.util;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
public class JsonUtil {
public static String marshal(Object obj) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(obj);
}
public static <T> T unmarshal(Class<T> clazz, String json)
throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
return (T) mapper.readValue(json, clazz);
}
public static String prettyPrintJson(Object obj) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
return mapper.writeValueAsString(obj);
}
}
CreateGlossaryCategory.java
package com.sample.app.glossary;
import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.glossary.AtlasGlossary;
import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
import org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.sample.app.util.JsonUtil;
public class CreateGlossaryCategory {
public static void main(String[] args) throws AtlasServiceException, JsonProcessingException {
AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
new String[] { "admin", "admin" });
AtlasGlossary atlasGlossary = new AtlasGlossary();
atlasGlossary.setName("myGlosary2");
atlasGlossary.setShortDescription("Demo Glossary");
atlasGlossary.setLongDescription("Demo GLossary.......");
AtlasGlossary persistedGlossary = atlasClient.createGlossary(atlasGlossary);
System.out.println("Glossary : \n" + JsonUtil.prettyPrintJson(persistedGlossary));
AtlasGlossaryCategory glossaryCategory = new AtlasGlossaryCategory();
glossaryCategory.setName("myGlosary2_category1");
glossaryCategory.setShortDescription("Demo category");
glossaryCategory.setLongDescription("Demo Category....");
AtlasGlossaryHeader atlasGlossaryHeader = new AtlasGlossaryHeader();
atlasGlossaryHeader.setGlossaryGuid(persistedGlossary.getGuid());
glossaryCategory.setAnchor(atlasGlossaryHeader);
AtlasGlossaryCategory persistedGlossaryCategory = atlasClient.createGlossaryCategory(glossaryCategory);
System.out.println("Category : \n" + JsonUtil.prettyPrintJson(persistedGlossaryCategory));
}
}
Output
Glossary :
{
"guid" : "11611ec8-c647-4954-a0eb-93c87031f7f4",
"qualifiedName" : "myGlosary2",
"name" : "myGlosary2",
"shortDescription" : "Demo Glossary",
"longDescription" : "Demo GLossary......."
}
Category :
{
"guid" : "8e8ae211-776e-4314-b509-ff16331d4acb",
"qualifiedName" : "myGlosary2_category1@myGlosary2",
"name" : "myGlosary2_category1",
"shortDescription" : "Demo category",
"longDescription" : "Demo Category....",
"anchor" : {
"glossaryGuid" : "11611ec8-c647-4954-a0eb-93c87031f7f4",
"relationGuid" : "b34b2fd7-c65b-463e-9a89-693bd6a200e0"
}
}
You can confirm the same from Atlas UI.
Previous Next Home

No comments:
Post a Comment