Wednesday, 19 October 2022

Atlas Client: Get entities assigned with a term

AtlasClientV2#getEntitiesAssignedWithTerm method is used to get the entities attached with given term.

 

Signature

public List<AtlasRelatedObjectId> getEntitiesAssignedWithTerm(String termGuid, String sortByAttribute, int limit, int offset) throws AtlasServiceException

 

Example

List<AtlasRelatedObjectId> entitiesAssignedToThisTerm = atlasClient.getEntitiesAssignedWithTerm(termId, null, 10, 0);



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

 

GetEntitiesAssignedWithGivenTerm.java

package com.sample.app.glossary;

import java.util.List;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.instance.AtlasRelatedObjectId;

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

public class GetEntitiesAssignedWithGivenTerm {

  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";

    List<AtlasRelatedObjectId> entitiesAssignedToThisTerm = atlasClient.getEntitiesAssignedWithTerm(termId, null,
        10, 0);

    System.out.println(JsonUtil.prettyPrintJson(entitiesAssignedToThisTerm));
  }

}

 

Output

[ {
  "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
    }
  }
} ]

 



Previous                                                    Next                                                    Home

No comments:

Post a Comment