diff --git a/intg/src/main/java/org/apache/atlas/model/audit/EntityAuditEventV2.java b/intg/src/main/java/org/apache/atlas/model/audit/EntityAuditEventV2.java index c7eb29fe27..199292160a 100644 --- a/intg/src/main/java/org/apache/atlas/model/audit/EntityAuditEventV2.java +++ b/intg/src/main/java/org/apache/atlas/model/audit/EntityAuditEventV2.java @@ -135,7 +135,6 @@ public static EntityAuditActionV2 fromString(String strValue) { private Map detail; private AtlasEntityHeader entityDetail; private Map headers; - private List linkedEntities; public EntityAuditEventV2() { } @@ -251,19 +250,6 @@ public void setHeaders(Map headers) { this.headers = headers; } - public List getLinkedEntities() { - return linkedEntities; - } - - public void setLinkedEntities(List linkedEntities) { - this.linkedEntities = linkedEntities; - } - - @JsonIgnore - public boolean hasLinkedEntities() { - return linkedEntities != null && !linkedEntities.isEmpty(); - } - @JsonIgnore public String getEntityDefinitionString() { if (entity != null) { @@ -330,9 +316,6 @@ public String toString() { sb.append(", created=").append(created); sb.append(", headers=").append(headers); - if (hasLinkedEntities()) { - sb.append(", linkedEntities=").append(linkedEntities); - } sb.append('}'); diff --git a/intg/src/main/java/org/apache/atlas/model/audit/EntityAuditSearchResult.java b/intg/src/main/java/org/apache/atlas/model/audit/EntityAuditSearchResult.java index a71cdf41db..f69edf1c7a 100644 --- a/intg/src/main/java/org/apache/atlas/model/audit/EntityAuditSearchResult.java +++ b/intg/src/main/java/org/apache/atlas/model/audit/EntityAuditSearchResult.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.apache.atlas.model.Clearable; +import org.apache.atlas.model.instance.AtlasEntityHeader; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -30,6 +31,7 @@ public EntityAuditSearchResult() { } private Map aggregations; private int count; private int totalCount; + private Map linkedEntities; public List getEntityAudits() { return entityAudits; @@ -63,6 +65,10 @@ public void setTotalCount(int totalCount) { this.totalCount = totalCount; } + public Map getLinkedEntities() { return linkedEntities; } + + public void setLinkedEntities(Map linkedEntities) { this.linkedEntities = linkedEntities; } + @Override public boolean equals(Object o) { if (this == o) { return true; } @@ -85,6 +91,7 @@ public String toString() { final StringBuilder sb = new StringBuilder("EntityAuditSearchResult{"); sb.append("entityAudits='").append(entityAudits).append('\''); sb.append(", aggregations='").append(aggregations).append('\''); + sb.append(", linkedEntities='").append(linkedEntities).append('\''); sb.append(", count=").append(count); sb.append(", totalCount=").append(totalCount); sb.append('}'); diff --git a/repository/src/main/java/org/apache/atlas/repository/audit/ESBasedAuditRepository.java b/repository/src/main/java/org/apache/atlas/repository/audit/ESBasedAuditRepository.java index 2b0c802b83..51e0012ff2 100644 --- a/repository/src/main/java/org/apache/atlas/repository/audit/ESBasedAuditRepository.java +++ b/repository/src/main/java/org/apache/atlas/repository/audit/ESBasedAuditRepository.java @@ -225,6 +225,12 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr Map responseMap = AtlasType.fromJson(responseString, Map.class); Map hits_0 = (Map) responseMap.get("hits"); List hits_1 = (List) hits_0.get("hits"); + Map existingLinkedEntities = searchResult.getLinkedEntities(); + + if (existingLinkedEntities == null) { + existingLinkedEntities = new HashMap<>(); + } + for (LinkedHashMap hit : hits_1) { Map source = (Map) hit.get("_source"); String entityGuid = (String) source.get(ENTITYID); @@ -251,7 +257,6 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr Map detail = event.getDetail(); if (detail != null && detail.containsKey("attributes")) { Map attributes = (Map) detail.get("attributes"); - List linkedEntityList = new ArrayList<>(); for (Map.Entry entry: attributes.entrySet()) { if (linkedAttributes.contains(entry.getKey())) { @@ -259,22 +264,20 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr if (guids != null && !guids.isEmpty()){ for (String guid: guids){ - try { - AtlasEntityHeader entityHeader = fetchAtlasEntityHeader(guid); - if (entityHeader != null) { - linkedEntityList.add(entityHeader); + if(!existingLinkedEntities.containsKey(guid)){ + try { + AtlasEntityHeader entityHeader = fetchAtlasEntityHeader(guid); + if (entityHeader != null) { + existingLinkedEntities.put(guid, entityHeader); + } + } catch (AtlasBaseException e) { + throw new AtlasBaseException(e); } - } catch (AtlasBaseException e) { - throw new AtlasBaseException(e); } } } } } - - if(!linkedEntityList.isEmpty()){ - event.setLinkedEntities(linkedEntityList); - } } event.setHeaders((Map) source.get("headers")); @@ -286,6 +289,7 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr Map countObject = (Map) hits_0.get("total"); int totalCount = (int) countObject.get("value"); searchResult.setEntityAudits(entityAudits); + searchResult.setLinkedEntities(existingLinkedEntities); searchResult.setAggregations(aggregationsMap); searchResult.setTotalCount(totalCount); searchResult.setCount(entityAudits.size());