Skip to content

Commit f699ca6

Browse files
Merge pull request #3678 from atlanhq/chargebeenpe
MM-3720 Chargebee another NPE while removing Struct vertex
2 parents 30d5879 + 2e37d39 commit f699ca6

File tree

1 file changed

+58
-48
lines changed

1 file changed

+58
-48
lines changed

repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java

+58-48
Original file line numberDiff line numberDiff line change
@@ -789,71 +789,81 @@ protected void deleteTypeVertex(AtlasVertex instanceVertex, boolean force) throw
789789
}
790790

791791
String typeName = GraphHelper.getTypeName(instanceVertex);
792-
AtlasType parentType = typeRegistry.getType(typeName);
793792

794-
if (parentType instanceof AtlasStructType) {
795-
AtlasStructType structType = (AtlasStructType) parentType;
796-
boolean isEntityType = (parentType instanceof AtlasEntityType);
793+
if (StringUtils.isNotEmpty(typeName)) {
794+
AtlasType parentType = typeRegistry.getType(typeName);
797795

798-
for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) {
799-
if (LOG.isDebugEnabled()) {
800-
LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex));
801-
}
796+
if (parentType instanceof AtlasStructType) {
797+
AtlasStructType structType = (AtlasStructType) parentType;
798+
boolean isEntityType = (parentType instanceof AtlasEntityType);
799+
800+
for (AtlasStructType.AtlasAttribute attributeInfo : structType.getAllAttributes().values()) {
801+
if (LOG.isDebugEnabled()) {
802+
LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex));
803+
}
802804

803-
boolean isOwned = isEntityType && attributeInfo.isOwnedRef();
804-
AtlasType attrType = attributeInfo.getAttributeType();
805-
String edgeLabel = attributeInfo.getRelationshipEdgeLabel();
805+
boolean isOwned = isEntityType && attributeInfo.isOwnedRef();
806+
AtlasType attrType = attributeInfo.getAttributeType();
807+
String edgeLabel = attributeInfo.getRelationshipEdgeLabel();
806808

807-
switch (attrType.getTypeCategory()) {
808-
case OBJECT_ID_TYPE:
809-
//If its class attribute, delete the reference
810-
deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned);
811-
break;
809+
switch (attrType.getTypeCategory()) {
810+
case OBJECT_ID_TYPE:
811+
//If its class attribute, delete the reference
812+
deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), isOwned);
813+
break;
812814

813-
case STRUCT:
814-
//If its struct attribute, delete the reference
815-
deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false);
816-
break;
815+
case STRUCT:
816+
//If its struct attribute, delete the reference
817+
deleteEdgeReference(instanceVertex, edgeLabel, attrType.getTypeCategory(), false);
818+
break;
817819

818-
case ARRAY:
819-
//For array attribute, if the element is struct/class, delete all the references
820-
AtlasArrayType arrType = (AtlasArrayType) attrType;
821-
AtlasType elemType = arrType.getElementType();
820+
case ARRAY:
821+
//For array attribute, if the element is struct/class, delete all the references
822+
AtlasArrayType arrType = (AtlasArrayType) attrType;
823+
AtlasType elemType = arrType.getElementType();
822824

823-
if (isReference(elemType.getTypeCategory())) {
824-
List<AtlasEdge> edges = getCollectionElementsUsingRelationship(instanceVertex, attributeInfo);
825+
if (isReference(elemType.getTypeCategory())) {
826+
List<AtlasEdge> edges = getCollectionElementsUsingRelationship(instanceVertex, attributeInfo);
825827

826-
if (CollectionUtils.isNotEmpty(edges)) {
827-
for (AtlasEdge edge : edges) {
828-
deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false, instanceVertex);
828+
if (CollectionUtils.isNotEmpty(edges)) {
829+
for (AtlasEdge edge : edges) {
830+
deleteEdgeReference(edge, elemType.getTypeCategory(), isOwned, false, instanceVertex);
831+
}
829832
}
830833
}
831-
}
832-
break;
834+
break;
833835

834-
case MAP:
835-
//For map attribute, if the value type is struct/class, delete all the references
836-
AtlasMapType mapType = (AtlasMapType) attrType;
837-
TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
836+
case MAP:
837+
//For map attribute, if the value type is struct/class, delete all the references
838+
AtlasMapType mapType = (AtlasMapType) attrType;
839+
TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
838840

839-
if (isReference(valueTypeCategory)) {
840-
List<AtlasEdge> edges = getMapValuesUsingRelationship(instanceVertex, attributeInfo);
841+
if (isReference(valueTypeCategory)) {
842+
List<AtlasEdge> edges = getMapValuesUsingRelationship(instanceVertex, attributeInfo);
841843

842-
for (AtlasEdge edge : edges) {
843-
deleteEdgeReference(edge, valueTypeCategory, isOwned, false, instanceVertex);
844+
for (AtlasEdge edge : edges) {
845+
deleteEdgeReference(edge, valueTypeCategory, isOwned, false, instanceVertex);
846+
}
844847
}
845-
}
846-
break;
848+
break;
847849

848-
case PRIMITIVE:
849-
// This is different from upstream atlas.
850-
// Here we are not deleting the unique property thus users can only restore after deleting an entity.
851-
if (attributeInfo.getVertexUniquePropertyName() != null && force) {
852-
instanceVertex.removeProperty(attributeInfo.getVertexUniquePropertyName());
853-
}
854-
break;
850+
case PRIMITIVE:
851+
// This is different from upstream atlas.
852+
// Here we are not deleting the unique property thus users can only restore after deleting an entity.
853+
if (attributeInfo.getVertexUniquePropertyName() != null && force) {
854+
instanceVertex.removeProperty(attributeInfo.getVertexUniquePropertyName());
855+
}
856+
break;
857+
}
855858
}
856859
}
860+
} else {
861+
try {
862+
LOG.error("typeName not found for the vertex {}", instanceVertex.getIdForDisplay());
863+
} catch (Exception e) {
864+
LOG.error("Error while writing error log");
865+
e.printStackTrace();
866+
}
857867
}
858868

859869
deleteVertex(instanceVertex, force);

0 commit comments

Comments
 (0)