Sunday 31 July 2022

Atlas Client: Get the classification associated with an entity

If you have an entity id, you can get the classifications associated with the entity using AtlasClientV2#getClassifications() method.

 


 

For example, there are two classifications ‘sensitive’ and ‘classified’ are attached to the entity products.

 

Below snippet is used to query all the classification of the entity by id.

 

Example

AtlasClassifications classifications = atlasClient.getClassifications(entityGuid);

List<AtlasClassification> entityClassifications = classifications.getList();
for (AtlasClassification atlasClassification : entityClassifications) {
  System.out.println(atlasClassification.getTypeName());
}

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 GetAllTheEntityClassifications class.

 

GetAllTheEntityClassifications.java

package com.sample.app.classifications;

import java.util.List;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;

import com.fasterxml.jackson.core.JsonProcessingException;

public class GetAllTheEntityClassifications {

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

    String entityGuid = "2b4cb4f9-b03e-4425-92de-8f1fc6c7e3aa";

    AtlasClassifications classifications = atlasClient.getClassifications(entityGuid);

    List<AtlasClassification> entityClassifications = classifications.getList();
    for (AtlasClassification atlasClassification : entityClassifications) {
      System.out.println(atlasClassification.getTypeName());
    }
  }

}

Output

sensitive_data
classified


Previous                                                    Next                                                    Home

No comments:

Post a Comment