Skip to content

Commit

Permalink
Merge pull request #3497 from atlanhq/mesh-148-link-api-beta
Browse files Browse the repository at this point in the history
MESH-192 : Bulk link api for domain<>asset link
  • Loading branch information
PRATHAM2002-DS committed Sep 9, 2024
2 parents d1d32a0 + bdaf52d commit 129b6fa
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public class EntityGraphMapper {
private static final String TYPE_CATEGORY = "AtlasGlossaryCategory";
private static final String TYPE_TERM = "AtlasGlossaryTerm";
private static final String TYPE_PRODUCT = "DataProduct";
private static final String TYPE_DOMAIN = "DataDomain";
private static final String TYPE_PROCESS = "Process";
private static final String ATTR_MEANINGS = "meanings";
private static final String ATTR_ANCHOR = "anchor";
Expand Down Expand Up @@ -199,6 +200,9 @@ public class EntityGraphMapper {
private final IFullTextMapper fullTextMapperV2;
private final TaskManagement taskManagement;
private final TransactionInterceptHelper transactionInterceptHelper;
private final EntityGraphRetriever retrieverNoRelation;

private static final Set<String> excludedTypes = new HashSet<>(Arrays.asList(TYPE_GLOSSARY, TYPE_CATEGORY, TYPE_TERM, TYPE_PRODUCT, TYPE_DOMAIN));

@Inject
public EntityGraphMapper(DeleteHandlerDelegate deleteDelegate, RestoreHandlerV1 restoreHandlerV1, AtlasTypeRegistry typeRegistry, AtlasGraph graph,
Expand All @@ -214,6 +218,7 @@ public EntityGraphMapper(DeleteHandlerDelegate deleteDelegate, RestoreHandlerV1
this.entityChangeNotifier = entityChangeNotifier;
this.instanceConverter = instanceConverter;
this.entityRetriever = new EntityGraphRetriever(graph, typeRegistry);
this.retrieverNoRelation = new EntityGraphRetriever(graph, typeRegistry, true);
this.fullTextMapperV2 = fullTextMapperV2;
this.taskManagement = taskManagement;
this.transactionInterceptHelper = transactionInterceptHelper;
Expand Down Expand Up @@ -4967,14 +4972,14 @@ public List<AtlasVertex> unlinkBusinessPolicy(String policyId, Set<String> unlin

public List<AtlasVertex> linkMeshEntityToAssets(String meshEntityId, Set<String> linkGuids) throws AtlasBaseException {
List<AtlasVertex> linkedVertices = new ArrayList<>();
Set<String> excludedTypes = new HashSet<>(Arrays.asList(TYPE_GLOSSARY, TYPE_CATEGORY, TYPE_TERM, TYPE_PRODUCT));

for (String guid : linkGuids) {
AtlasVertex ev = findByGuid(graph, guid);

if (ev != null) {
String typeName = ev.getProperty(TYPE_NAME_PROPERTY_KEY, String.class);
if (excludedTypes.contains(typeName)){
LOG.warn("Type {} is not allowed to link with mesh entity", typeName);
continue;
}
Set<String> existingValues = ev.getMultiValuedSetProperty(DOMAIN_GUIDS_ATTR, String.class);
Expand All @@ -5000,14 +5005,14 @@ public List<AtlasVertex> linkMeshEntityToAssets(String meshEntityId, Set<String>

public List<AtlasVertex> unlinkMeshEntityFromAssets(String meshEntityId, Set<String> unlinkGuids) throws AtlasBaseException {
List<AtlasVertex> unlinkedVertices = new ArrayList<>();
Set<String> excludedTypes = new HashSet<>(Arrays.asList(TYPE_GLOSSARY, TYPE_CATEGORY, TYPE_TERM, TYPE_PRODUCT));

for (String guid : unlinkGuids) {
AtlasVertex ev = AtlasGraphUtilsV2.findByGuid(graph, guid);

if (ev != null) {
String typeName = ev.getProperty(TYPE_NAME_PROPERTY_KEY, String.class);
if (excludedTypes.contains(typeName)){
LOG.warn("Type {} is not allowed to link with mesh entity", typeName);
continue;
}

Expand Down Expand Up @@ -5066,7 +5071,7 @@ private void setEntityCommonAttributes(AtlasVertex ev, AtlasEntity diffEntity) {
}

private void isAuthorizedToLink(AtlasVertex vertex) throws AtlasBaseException {
AtlasEntityHeader sourceEntity = entityRetriever.toAtlasEntityHeader(vertex);
AtlasEntityHeader sourceEntity = retrieverNoRelation.toAtlasEntityHeader(vertex);

// source -> UPDATE + READ
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_UPDATE, sourceEntity),
Expand Down

0 comments on commit 129b6fa

Please sign in to comment.