AtlasClient#partialUpdateCategoryByGuid method is used to do patch update on Atlas glossary category.
Signature
public AtlasGlossaryCategory partialUpdateCategoryByGuid(String categoryGuid, Map<String, String> attributes) throws AtlasServiceException
Below snippet update the long description of category1.
Map<String, String> attributes = new HashMap<>();
attributes.put("longDescription", "Patch updating this category long descriptions to showcase the demo");
atlasGlossaryCategory = atlasClient.partialUpdateCategoryByGuid(categoryId, attributes);
Find the below working application.
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);
}
}
PatchUpdateOfAtlasCategory.java
package com.sample.app.glossary;
import java.util.HashMap;
import java.util.Map;
import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.sample.app.util.JsonUtil;
public class PatchUpdateOfAtlasCategory {
public static void main(String[] args) throws AtlasServiceException, JsonProcessingException {
AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
new String[] { "admin", "admin" });
String categoryId = "80e199fb-f924-4470-adc1-8227b5650f6c";
AtlasGlossaryCategory atlasGlossaryCategory = atlasClient.getGlossaryCategory(categoryId);
System.out.println("atlasGlossaryCategory : \n" + JsonUtil.prettyPrintJson(atlasGlossaryCategory));
System.out.println("\nUpdating the long description of atlasGlossaryCategoryn");
Map<String, String> attributes = new HashMap<>();
attributes.put("longDescription", "Patch updating this category long descriptions to showcase the demo");
atlasGlossaryCategory = atlasClient.partialUpdateCategoryByGuid(categoryId, attributes);
System.out.println("\nAfter updation atlasGlossaryTerm : \n" + JsonUtil.prettyPrintJson(atlasGlossaryCategory));
}
}
Output
atlasGlossaryCategory :
{
"guid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
"qualifiedName" : "category1@myGlosary3",
"name" : "category1",
"shortDescription" : "category1...",
"longDescription" : "Category to demo the client apis",
"anchor" : {
"glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
"relationGuid" : "c9e00acf-17ce-4e06-b570-3c47a05dedb3"
},
"terms" : [ {
"termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
"relationGuid" : "c1a5772f-290e-4696-a80c-5cc5a69b9bdd",
"displayText" : "term1_updated"
} ]
}
Updating the long description of atlasGlossaryCategoryn
After updation atlasGlossaryTerm :
{
"guid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
"qualifiedName" : "category1@myGlosary3",
"name" : "category1",
"shortDescription" : "category1...",
"longDescription" : "Patch updating this category long descriptions to showcase the demo",
"anchor" : {
"glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
"relationGuid" : "c9e00acf-17ce-4e06-b570-3c47a05dedb3"
},
"terms" : [ {
"termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
"relationGuid" : "c1a5772f-290e-4696-a80c-5cc5a69b9bdd",
"displayText" : "term1_updated"
} ]
}
After updation
Previous Next Home
No comments:
Post a Comment