Commit a0269b9c by apoorvnaik

ATLAS-2705 #2

Change-Id: I37796a6596cb284ba885dc05ffacd1dd7bcb6fba
parent 96e5f1cb
...@@ -113,7 +113,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -113,7 +113,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
updatedCategory.getAnchor().getGlossaryGuid(), updatedCategory.getAnchor().getGlossaryGuid(),
storeObject.getGuid()); storeObject.getGuid());
} }
relationshipStore.deleteById(storeObject.getAnchor().getRelationGuid()); relationshipStore.deleteById(storeObject.getAnchor().getRelationGuid(), true);
// Derive the qualifiedName when anchor changes // Derive the qualifiedName when anchor changes
String anchorGlossaryGuid = updatedCategory.getAnchor().getGlossaryGuid(); String anchorGlossaryGuid = updatedCategory.getAnchor().getGlossaryGuid();
...@@ -135,7 +135,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -135,7 +135,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
LOG.debug("Deleting category anchor"); LOG.debug("Deleting category anchor");
} }
relationshipStore.deleteById(storeObject.getAnchor().getRelationGuid()); relationshipStore.deleteById(storeObject.getAnchor().getRelationGuid(), true);
} }
break; break;
} }
...@@ -174,7 +174,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -174,7 +174,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
relationshipStore.update(parentRelationship); relationshipStore.update(parentRelationship);
} else { } else {
// Delete link to existing parent and link to new parent // Delete link to existing parent and link to new parent
relationshipStore.deleteById(parentRelationship.getGuid()); relationshipStore.deleteById(parentRelationship.getGuid(), true);
createRelationship(defineCategoryHierarchyLink(newParent, storeObject.getGuid())); createRelationship(defineCategoryHierarchyLink(newParent, storeObject.getGuid()));
} }
} }
...@@ -209,7 +209,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -209,7 +209,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
LOG.debug("Removing category parent, category = {}, parent = {}", storeObject.getGuid(), existingParent.getDisplayText()); LOG.debug("Removing category parent, category = {}, parent = {}", storeObject.getGuid(), existingParent.getDisplayText());
} }
relationshipStore.deleteById(existingParent.getRelationGuid()); relationshipStore.deleteById(existingParent.getRelationGuid(), true);
// Parent deleted, qualifiedName needs recomputation // Parent deleted, qualifiedName needs recomputation
...@@ -343,7 +343,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -343,7 +343,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
LOG.debug("Creating term relation with category = {}, terms = {}", storeObject.getDisplayName(), term.getDisplayText()); LOG.debug("Creating term relation with category = {}, terms = {}", storeObject.getDisplayName(), term.getDisplayText());
} }
relationshipStore.deleteById(term.getRelationGuid()); relationshipStore.deleteById(term.getRelationGuid(), true);
} }
} }
} }
...@@ -485,7 +485,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -485,7 +485,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
LOG.debug("Deleting child, category = {}, child = {}", storeObject.getDisplayName(), child.getDisplayText()); LOG.debug("Deleting child, category = {}, child = {}", storeObject.getDisplayName(), child.getDisplayText());
} }
relationshipStore.deleteById(child.getRelationGuid()); relationshipStore.deleteById(child.getRelationGuid(), true);
} }
} }
} }
...@@ -565,9 +565,11 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -565,9 +565,11 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
LOG.debug("Child anchor guid({}) doesn't match parent anchor guid({}). Updating child anchor", childAnchorGuid, parentAnchorGuid); LOG.debug("Child anchor guid({}) doesn't match parent anchor guid({}). Updating child anchor", childAnchorGuid, parentAnchorGuid);
} }
// Remove old glossary relation // Remove old glossary relation
relationshipStore.deleteById(child.getAnchor().getRelationGuid()); relationshipStore.deleteById(child.getAnchor().getRelationGuid(), true);
// Link to new glossary // Link to new glossary
createRelationship(defineCategoryAnchorRelation(parentAnchorGuid, child.getGuid())); createRelationship(defineCategoryAnchorRelation(parentAnchorGuid, child.getGuid()));
// Update the child's anchor GUID // Update the child's anchor GUID
child.getAnchor().setGlossaryGuid(parentAnchorGuid); child.getAnchor().setGlossaryGuid(parentAnchorGuid);
} }
......
...@@ -119,7 +119,7 @@ public class GlossaryTermUtils extends GlossaryUtils { ...@@ -119,7 +119,7 @@ public class GlossaryTermUtils extends GlossaryUtils {
} }
AtlasRelatedObjectId existingTermRelation = assignedEntityMap.get(relatedObjectId.getGuid()); AtlasRelatedObjectId existingTermRelation = assignedEntityMap.get(relatedObjectId.getGuid());
if (CollectionUtils.isNotEmpty(assignedEntities) && isRelationshipGuidSame(existingTermRelation, relatedObjectId)) { if (CollectionUtils.isNotEmpty(assignedEntities) && isRelationshipGuidSame(existingTermRelation, relatedObjectId)) {
relationshipStore.deleteById(relatedObjectId.getRelationshipGuid()); relationshipStore.deleteById(relatedObjectId.getRelationshipGuid(), true);
} else { } else {
throw new AtlasBaseException(AtlasErrorCode.INVALID_TERM_DISSOCIATION, relatedObjectId.getRelationshipGuid(), glossaryTerm.getGuid(), relatedObjectId.getGuid()); throw new AtlasBaseException(AtlasErrorCode.INVALID_TERM_DISSOCIATION, relatedObjectId.getRelationshipGuid(), glossaryTerm.getGuid(), relatedObjectId.getGuid());
} }
...@@ -176,7 +176,7 @@ public class GlossaryTermUtils extends GlossaryUtils { ...@@ -176,7 +176,7 @@ public class GlossaryTermUtils extends GlossaryUtils {
updatedTermAnchor.getGlossaryGuid(), updatedTermAnchor.getGlossaryGuid(),
storeObject.getDisplayName()); storeObject.getDisplayName());
} }
relationshipStore.deleteById(existingAnchor.getRelationGuid()); relationshipStore.deleteById(existingAnchor.getRelationGuid(), true);
// Derive the qualifiedName when anchor changes // Derive the qualifiedName when anchor changes
String anchorGlossaryGuid = updatedTermAnchor.getGlossaryGuid(); String anchorGlossaryGuid = updatedTermAnchor.getGlossaryGuid();
...@@ -195,7 +195,7 @@ public class GlossaryTermUtils extends GlossaryUtils { ...@@ -195,7 +195,7 @@ public class GlossaryTermUtils extends GlossaryUtils {
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
LOG.debug("Deleting term anchor"); LOG.debug("Deleting term anchor");
} }
relationshipStore.deleteById(existingAnchor.getRelationGuid()); relationshipStore.deleteById(existingAnchor.getRelationGuid(), true);
} }
break; break;
} }
...@@ -406,7 +406,7 @@ public class GlossaryTermUtils extends GlossaryUtils { ...@@ -406,7 +406,7 @@ public class GlossaryTermUtils extends GlossaryUtils {
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
LOG.debug("Deleting relation guid = {}, text = {}", categorizationHeader.getRelationGuid(), categorizationHeader.getDisplayText()); LOG.debug("Deleting relation guid = {}, text = {}", categorizationHeader.getRelationGuid(), categorizationHeader.getDisplayText());
} }
relationshipStore.deleteById(categorizationHeader.getRelationGuid()); relationshipStore.deleteById(categorizationHeader.getRelationGuid(), true);
} }
} }
} }
...@@ -466,7 +466,7 @@ public class GlossaryTermUtils extends GlossaryUtils { ...@@ -466,7 +466,7 @@ public class GlossaryTermUtils extends GlossaryUtils {
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
LOG.debug("Deleting term relation = {}, terms = {}", relation, termHeader.getDisplayText()); LOG.debug("Deleting term relation = {}, terms = {}", relation, termHeader.getDisplayText());
} }
relationshipStore.deleteById(termHeader.getRelationGuid()); relationshipStore.deleteById(termHeader.getRelationGuid(), true);
} }
} }
} }
......
...@@ -71,4 +71,11 @@ public interface AtlasRelationshipStore { ...@@ -71,4 +71,11 @@ public interface AtlasRelationshipStore {
* @param guid relationship instance guid * @param guid relationship instance guid
*/ */
void deleteById(String guid) throws AtlasBaseException; void deleteById(String guid) throws AtlasBaseException;
/**
* Delete a relationship instance using guid.
* @param guid relationship instance guid
* @param forceDelete force delete the relationship edge
*/
void deleteById(String guid, boolean forceDelete) throws AtlasBaseException;
} }
...@@ -234,8 +234,14 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore { ...@@ -234,8 +234,14 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteById(String guid) throws AtlasBaseException { public void deleteById(String guid) throws AtlasBaseException {
deleteById(guid, false);
}
@Override
@GraphTransaction
public void deleteById(String guid, boolean forceDelete) throws AtlasBaseException {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> deleteById({})", guid); LOG.debug("==> deleteById({}, {})", guid, forceDelete);
} }
if (StringUtils.isEmpty(guid)) { if (StringUtils.isEmpty(guid)) {
...@@ -252,7 +258,7 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore { ...@@ -252,7 +258,7 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_DELETED, guid); throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_DELETED, guid);
} }
deleteHandler.deleteRelationships(Collections.singleton(edge)); deleteHandler.deleteRelationships(Collections.singleton(edge), forceDelete);
// notify entities for added/removed classification propagation // notify entities for added/removed classification propagation
entityChangeNotifier.notifyPropagatedEntities(); entityChangeNotifier.notifyPropagatedEntities();
......
...@@ -52,11 +52,7 @@ import org.slf4j.LoggerFactory; ...@@ -52,11 +52,7 @@ import org.slf4j.LoggerFactory;
import java.util.*; import java.util.*;
import static org.apache.atlas.model.TypeCategory.ARRAY; import static org.apache.atlas.model.TypeCategory.*;
import static org.apache.atlas.model.TypeCategory.CLASSIFICATION;
import static org.apache.atlas.model.TypeCategory.MAP;
import static org.apache.atlas.model.TypeCategory.OBJECT_ID_TYPE;
import static org.apache.atlas.model.TypeCategory.STRUCT;
import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE; import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE;
import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED; import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED;
import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags.ONE_TO_TWO; import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags.ONE_TO_TWO;
...@@ -64,25 +60,7 @@ import static org.apache.atlas.repository.Constants.CLASSIFICATION_EDGE_NAME_PRO ...@@ -64,25 +60,7 @@ import static org.apache.atlas.repository.Constants.CLASSIFICATION_EDGE_NAME_PRO
import static org.apache.atlas.repository.Constants.CLASSIFICATION_LABEL; import static org.apache.atlas.repository.Constants.CLASSIFICATION_LABEL;
import static org.apache.atlas.repository.Constants.PROPAGATED_TRAIT_NAMES_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.PROPAGATED_TRAIT_NAMES_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.RELATIONSHIP_GUID_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.RELATIONSHIP_GUID_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.TRAIT_NAMES_PROPERTY_KEY; import static org.apache.atlas.repository.graph.GraphHelper.*;
import static org.apache.atlas.repository.graph.GraphHelper.addToPropagatedTraitNames;
import static org.apache.atlas.repository.graph.GraphHelper.getAssociatedEntityVertex;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationEdge;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationEdges;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationEntityGuid;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationName;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationVertices;
import static org.apache.atlas.repository.graph.GraphHelper.getCollectionElementsUsingRelationship;
import static org.apache.atlas.repository.graph.GraphHelper.getGuid;
import static org.apache.atlas.repository.graph.GraphHelper.getMapValuesUsingRelationship;
import static org.apache.atlas.repository.graph.GraphHelper.getPropagatedClassificationEdge;
import static org.apache.atlas.repository.graph.GraphHelper.getPropagatedEdges;
import static org.apache.atlas.repository.graph.GraphHelper.getPropagationEnabledClassificationVertices;
import static org.apache.atlas.repository.graph.GraphHelper.getRelationshipGuid;
import static org.apache.atlas.repository.graph.GraphHelper.getTraitNames;
import static org.apache.atlas.repository.graph.GraphHelper.getTypeName;
import static org.apache.atlas.repository.graph.GraphHelper.string;
import static org.apache.atlas.repository.graph.GraphHelper.updateModificationMetadata;
import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getIdFromEdge; import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getIdFromEdge;
import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getQualifiedAttributePropertyKey; import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getQualifiedAttributePropertyKey;
import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getState; import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getState;
...@@ -150,16 +128,17 @@ public abstract class DeleteHandlerV1 { ...@@ -150,16 +128,17 @@ public abstract class DeleteHandlerV1 {
* @throws AtlasBaseException * @throws AtlasBaseException
*/ */
public void deleteRelationship(AtlasEdge edge) throws AtlasBaseException { public void deleteRelationship(AtlasEdge edge) throws AtlasBaseException {
deleteRelationships(Collections.singleton(edge)); deleteRelationships(Collections.singleton(edge), false);
} }
/** /**
* Deletes the specified relationship edges. * Deletes the specified relationship edges.
* *
* @param edges * @param edges
* @param forceDelete
* @throws AtlasBaseException * @throws AtlasBaseException
*/ */
public void deleteRelationships(Collection<AtlasEdge> edges) throws AtlasBaseException { public void deleteRelationships(Collection<AtlasEdge> edges, final boolean forceDelete) throws AtlasBaseException {
for (AtlasEdge edge : edges) { for (AtlasEdge edge : edges) {
boolean isInternal = isInternalType(edge.getInVertex()) && isInternalType(edge.getOutVertex()); boolean isInternal = isInternalType(edge.getInVertex()) && isInternalType(edge.getOutVertex());
...@@ -171,7 +150,7 @@ public abstract class DeleteHandlerV1 { ...@@ -171,7 +150,7 @@ public abstract class DeleteHandlerV1 {
continue; continue;
} }
deleteEdge(edge, isInternal); deleteEdge(edge, isInternal || forceDelete);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment