Commit df44a5cb by Sarath Subramanian

ATLAS-3073: Investigate and fix IT failures in EntityJerseyResourceIT

parent 0f79c344
......@@ -24,6 +24,7 @@ import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntity.Status;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.v1.model.instance.AtlasSystemAttributes;
import org.apache.atlas.v1.model.instance.Id;
import org.apache.atlas.v1.model.instance.Referenceable;
......@@ -128,30 +129,12 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
}
final Map v2Attribs = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
final Map v2RelationshipAttribs = (Map) v2Map.get(RELATIONSHIP_ATTRIBUTES_PROPERTY_KEY);
final Map attributes;
if (MapUtils.isNotEmpty(v2RelationshipAttribs)) {
if (MapUtils.isNotEmpty(v2Attribs)) {
attributes = new HashMap(v2RelationshipAttribs);
for (Object key : v2Attribs.keySet()) {
if (!attributes.containsKey(key)) {
attributes.put(key, v2Attribs.get(key));
}
}
} else {
attributes = v2RelationshipAttribs;
}
} else {
attributes = v2Attribs;
}
final Map v2Attribs = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
if (MapUtils.isEmpty(v2Attribs)) {
ret = new Id(idStr, 0, typeName);
} else {
ret = new Referenceable(idStr, typeName, super.fromV2ToV1(entityType, attributes, context));
ret = new Referenceable(idStr, typeName, super.fromV2ToV1(entityType, v2Attribs, context));
}
} else if (v2Obj instanceof AtlasEntity) {
AtlasEntity entity = (AtlasEntity) v2Obj;
......@@ -161,28 +144,10 @@ public class AtlasEntityFormatConverter extends AtlasStructFormatConverter {
status = Status.ACTIVE;
}
final Map<String, Object> v2Attribs = entity.getAttributes();
final Map<String, Object> v2RelationshipAttribs = entity.getRelationshipAttributes();
final Map<String, Object> attributes;
if (MapUtils.isNotEmpty(v2RelationshipAttribs)) {
if (MapUtils.isNotEmpty(v2Attribs)) {
attributes = new HashMap(v2RelationshipAttribs);
for (String key : v2Attribs.keySet()) {
if (!attributes.containsKey(key)) {
attributes.put(key, v2Attribs.get(key));
}
}
} else {
attributes = v2RelationshipAttribs;
}
} else {
attributes = v2Attribs;
}
final Map<String, Object> v2Attribs = entity.getAttributes();
Referenceable referenceable = new Referenceable(entity.getGuid(), entity.getTypeName(), status.name(),
fromV2ToV1(entityType, attributes, context),
fromV2ToV1(entityType, v2Attribs, context),
new AtlasSystemAttributes(entity.getCreatedBy(), entity.getUpdatedBy(), entity.getCreateTime(), entity.getUpdateTime()));
if (CollectionUtils.isNotEmpty(entity.getClassifications())) {
......
......@@ -65,6 +65,7 @@ import javax.inject.Inject;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
......@@ -1044,13 +1045,41 @@ public class EntityGraphRetriever {
entity.setRelationshipAttribute(attributeName, ret);
if (attributeEndDef.getIsLegacyAttribute() && !entity.hasAttribute(attributeName)) {
entity.setAttribute(attributeName, ret);
entity.setAttribute(attributeName, toAtlasObjectId(ret));
}
}
return ret;
}
private Object toAtlasObjectId(Object obj) {
final Object ret;
if (obj instanceof AtlasObjectId) {
ret = new AtlasObjectId((AtlasObjectId) obj);
} else if (obj instanceof Collection) {
List list = new ArrayList();
for (Object elem : (Collection) obj) {
list.add(toAtlasObjectId(elem));
}
ret = list;
} else if (obj instanceof Map) {
Map map = new HashMap();
for (Object key : ((Map) obj).keySet()) {
map.put(key, toAtlasObjectId(((Map) obj).get(key)));
}
ret = map;
} else {
ret = obj;
}
return ret;
}
private AtlasObjectId mapRelatedVertexToObjectId(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) throws AtlasBaseException {
AtlasEdge edge = graphHelper.getEdgeForLabel(entityVertex, attribute.getRelationshipEdgeLabel(), attribute.getRelationshipEdgeDirection());
......
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