Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MESH-299 | Changed the position of linkedentity attribute to root #3969

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public static EntityAuditActionV2 fromString(String strValue) {
private Map<String, Object> detail;
private AtlasEntityHeader entityDetail;
private Map<String, String> headers;
private List<AtlasEntityHeader> linkedEntities;

public EntityAuditEventV2() { }

Expand Down Expand Up @@ -251,19 +250,6 @@ public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}

public List<AtlasEntityHeader> getLinkedEntities() {
return linkedEntities;
}

public void setLinkedEntities(List<AtlasEntityHeader> linkedEntities) {
this.linkedEntities = linkedEntities;
}

@JsonIgnore
public boolean hasLinkedEntities() {
return linkedEntities != null && !linkedEntities.isEmpty();
}

@JsonIgnore
public String getEntityDefinitionString() {
if (entity != null) {
Expand Down Expand Up @@ -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('}');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,7 @@ public EntityAuditSearchResult() { }
private Map<String, Object> aggregations;
private int count;
private int totalCount;
private Map<String, AtlasEntityHeader> linkedEntities;

public List<EntityAuditEventV2> getEntityAudits() {
return entityAudits;
Expand Down Expand Up @@ -63,6 +65,10 @@ public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}

public Map<String, AtlasEntityHeader> getLinkedEntities() { return linkedEntities; }

public void setLinkedEntities(Map<String, AtlasEntityHeader> linkedEntities) { this.linkedEntities = linkedEntities; }

@Override
public boolean equals(Object o) {
if (this == o) { return true; }
Expand All @@ -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('}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr
Map<String, Object> responseMap = AtlasType.fromJson(responseString, Map.class);
Map<String, Object> hits_0 = (Map<String, Object>) responseMap.get("hits");
List<LinkedHashMap> hits_1 = (List<LinkedHashMap>) hits_0.get("hits");
Map<String, AtlasEntityHeader> 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);
Expand All @@ -251,30 +257,27 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr
Map<String, Object> detail = event.getDetail();
if (detail != null && detail.containsKey("attributes")) {
Map<String, Object> attributes = (Map<String, Object>) detail.get("attributes");
List<AtlasEntityHeader> linkedEntityList = new ArrayList<>();

for (Map.Entry<String, Object> entry: attributes.entrySet()) {
if (linkedAttributes.contains(entry.getKey())) {
List<String> guids = (List<String>) entry.getValue();

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<String, String>) source.get("headers"));
Expand All @@ -286,6 +289,7 @@ private EntityAuditSearchResult getResultFromResponse(String responseString) thr
Map<String, Object> countObject = (Map<String, Object>) 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());
Expand Down
Loading