Commit c95aba21 by Sarath Subramanian

ATLAS-3545: NullPointerException while trying to delete classification

parent 8ca94c8d
...@@ -1862,6 +1862,10 @@ public class EntityGraphMapper { ...@@ -1862,6 +1862,10 @@ public class EntityGraphMapper {
AtlasVertex classificationVertex = getClassificationVertex(entityVertex, classificationName); AtlasVertex classificationVertex = getClassificationVertex(entityVertex, classificationName);
AtlasClassification classification = entityRetriever.toAtlasClassification(classificationVertex); AtlasClassification classification = entityRetriever.toAtlasClassification(classificationVertex);
if (classification == null) {
throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
}
// remove classification from propagated entities if propagation is turned on // remove classification from propagated entities if propagation is turned on
if (isPropagationEnabled(classificationVertex)) { if (isPropagationEnabled(classificationVertex)) {
List<AtlasVertex> propagatedEntityVertices = deleteDelegate.getHandler().removeTagPropagation(classificationVertex); List<AtlasVertex> propagatedEntityVertices = deleteDelegate.getHandler().removeTagPropagation(classificationVertex);
...@@ -2028,6 +2032,10 @@ public class EntityGraphMapper { ...@@ -2028,6 +2032,10 @@ public class EntityGraphMapper {
AtlasClassification currentClassification = entityRetriever.toAtlasClassification(classificationVertex); AtlasClassification currentClassification = entityRetriever.toAtlasClassification(classificationVertex);
if (currentClassification == null) {
continue;
}
validateAndNormalizeForUpdate(classification); validateAndNormalizeForUpdate(classification);
boolean isClassificationUpdated = false; boolean isClassificationUpdated = false;
......
...@@ -277,20 +277,27 @@ public class EntityGraphRetriever { ...@@ -277,20 +277,27 @@ public class EntityGraphRetriever {
} }
public AtlasClassification toAtlasClassification(AtlasVertex classificationVertex) throws AtlasBaseException { public AtlasClassification toAtlasClassification(AtlasVertex classificationVertex) throws AtlasBaseException {
AtlasClassification ret = new AtlasClassification(getTypeName(classificationVertex)); AtlasClassification ret = null;
String classificationName = getTypeName(classificationVertex);
ret.setEntityGuid(AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class)); if (StringUtils.isEmpty(classificationName)) {
ret.setEntityStatus(getClassificationEntityStatus(classificationVertex)); LOG.warn("Ignoring invalid classification vertex: {}", AtlasGraphUtilsV2.toString(classificationVertex));
ret.setPropagate(isPropagationEnabled(classificationVertex)); } else {
ret.setRemovePropagationsOnEntityDelete(getRemovePropagations(classificationVertex)); ret = new AtlasClassification(classificationName);
String strValidityPeriods = AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class); ret.setEntityGuid(AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class));
ret.setEntityStatus(getClassificationEntityStatus(classificationVertex));
ret.setPropagate(isPropagationEnabled(classificationVertex));
ret.setRemovePropagationsOnEntityDelete(getRemovePropagations(classificationVertex));
if (strValidityPeriods != null) { String strValidityPeriods = AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class);
ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST_TYPE));
}
mapAttributes(classificationVertex, ret, null); if (strValidityPeriods != null) {
ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST_TYPE));
}
mapAttributes(classificationVertex, ret, null);
}
return ret; return ret;
} }
...@@ -621,10 +628,12 @@ public class EntityGraphRetriever { ...@@ -621,10 +628,12 @@ public class EntityGraphRetriever {
Iterator<AtlasEdge> iterator = edges.iterator(); Iterator<AtlasEdge> iterator = edges.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
AtlasEdge edge = iterator.next(); AtlasEdge classificationEdge = iterator.next();
AtlasVertex classificationVertex = classificationEdge != null ? classificationEdge.getInVertex() : null;
AtlasClassification classification = toAtlasClassification(classificationVertex);
if (edge != null) { if (classification != null) {
ret.add(toAtlasClassification(edge.getInVertex())); ret.add(classification);
} }
} }
} }
...@@ -711,12 +720,15 @@ public class EntityGraphRetriever { ...@@ -711,12 +720,15 @@ public class EntityGraphRetriever {
List<AtlasEdge> edges = getAllClassificationEdges(entityVertex); List<AtlasEdge> edges = getAllClassificationEdges(entityVertex);
if (CollectionUtils.isNotEmpty(edges)) { if (CollectionUtils.isNotEmpty(edges)) {
List<AtlasClassification> allClassifications = new ArrayList<>(); List<AtlasClassification> allClassifications = new ArrayList<>();
for (AtlasEdge edge : edges) { for (AtlasEdge edge : edges) {
AtlasVertex classificationVertex = edge.getInVertex(); AtlasVertex classificationVertex = edge.getInVertex();
AtlasClassification classification = toAtlasClassification(classificationVertex);
allClassifications.add(toAtlasClassification(classificationVertex)); if (classification != null) {
allClassifications.add(classification);
}
} }
entity.setClassifications(allClassifications); entity.setClassifications(allClassifications);
...@@ -1387,7 +1399,10 @@ public class EntityGraphRetriever { ...@@ -1387,7 +1399,10 @@ public class EntityGraphRetriever {
for (AtlasVertex classificationVertex : classificationVertices) { for (AtlasVertex classificationVertex : classificationVertices) {
String classificationId = classificationVertex.getIdForDisplay(); String classificationId = classificationVertex.getIdForDisplay();
AtlasClassification classification = toAtlasClassification(classificationVertex); AtlasClassification classification = toAtlasClassification(classificationVertex);
String entityGuid = classification.getEntityGuid();
if (classification == null) {
continue;
}
if (blockedClassificationIds.contains(classificationId)) { if (blockedClassificationIds.contains(classificationId)) {
blockedClassifications.add(classification); blockedClassifications.add(classification);
...@@ -1397,7 +1412,7 @@ public class EntityGraphRetriever { ...@@ -1397,7 +1412,7 @@ public class EntityGraphRetriever {
// add entity headers to referred entities // add entity headers to referred entities
if (extendedInfo) { if (extendedInfo) {
addToReferredEntities(relationshipWithExtInfo, entityGuid); addToReferredEntities(relationshipWithExtInfo, classification.getEntityGuid());
} }
} }
......
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