ATLAS-2705: Search using term shouldn't show deleted entities by default
Change-Id: I23b53086b2bb2380f451e7d85b59096edc610181
diff --git a/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java b/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
index 1890b1d..6e63061 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/SearchContext.java
@@ -27,16 +27,15 @@
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
-import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasVertex;
+import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasTypeRegistry;
-import org.apache.atlas.v1.model.instance.Id;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -233,11 +232,16 @@
AtlasAttribute attr = termType.getRelationshipAttribute(TermSearchProcessor.ATLAS_GLOSSARY_TERM_ATTR_ASSIGNED_ENTITIES);
Iterator<AtlasEdge> edges = GraphHelper.getEdgesForLabel(glossaryTerm, attr.getRelationshipEdgeLabel(), attr.getRelationshipEdgeDirection());
+ boolean excludeDeletedEntities = searchParameters.getExcludeDeletedEntities();
if (edges != null) {
while (edges.hasNext()) {
AtlasEdge edge = edges.next();
- ret.add(edge.getInVertex());
+ AtlasVertex inVertex = edge.getInVertex();
+ if (excludeDeletedEntities && AtlasGraphUtilsV1.getState(inVertex) == AtlasEntity.Status.DELETED) {
+ continue;
+ }
+ ret.add(inVertex);
}
}
diff --git a/repository/src/main/java/org/apache/atlas/discovery/TermSearchProcessor.java b/repository/src/main/java/org/apache/atlas/discovery/TermSearchProcessor.java
index 19d9bc4..c253d54 100644
--- a/repository/src/main/java/org/apache/atlas/discovery/TermSearchProcessor.java
+++ b/repository/src/main/java/org/apache/atlas/discovery/TermSearchProcessor.java
@@ -20,7 +20,6 @@
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.collections.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -89,21 +88,18 @@
if (CollectionUtils.isEmpty(assignedEntities)) {
entityVertices.clear();
} else {
- CollectionUtils.filter(entityVertices, new Predicate() {
- @Override
- public boolean evaluate(Object o) {
- if (o instanceof AtlasVertex) {
- AtlasVertex entityVertex = (AtlasVertex) o;
+ CollectionUtils.filter(entityVertices, o -> {
+ if (o instanceof AtlasVertex) {
+ AtlasVertex entityVertex = (AtlasVertex) o;
- for (AtlasVertex assignedEntity : assignedEntities) {
- if (assignedEntity.getId().equals(entityVertex.getId())) {
- return true;
- }
+ for (AtlasVertex assignedEntity : assignedEntities) {
+ if (assignedEntity.getId().equals(entityVertex.getId())) {
+ return true;
}
}
-
- return false;
}
+
+ return false;
});
}
}