diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/accesscontrol/PersonaPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/accesscontrol/PersonaPreProcessor.java index 77078f5c53..3541e3e4a7 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/accesscontrol/PersonaPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/accesscontrol/PersonaPreProcessor.java @@ -23,6 +23,8 @@ import org.apache.atlas.auth.client.keycloak.AtlasKeycloakClient; import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasObjectId; +import org.apache.atlas.model.instance.AtlasRelatedObjectId; +import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.instance.AtlasStruct; import org.apache.atlas.model.instance.EntityMutations; import org.apache.atlas.repository.graphdb.AtlasGraph; @@ -30,6 +32,7 @@ import org.apache.atlas.repository.store.aliasstore.ESAliasStore; import org.apache.atlas.repository.store.aliasstore.IndexAliasStore; import org.apache.atlas.repository.store.graph.AtlasEntityStore; +import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever; import org.apache.atlas.repository.store.graph.v2.EntityMutationContext; import org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessor; @@ -186,18 +189,22 @@ private void processUpdatePersona(EntityMutationContext context, AtlasStruct ent private void updatePoliciesIsEnabledAttr(EntityMutationContext context, AtlasEntity existingPersonaEntity, boolean enable) throws AtlasBaseException { - List policies = (List) existingPersonaEntity.getRelationshipAttribute(REL_ATTR_POLICIES); + List policies = (List) existingPersonaEntity.getRelationshipAttribute(REL_ATTR_POLICIES); if (CollectionUtils.isNotEmpty(policies)) { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(POLICY_ENTITY_TYPE); - for (AtlasObjectId policy : policies) { - AtlasVertex policyVertex = entityRetriever.getEntityVertex(policy.getGuid()); + for (AtlasRelatedObjectId policy : policies) { + if (policy.getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) { + AtlasVertex policyVertex = entityRetriever.getEntityVertex(policy.getGuid()); - AtlasEntity policyToBeUpdated = entityRetriever.toAtlasEntity(policyVertex); - policyToBeUpdated.setAttribute(ATTR_POLICY_IS_ENABLED, enable); + if (AtlasGraphUtilsV2.getState(policyVertex) == AtlasEntity.Status.ACTIVE) { + AtlasEntity policyToBeUpdated = entityRetriever.toAtlasEntity(policyVertex); + policyToBeUpdated.setAttribute(ATTR_POLICY_IS_ENABLED, enable); - context.addUpdated(policyToBeUpdated.getGuid(), policyToBeUpdated, entityType, policyVertex); + context.addUpdated(policyToBeUpdated.getGuid(), policyToBeUpdated, entityType, policyVertex); + } + } } } } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/accesscontrol/PurposePreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/accesscontrol/PurposePreProcessor.java index ec88e3b134..1bb311e84e 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/accesscontrol/PurposePreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/accesscontrol/PurposePreProcessor.java @@ -22,6 +22,8 @@ import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasObjectId; +import org.apache.atlas.model.instance.AtlasRelatedObjectId; +import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.instance.AtlasStruct; import org.apache.atlas.model.instance.EntityMutations; import org.apache.atlas.repository.graphdb.AtlasGraph; @@ -29,6 +31,7 @@ import org.apache.atlas.repository.store.aliasstore.ESAliasStore; import org.apache.atlas.repository.store.aliasstore.IndexAliasStore; import org.apache.atlas.repository.store.graph.AtlasEntityStore; +import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever; import org.apache.atlas.repository.store.graph.v2.EntityMutationContext; import org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessor; @@ -145,23 +148,27 @@ private void processUpdatePurpose(EntityMutationContext context, if (!CollectionUtils.isEmpty(newTags) && !CollectionUtils.isEqualCollection(newTags, getPurposeTags(existingPurposeEntity))) { validateUniquenessByTags(graph, newTags, PURPOSE_ENTITY_TYPE); - List policies = (List) existingPurposeEntity.getRelationshipAttribute(REL_ATTR_POLICIES); + List policies = (List) existingPurposeEntity.getRelationshipAttribute(REL_ATTR_POLICIES); if (CollectionUtils.isNotEmpty(policies)) { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(POLICY_ENTITY_TYPE); List newTagsResources = newTags.stream().map(x -> "tag:" + x).collect(Collectors.toList()); - for (AtlasObjectId policy : policies) { - AtlasVertex policyVertex = entityRetriever.getEntityVertex(policy.getGuid()); + for (AtlasRelatedObjectId policy : policies) { + if (policy.getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) { + AtlasVertex policyVertex = entityRetriever.getEntityVertex(policy.getGuid()); - policyVertex.removeProperty(ATTR_POLICY_RESOURCES); + if (AtlasGraphUtilsV2.getState(policyVertex) == AtlasEntity.Status.ACTIVE) { + policyVertex.removeProperty(ATTR_POLICY_RESOURCES); - AtlasEntity policyToBeUpdated = entityRetriever.toAtlasEntity(policyVertex); - policyToBeUpdated.setAttribute(ATTR_POLICY_RESOURCES, newTagsResources); + AtlasEntity policyToBeUpdated = entityRetriever.toAtlasEntity(policyVertex); + policyToBeUpdated.setAttribute(ATTR_POLICY_RESOURCES, newTagsResources); - context.addUpdated(policyToBeUpdated.getGuid(), policyToBeUpdated, entityType, policyVertex); + context.addUpdated(policyToBeUpdated.getGuid(), policyToBeUpdated, entityType, policyVertex); - existingPurposeExtInfo.addReferredEntity(policyToBeUpdated); + existingPurposeExtInfo.addReferredEntity(policyToBeUpdated); + } + } } } @@ -173,21 +180,25 @@ private void processUpdatePurpose(EntityMutationContext context, RequestContext.get().endMetricRecord(metricRecorder); } - private void updatePoliciesIsEnabledAttr(EntityMutationContext context, AtlasEntity existingPersonaEntity, + private void updatePoliciesIsEnabledAttr(EntityMutationContext context, AtlasEntity existingPurposeEntity, boolean enable) throws AtlasBaseException { - List policies = (List) existingPersonaEntity.getRelationshipAttribute(REL_ATTR_POLICIES); + List policies = (List) existingPurposeEntity.getRelationshipAttribute(REL_ATTR_POLICIES); if (CollectionUtils.isNotEmpty(policies)) { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(POLICY_ENTITY_TYPE); - for (AtlasObjectId policy : policies) { - AtlasVertex policyVertex = entityRetriever.getEntityVertex(policy.getGuid()); + for (AtlasRelatedObjectId policy : policies) { + if (policy.getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) { + AtlasVertex policyVertex = entityRetriever.getEntityVertex(policy.getGuid()); - AtlasEntity policyToBeUpdated = entityRetriever.toAtlasEntity(policyVertex); - policyToBeUpdated.setAttribute(ATTR_POLICY_IS_ENABLED, enable); + if (AtlasGraphUtilsV2.getState(policyVertex) == AtlasEntity.Status.ACTIVE) { + AtlasEntity policyToBeUpdated = entityRetriever.toAtlasEntity(policyVertex); + policyToBeUpdated.setAttribute(ATTR_POLICY_IS_ENABLED, enable); - context.addUpdated(policyToBeUpdated.getGuid(), policyToBeUpdated, entityType, policyVertex); + context.addUpdated(policyToBeUpdated.getGuid(), policyToBeUpdated, entityType, policyVertex); + } + } } } }