Saturday, 8 October 2022

Atlas Client: Partial or patch update of term by id

AtlasClientV2#partialUpdateTermByGuid method is used to do partial or patch update of term by id.

 

Signature

public AtlasGlossaryTerm partialUpdateTermByGuid(String termGuid, Map<String, String> attributes) throws AtlasServiceException

 

Before updation.

 


Below snippet update the long description of term2.

Map<String, String> attributes = new HashMap<>();
attributes.put("longDescription", "term2 is used for demo purpose");
atlasGlossaryTerm = atlasClient.partialUpdateTermByGuid(termId, 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);
	}
}

PatchUpdateGlossaryTermById.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.AtlasGlossaryTerm;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.sample.app.util.JsonUtil;

public class PatchUpdateGlossaryTermById {

  public static void main(String[] args) throws AtlasServiceException, JsonProcessingException {
    AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
        new String[] { "admin", "admin" });

    String termId = "8d0451be-bfe9-497c-aae9-f1892b156c94";

    AtlasGlossaryTerm atlasGlossaryTerm = atlasClient.getGlossaryTerm(termId);
    System.out.println("atlasGlossaryTerm : \n" + JsonUtil.prettyPrintJson(atlasGlossaryTerm));

    System.out.println("\nUpdating the long description of glossary term\n");
    Map<String, String> attributes = new HashMap<>();
    attributes.put("longDescription", "term2 is used for demo purpose");

    atlasGlossaryTerm = atlasClient.partialUpdateTermByGuid(termId, attributes);
    System.out.println("\natlasGlossaryTerm : \n" + JsonUtil.prettyPrintJson(atlasGlossaryTerm));

  }
}

Output

atlasGlossaryTerm : 
{
  "guid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
  "qualifiedName" : "term2@myGlosary3",
  "name" : "term2",
  "shortDescription" : "term2...",
  "longDescription" : "term2......",
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "8fe3ae77-0a42-42a5-8230-5a1c954b819b"
  },
  "categories" : [ {
    "categoryGuid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
    "relationGuid" : "aa82b016-39bb-40ab-83fc-aa7f14c17e5a",
    "displayText" : "category1"
  } ],
  "seeAlso" : [ {
    "termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "relationGuid" : "a6b631ef-3b5b-4260-a069-5368ab39ad78",
    "displayText" : "term1_updated"
  } ],
  "glossaryTermHeader" : {
    "termGuid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
    "qualifiedName" : "term2@myGlosary3"
  }
}

Updating the long description of glossary term


atlasGlossaryTerm : 
{
  "guid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
  "qualifiedName" : "term2@myGlosary3",
  "name" : "term2",
  "shortDescription" : "term2...",
  "longDescription" : "term2 is used for demo purpose",
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "8fe3ae77-0a42-42a5-8230-5a1c954b819b"
  },
  "categories" : [ {
    "categoryGuid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
    "relationGuid" : "aa82b016-39bb-40ab-83fc-aa7f14c17e5a",
    "displayText" : "category1"
  } ],
  "seeAlso" : [ {
    "termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "relationGuid" : "a6b631ef-3b5b-4260-a069-5368ab39ad78",
    "displayText" : "term1_updated"
  } ],
  "glossaryTermHeader" : {
    "termGuid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
    "qualifiedName" : "term2@myGlosary3"
  }
}

After updation



  

Previous                                                    Next                                                    Home

No comments:

Post a Comment