Friday, 2 September 2022

Atlas client: Create glossary

AtlasClientV2 provides 'createGlossary' method to create a glossary.

 

Signature

public AtlasGlossary createGlossary(AtlasGlossary glossary) throws AtlasServiceException

 

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

 

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

 

CreateGlossary.java

package com.sample.app.glossary;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.glossary.AtlasGlossary;

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

public class CreateGlossary {

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

		AtlasGlossary atlasGlossary = new AtlasGlossary();
		atlasGlossary.setName("myGlosary1");
		atlasGlossary.setShortDescription("Demo Glossary");
		atlasGlossary.setLongDescription("Demo GLossary.......");

		AtlasGlossary persistedGlossary = atlasClient.createGlossary(atlasGlossary);

		System.out.println(JsonUtil.prettyPrintJson(persistedGlossary));

	}
}

Output

{
  "guid" : "c71a18b9-9f24-4451-8acc-a9a4d55cf1a0",
  "qualifiedName" : "myGlosary1",
  "name" : "myGlosary1",
  "shortDescription" : "Demo Glossary",
  "longDescription" : "Demo GLossary......."
}

You can confirm the same by login to Atlas UI.


      Create a glossary category
      Create glossary term
      Get All glossaries
      Get the glossary by guid
      Get Detailed Glossary including terms and categories
      Get glossary term by guid
      Get the terms in a glossary
      get term headers in a glossary
      Get glossary category by id
      Get all the categories in a glossary by glossary id
      Get glossary category headers in a glossary by glossary id
      Get terms in a category
      Get related terms of this term
      Update glossary by id
      Partial or patch update of glossary by id
      Update glossary term by id
      Partial or patch update of term by id
      Update glossary category by id
      Partial or patch update of glossary category
      Delete glossary by id
      Delete glossary term by id
      Delete glossary category by id
      Get entities assigned with a term
      Assign term to entities
      detach or remove term from an entity

Previous                                                    Next                                                    Home

No comments:

Post a Comment