Monday 26 September 2022

Atlas Client: Get glossary category headers in a glossary by glossary id

AtlasClientV2#getGlossaryCategoryHeaders method return the category headers in a glossary.

 

Signature

public List<AtlasRelatedCategoryHeader> getGlossaryCategoryHeaders(String glossaryGuid, String sortByAttribute, int limit, int offset) throws AtlasServiceException

 

Example

List<AtlasRelatedCategoryHeader> glossaryCategoryHeaders = atlasClient.getGlossaryCategoryHeaders(glossaryId, 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);
	}
}

GetGlossaryCategoryHeadersInAGlossary.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.glossary.relations.AtlasRelatedCategoryHeader;

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

public class GetGlossaryCategoryHeadersInAGlossary {

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

    String glossaryId = "844a3e1a-110c-4bef-91bf-622dc1eab3e7";

    List<AtlasRelatedCategoryHeader> glossaryCategoryHeaders = atlasClient.getGlossaryCategoryHeaders(glossaryId, null, 10, 0);

    if (glossaryCategoryHeaders == null) {
      System.out.println("Glossary categories not exists");
    } else {
      System.out.println("Glossary categories : \n" + JsonUtil.prettyPrintJson(glossaryCategoryHeaders));
    }

  }

}

Output

Glossary categories : 
[ {
  "categoryGuid" : "80e199fb-f924-4470-adc1-8227b5650f6c",
  "relationGuid" : "c9e00acf-17ce-4e06-b570-3c47a05dedb3",
  "displayText" : "category1"
} ]


Previous                                                    Next                                                    Home

No comments:

Post a Comment