Saturday 8 October 2022

Atlas Client: Update glossary term by id

AtlasClientV2#updateGlossaryTermByGuid method is used to update the glossary term by id.

 

Signature

public AtlasGlossaryTerm updateGlossaryTermByGuid(String termGuid, AtlasGlossaryTerm glossaryTerm) throws AtlasServiceException

 

Example

atlasGlossaryTerm = atlasClient.updateGlossaryTermByGuid(termId, atlasGlossaryTerm);

 

Before Updating

 


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);
	}
}

 

UpdateGlossaryTermById.java

package com.sample.app.glossary;

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 UpdateGlossaryTermById {
  public static void main(String[] args) throws AtlasServiceException, JsonProcessingException {
    AtlasClientV2 atlasClient = new AtlasClientV2(new String[] { "http://localhost:21000" },
        new String[] { "admin", "admin" });

    String termId = "cd2dbbc5-0440-477e-a6e6-175eb13e3d46";

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

    System.out.println("\nUpdating the name of glossary term\n");
    atlasGlossaryTerm.setName(atlasGlossaryTerm.getName() + "_updated");

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

  }

}

Output

atlasGlossaryTerm : 
{
  "guid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
  "qualifiedName" : "term1@myGlosary3",
  "name" : "term1",
  "shortDescription" : "term1...",
  "longDescription" : "term1...........",
  "classifications" : [ {
    "typeName" : "sensitive_data",
    "attributes" : {
      "durationInDays" : 8
    },
    "entityGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "entityStatus" : "ACTIVE",
    "propagate" : true,
    "validityPeriods" : [ ],
    "removePropagationsOnEntityDelete" : false
  } ],
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "607768b1-d47a-4659-aa63-9acc8d175c80"
  },
  "assignedEntities" : [ {
    "guid" : "95731109-eb31-44e9-896e-60652e119312",
    "typeName" : "DemoType7",
    "entityStatus" : "ACTIVE",
    "displayText" : "CreateEntities_DEMO1",
    "relationshipType" : "AtlasGlossarySemanticAssignment",
    "relationshipGuid" : "981b2432-c033-42f5-bf37-07e4c3e41fad",
    "relationshipStatus" : "ACTIVE",
    "relationshipAttributes" : {
      "typeName" : "AtlasGlossarySemanticAssignment",
      "attributes" : {
        "expression" : null,
        "createdBy" : null,
        "steward" : null,
        "confidence" : null,
        "description" : null,
        "source" : null,
        "status" : null
      }
    }
  }, {
    "guid" : "e63cb343-675e-4cde-9d49-ceb43fb1aacb",
    "typeName" : "DemoType6",
    "entityStatus" : "ACTIVE",
    "displayText" : "AttributeDefaultValue_DEMO1",
    "relationshipType" : "AtlasGlossarySemanticAssignment",
    "relationshipGuid" : "c02d605e-6165-448e-a77c-0df916781fb0",
    "relationshipStatus" : "ACTIVE",
    "relationshipAttributes" : {
      "typeName" : "AtlasGlossarySemanticAssignment",
      "attributes" : {
        "expression" : null,
        "createdBy" : null,
        "steward" : null,
        "confidence" : null,
        "description" : null,
        "source" : null,
        "status" : null
      }
    }
  } ],
  "categories" : [ {
    "categoryGuid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
    "relationGuid" : "c1a5772f-290e-4696-a80c-5cc5a69b9bdd",
    "displayText" : "category1"
  } ],
  "seeAlso" : [ {
    "termGuid" : "b480660d-d038-41bd-b2c1-076adedd2421",
    "relationGuid" : "d807b7c7-f243-4541-94c5-8555bd689cfa",
    "displayText" : "term4"
  }, {
    "termGuid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
    "relationGuid" : "a6b631ef-3b5b-4260-a069-5368ab39ad78",
    "displayText" : "term2"
  } ],
  "glossaryTermHeader" : {
    "termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "qualifiedName" : "term1@myGlosary3"
  }
}

Updating the name of glossary term


atlasGlossaryTerm : 
{
  "guid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
  "qualifiedName" : "term1@myGlosary3",
  "name" : "term1_updated",
  "shortDescription" : "term1...",
  "longDescription" : "term1...........",
  "classifications" : [ {
    "typeName" : "sensitive_data",
    "attributes" : {
      "durationInDays" : 8
    },
    "entityGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "entityStatus" : "ACTIVE",
    "propagate" : true,
    "validityPeriods" : [ ],
    "removePropagationsOnEntityDelete" : false
  } ],
  "anchor" : {
    "glossaryGuid" : "844a3e1a-110c-4bef-91bf-622dc1eab3e7",
    "relationGuid" : "607768b1-d47a-4659-aa63-9acc8d175c80"
  },
  "assignedEntities" : [ {
    "guid" : "95731109-eb31-44e9-896e-60652e119312",
    "typeName" : "DemoType7",
    "entityStatus" : "ACTIVE",
    "displayText" : "CreateEntities_DEMO1",
    "relationshipType" : "AtlasGlossarySemanticAssignment",
    "relationshipGuid" : "981b2432-c033-42f5-bf37-07e4c3e41fad",
    "relationshipStatus" : "ACTIVE",
    "relationshipAttributes" : {
      "typeName" : "AtlasGlossarySemanticAssignment",
      "attributes" : {
        "expression" : null,
        "createdBy" : null,
        "steward" : null,
        "confidence" : null,
        "description" : null,
        "source" : null,
        "status" : null
      }
    }
  }, {
    "guid" : "e63cb343-675e-4cde-9d49-ceb43fb1aacb",
    "typeName" : "DemoType6",
    "entityStatus" : "ACTIVE",
    "displayText" : "AttributeDefaultValue_DEMO1",
    "relationshipType" : "AtlasGlossarySemanticAssignment",
    "relationshipGuid" : "c02d605e-6165-448e-a77c-0df916781fb0",
    "relationshipStatus" : "ACTIVE",
    "relationshipAttributes" : {
      "typeName" : "AtlasGlossarySemanticAssignment",
      "attributes" : {
        "expression" : null,
        "createdBy" : null,
        "steward" : null,
        "confidence" : null,
        "description" : null,
        "source" : null,
        "status" : null
      }
    }
  } ],
  "categories" : [ {
    "categoryGuid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
    "relationGuid" : "c1a5772f-290e-4696-a80c-5cc5a69b9bdd",
    "displayText" : "category1"
  } ],
  "seeAlso" : [ {
    "termGuid" : "b480660d-d038-41bd-b2c1-076adedd2421",
    "relationGuid" : "d807b7c7-f243-4541-94c5-8555bd689cfa",
    "displayText" : "term4"
  }, {
    "termGuid" : "8d0451be-bfe9-497c-aae9-f1892b156c94",
    "relationGuid" : "a6b631ef-3b5b-4260-a069-5368ab39ad78",
    "displayText" : "term2"
  } ],
  "glossaryTermHeader" : {
    "termGuid" : "cd2dbbc5-0440-477e-a6e6-175eb13e3d46",
    "qualifiedName" : "term1@myGlosary3"
  }
}

After Updation




  

Previous                                                    Next                                                    Home

No comments:

Post a Comment