diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java index 537f27339f..68c6dacd9c 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java @@ -789,71 +789,81 @@ protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throw } String typeName = GraphHelper.getTypeName(instanceVertex); - AtlasType parentType = typeRegistry.getType(typeName); - if (parentType instanceof AtlasStructType) { - AtlasStructType structType = (AtlasStructType) parentType; - boolean isEntityType = (parentType instanceof AtlasEntityType); + if (StringUtils.isNotEmpty(typeName)) { + AtlasType parentType = typeRegistry.getType(typeName); - for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) { - if (LOG.isDebugEnabled()) { - LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex)); - } + if (parentType instanceof AtlasStructType) { + AtlasStructType structType = (AtlasStructType) parentType; + boolean isEntityType = (parentType instanceof AtlasEntityType); + + for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex)); + } - boolean isOwned = isEntityType && attributeInfo.isOwnedRef(); - AtlasType attrType = attributeInfo.getAttributeType(); - String edgeLabel = attributeInfo.getRelationshipEdgeLabel(); + boolean isOwned = isEntityType && attributeInfo.isOwnedRef(); + AtlasType attrType = attributeInfo.getAttributeType(); + String edgeLabel = attributeInfo.getRelationshipEdgeLabel(); - switch (attrType.getTypeCategory()) { - case OBJECT_ID_TYPE: - //If its class attribute, delete the reference - deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned); - break; + switch (attrType.getTypeCategory()) { + case OBJECT_ID_TYPE: + //If its class attribute, delete the reference + deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned); + break; - case STRUCT: - //If its struct attribute, delete the reference - deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false); - break; + case STRUCT: + //If its struct attribute, delete the reference + deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false); + break; - case ARRAY: - //For array attribute, if the element is struct/class, delete all the references - AtlasArrayType arrType = (AtlasArrayType) attrType; - AtlasType elemType = arrType.getElementType(); + case ARRAY: + //For array attribute, if the element is struct/class, delete all the references + AtlasArrayType arrType = (AtlasArrayType) attrType; + AtlasType elemType = arrType.getElementType(); - if (isReference(elemType.getTypeCategory())) { - List edges = getCollectionElementsUsingRelationship(instanceVertex, attributeInfo); + if (isReference(elemType.getTypeCategory())) { + List edges = getCollectionElementsUsingRelationship(instanceVertex, attributeInfo); - if (CollectionUtils.isNotEmpty(edges)) { - for (AtlasEdge edge : edges) { - deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false, instanceVertex); + if (CollectionUtils.isNotEmpty(edges)) { + for (AtlasEdge edge : edges) { + deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false, instanceVertex); + } } } - } - break; + break; - case MAP: - //For map attribute, if the value type is struct/class, delete all the references - AtlasMapType mapType = (AtlasMapType) attrType; - TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory(); + case MAP: + //For map attribute, if the value type is struct/class, delete all the references + AtlasMapType mapType = (AtlasMapType) attrType; + TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory(); - if (isReference(valueTypeCategory)) { - List edges = getMapValuesUsingRelationship(instanceVertex, attributeInfo); + if (isReference(valueTypeCategory)) { + List edges = getMapValuesUsingRelationship(instanceVertex, attributeInfo); - for (AtlasEdge edge : edges) { - deleteEdgeReference(edge, valueTypeCategory, isOwned, false, instanceVertex); + for (AtlasEdge edge : edges) { + deleteEdgeReference(edge, valueTypeCategory, isOwned, false, instanceVertex); + } } - } - break; + break; - case PRIMITIVE: - // This is different from upstream atlas. - // Here we are not deleting the unique property thus users can only restore after deleting an entity. - if (attributeInfo.getVertexUniquePropertyName() != null && force) { - instanceVertex.removeProperty(attributeInfo.getVertexUniquePropertyName()); - } - break; + case PRIMITIVE: + // This is different from upstream atlas. + // Here we are not deleting the unique property thus users can only restore after deleting an entity. + if (attributeInfo.getVertexUniquePropertyName() != null && force) { + instanceVertex.removeProperty(attributeInfo.getVertexUniquePropertyName()); + } + break; + } } } + } else { + try { + LOG.error("typeName not found for the vertex {}", instanceVertex.getIdForDisplay()); + } catch (Exception e) { + LOG.error("Error while writing error log"); + e.printStackTrace(); + } } deleteVertex(instanceVertex, force);