Thursday 28 July 2022

Atlas client: get the classification definition by name

This is continuation to my previous post. In the previous post, I explained how to create a new classification. In this post, I am going to explain how to get the classification definition by name.

 

AtlasClientV2#getClassificationDefByName() method is used to get the classification definition by name.

 

Example

AtlasClassificationDef atlasClassificationDef = atlasClient.getClassificationDefByName("sensitive_data");

 

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

 

GetTheClassificationByName.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 GetTheClassificationByName {

  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.getClassificationDefByName("sensitive_data");

    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