Skip to content

Commit

Permalink
Merge pull request #3678 from atlanhq/chargebeenpe
Browse files Browse the repository at this point in the history
MM-3720 Chargebee another NPE while removing Struct vertex
  • Loading branch information
nikhilbonte21 authored Oct 29, 2024
2 parents 30d5879 + 2e37d39 commit f699ca6
Showing 1 changed file with 58 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AtlasEdge> edges = getCollectionElementsUsingRelationship(instanceVertex, attributeInfo);
if (isReference(elemType.getTypeCategory())) {
List<AtlasEdge> 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<AtlasEdge> edges = getMapValuesUsingRelationship(instanceVertex, attributeInfo);
if (isReference(valueTypeCategory)) {
List<AtlasEdge> 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);
Expand Down

0 comments on commit f699ca6

Please sign in to comment.