Thursday 20 October 2022

Atlas Client: Assign term to entities

AtlasClientV2#assignTermToEntities method is used to assign term to entities.

 

Signature

public void assignTermToEntities(String termGuid, List<AtlasRelatedObjectId> relatedObjectIds) throws AtlasServiceException

 

Example

String termId = "cd2dbbc5-0440-477e-a6e6-175eb13e3d46";

String objectId = "4eea7a7e-c59b-46ee-b6e9-a998251dada2";
String typeName = "DemoType16";

AtlasRelatedObjectId atlasRelatedObjectId = new AtlasRelatedObjectId();
atlasRelatedObjectId.setGuid(objectId);
atlasRelatedObjectId.setTypeName(typeName);

List<AtlasRelatedObjectId> relatedObjectIds = Arrays.asList(atlasRelatedObjectId);

 


Find the below working application.

 

atlas-application.properties

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

AssignTermToEntities.java

package com.sample.app.glossary;

import java.util.Arrays;
import java.util.List;

import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.model.instance.AtlasRelatedObjectId;

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

		String termId = "cd2dbbc5-0440-477e-a6e6-175eb13e3d46";

		String objectId = "4eea7a7e-c59b-46ee-b6e9-a998251dada2";
		String typeName = "DemoType16";

		AtlasRelatedObjectId atlasRelatedObjectId = new AtlasRelatedObjectId();
		atlasRelatedObjectId.setGuid(objectId);
		atlasRelatedObjectId.setTypeName(typeName);

		List<AtlasRelatedObjectId> relatedObjectIds = Arrays.asList(atlasRelatedObjectId);
		
		atlasClient.assignTermToEntities(termId, relatedObjectIds);
	}
}

You can observe that the term ‘sensitive’ is attached to the entity.



  

Previous                                                    Next                                                    Home

No comments:

Post a Comment