Friday 29 July 2022

Atlas Client: Get the classification by id

AtlasClientV2#getClassificationDefByGuid() return the classification associated with the id.

 

Example

AtlasClassificationDef atlasClassificationDef = atlasClient.getClassificationDefByGuid("d71e4578-3e55-4a86-ae04-c9c971ee0420");

 

Find the below working application.

 

Create atlas-application.properties file under src/main/resources folder.

 

atlas-application.properties

 

atlas.client.readTimeoutMSecs=30000
atlas.client.connectTimeoutMSecs=30000

Define JsonUtil, GetTheClassificationById classes.

 

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

GetTheClassificationById.java

package com.sample.app.classifications;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.typedef.AtlasClassificationDef;

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

public class GetTheClassificationById {

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

    AtlasClassificationDef atlasClassificationDef = atlasClient
        .getClassificationDefByGuid("d71e4578-3e55-4a86-ae04-c9c971ee0420");

    if (atlasClassificationDef == null) {
      System.out.println("No classification found");
      System.exit(1);
    }
    System.out.println(JsonUtil.prettyPrintJson(atlasClassificationDef));
  }

}

Output

{
  "category" : "CLASSIFICATION",
  "guid" : "d71e4578-3e55-4a86-ae04-c9c971ee0420",
  "createdBy" : "admin",
  "updatedBy" : "admin",
  "createTime" : 1644834992198,
  "updateTime" : 1644834992198,
  "version" : 1,
  "name" : "sensitive_data",
  "description" : "Entities with sensitive data can classified as sensitive",
  "typeVersion" : "1.0",
  "attributeDefs" : [ {
    "name" : "durationInDays",
    "typeName" : "int",
    "isOptional" : false,
    "cardinality" : "SINGLE",
    "valuesMinCount" : 1,
    "valuesMaxCount" : 1,
    "isUnique" : false,
    "isIndexable" : false,
    "includeInNotification" : false,
    "defaultValue" : "12",
    "searchWeight" : -1
  } ],
  "superTypes" : [ ],
  "entityTypes" : [ ],
  "subTypes" : [ ]
}

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment