You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2019/01/25 08:55:42 UTC

[atlas] branch branch-0.8 updated: ATLAS-3035: updated entity-get/delete to retrieve/delete soft-ref entities

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch branch-0.8
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/branch-0.8 by this push:
     new b5a90cc  ATLAS-3035: updated entity-get/delete to retrieve/delete soft-ref entities
b5a90cc is described below

commit b5a90ccab567a31078c16195a6af551fa8d4e806
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Wed Jan 23 16:19:01 2019 -0800

    ATLAS-3035: updated entity-get/delete to retrieve/delete soft-ref entities
---
 .../org/apache/atlas/utils/AtlasEntityUtil.java    | 122 ++++++++++++++++++
 .../repository/impexp/AtlasServerService.java      |   3 +-
 .../repository/store/graph/v1/DeleteHandlerV1.java |  85 ++++++++++---
 .../store/graph/v1/EntityGraphMapper.java          |  37 ++----
 .../store/graph/v1/EntityGraphRetriever.java       | 141 ++++++++++++---------
 5 files changed, 284 insertions(+), 104 deletions(-)

diff --git a/intg/src/main/java/org/apache/atlas/utils/AtlasEntityUtil.java b/intg/src/main/java/org/apache/atlas/utils/AtlasEntityUtil.java
new file mode 100644
index 0000000..19cd440
--- /dev/null
+++ b/intg/src/main/java/org/apache/atlas/utils/AtlasEntityUtil.java
@@ -0,0 +1,122 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.atlas.utils;
+
+
+import org.apache.atlas.model.instance.AtlasObjectId;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+public class AtlasEntityUtil {
+    private static final Logger LOG = LoggerFactory.getLogger(AtlasEntityUtil.class);
+
+    private static final String SOFT_REFERENCE_FORMAT_SEPERATOR       = ":";
+    private static final String SOFT_REF_FORMAT                       = "%s" + SOFT_REFERENCE_FORMAT_SEPERATOR + "%s";
+    private static final int    SOFT_REFERENCE_FORMAT_INDEX_TYPE_NAME = 0;
+    private static final int    SOFT_REFERENCE_FORMAT_INDEX_GUID      = 1;
+
+
+    public static String formatSoftRefValue(String typeName, String guid) {
+        return String.format(SOFT_REF_FORMAT, typeName, guid);
+    }
+
+    public static String formatSoftRefValue(AtlasObjectId objectId) {
+        return formatSoftRefValue(objectId.getTypeName(), objectId.getGuid());
+    }
+
+    public static List<String> formatSoftRefValue(List<AtlasObjectId> objIds) {
+        List<String> ret = new ArrayList<>();
+
+        for (AtlasObjectId objId : objIds) {
+            ret.add(formatSoftRefValue(objId));
+        }
+
+        return ret;
+    }
+
+    public static Map<String, String> formatSoftRefValue(Map<String, AtlasObjectId> objIdMap) {
+        Map<String, String> ret = new HashMap<>();
+
+        for (Map.Entry<String, AtlasObjectId> entry : objIdMap.entrySet()) {
+            ret.put(entry.getKey(), formatSoftRefValue(entry.getValue()));
+        }
+
+        return ret;
+    }
+
+    public static AtlasObjectId parseSoftRefValue(String softRefValue) {
+        AtlasObjectId ret = null;
+
+        if (StringUtils.isNotEmpty(softRefValue)) {
+            String[] objectIdParts = StringUtils.split(softRefValue, SOFT_REFERENCE_FORMAT_SEPERATOR);
+
+            if(objectIdParts.length >= 2) {
+                ret = new AtlasObjectId(objectIdParts[SOFT_REFERENCE_FORMAT_INDEX_GUID], objectIdParts[SOFT_REFERENCE_FORMAT_INDEX_TYPE_NAME]);
+            } else {
+                LOG.warn("Invalid soft-ref value: {}", softRefValue);
+            }
+        }
+
+        return ret;
+    }
+
+    public static List<AtlasObjectId> parseSoftRefValue(List<String> softRefValue) {
+        List<AtlasObjectId> ret = null;
+
+        if (CollectionUtils.isNotEmpty(softRefValue)) {
+            ret = new ArrayList<>();
+
+            for (String elemValue : softRefValue) {
+                AtlasObjectId objId = parseSoftRefValue(elemValue);
+
+                if (objId != null) {
+                    ret.add(objId);
+                }
+            }
+        }
+
+        return ret;
+    }
+
+    public static Map<String, AtlasObjectId> parseSoftRefValue(Map<String, String> softRefValue) {
+        Map<String, AtlasObjectId> ret = null;
+
+        if (MapUtils.isNotEmpty(softRefValue)) {
+            ret = new HashMap<>();
+
+            for (Map.Entry<String, String> entry : softRefValue.entrySet()) {
+                AtlasObjectId objId = parseSoftRefValue(entry.getValue());
+
+                if (objId != null) {
+                    ret.put(entry.getKey(), objId);
+                }
+            }
+        }
+
+        return ret;
+    }
+}
diff --git a/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java b/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java
index 417e405..5463c33 100644
--- a/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java
+++ b/repository/src/main/java/org/apache/atlas/repository/impexp/AtlasServerService.java
@@ -33,6 +33,7 @@ import org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever;
 import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasTypeRegistry;
+import org.apache.atlas.utils.AtlasEntityUtil;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -119,7 +120,7 @@ public class AtlasServerService {
     private void updateAttribute(AtlasEntity.AtlasEntityWithExtInfo entityWithExtInfo,
                                  String propertyName,
                                  AtlasObjectId objectId) {
-        String value = EntityGraphMapper.getSoftRefFormattedValue(objectId);
+        String value = AtlasEntityUtil.formatSoftRefValue(objectId);
         updateAttribute(entityWithExtInfo.getEntity(), propertyName, value);
         for (AtlasEntity e : entityWithExtInfo.getReferredEntities().values()) {
             updateAttribute(e, propertyName, value);
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
index 8024302..579758a 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
@@ -40,6 +40,8 @@ import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasType;
 import org.apache.atlas.type.AtlasTypeRegistry;
+import org.apache.atlas.utils.AtlasEntityUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -190,12 +192,23 @@ public abstract class DeleteHandlerV1 {
                 }
                 String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(entityType, attributeInfo.getName());
                 AtlasType attrType = attributeInfo.getAttributeType();
+
                 switch (attrType.getTypeCategory()) {
                 case OBJECT_ID_TYPE:
-                    AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel);
-                    if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
-                        AtlasVertex compositeVertex = edge.getInVertex();
-                        vertices.push(compositeVertex);
+                    if (attributeInfo.getAttributeDef().isSoftReferenced()) {
+                        String        softRefVal = vertex.getProperty(attributeInfo.getVertexPropertyName(), String.class);
+                        AtlasObjectId refObjId   = AtlasEntityUtil.parseSoftRefValue(softRefVal);
+                        AtlasVertex   refVertex  = refObjId != null ? AtlasGraphUtilsV1.findByGuid(refObjId.getGuid()) : null;
+
+                        if (refVertex != null) {
+                            vertices.push(refVertex);
+                        }
+                    } else {
+                        AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel);
+                        if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
+                            AtlasVertex compositeVertex = edge.getInVertex();
+                            vertices.push(compositeVertex);
+                        }
                     }
                     break;
                 case ARRAY:
@@ -203,13 +216,29 @@ public abstract class DeleteHandlerV1 {
                     if (arrType.getElementType().getTypeCategory() != TypeCategory.OBJECT_ID_TYPE) {
                         continue;
                     }
-                    Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(vertex, edgeLabel);
-                    if (edges != null) {
-                        while (edges.hasNext()) {
-                            edge = edges.next();
-                            if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
-                                AtlasVertex compositeVertex = edge.getInVertex();
-                                vertices.push(compositeVertex);
+
+                    if (attributeInfo.getAttributeDef().isSoftReferenced()) {
+                        List                softRefVal = vertex.getListProperty(attributeInfo.getVertexPropertyName(), List.class);
+                        List<AtlasObjectId> refObjIds  = AtlasEntityUtil.parseSoftRefValue(softRefVal);
+
+                        if (CollectionUtils.isNotEmpty(refObjIds)) {
+                            for (AtlasObjectId refObjId : refObjIds) {
+                                AtlasVertex refVertex = AtlasGraphUtilsV1.findByGuid(refObjId.getGuid());
+
+                                if (refVertex != null) {
+                                    vertices.push(refVertex);
+                                }
+                            }
+                        }
+                    } else {
+                        Iterator<AtlasEdge> edges = graphHelper.getOutGoingEdgesByLabel(vertex, edgeLabel);
+                        if (edges != null) {
+                            while (edges.hasNext()) {
+                                AtlasEdge edge = edges.next();
+                                if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
+                                    AtlasVertex compositeVertex = edge.getInVertex();
+                                    vertices.push(compositeVertex);
+                                }
                             }
                         }
                     }
@@ -220,15 +249,31 @@ public abstract class DeleteHandlerV1 {
                     if (valueTypeCategory != TypeCategory.OBJECT_ID_TYPE) {
                         continue;
                     }
-                    String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(entityType, attributeInfo.getName());
-                    List<String> keys = vertex.getProperty(propertyName, List.class);
-                    if (keys != null) {
-                        for (String key : keys) {
-                            String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, key);
-                            edge = graphHelper.getEdgeForLabel(vertex, mapEdgeLabel);
-                            if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
-                                AtlasVertex compositeVertex = edge.getInVertex();
-                                vertices.push(compositeVertex);
+
+                    if (attributeInfo.getAttributeDef().isSoftReferenced()) {
+                        Map                        softRefVal = vertex.getProperty(attributeInfo.getVertexPropertyName(), Map.class);
+                        Map<String, AtlasObjectId> refObjIds  = AtlasEntityUtil.parseSoftRefValue(softRefVal);
+
+                        if (MapUtils.isNotEmpty(refObjIds)) {
+                            for (AtlasObjectId refObjId : refObjIds.values()) {
+                                AtlasVertex refVertex = AtlasGraphUtilsV1.findByGuid(refObjId.getGuid());
+
+                                if (refVertex != null) {
+                                    vertices.push(refVertex);
+                                }
+                            }
+                        }
+                    } else {
+                        String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(entityType, attributeInfo.getName());
+                        List<String> keys = vertex.getProperty(propertyName, List.class);
+                        if (keys != null) {
+                            for (String key : keys) {
+                                String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, key);
+                                AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, mapEdgeLabel);
+                                if (edge != null && AtlasGraphUtilsV1.getState(edge) == AtlasEntity.Status.ACTIVE) {
+                                    AtlasVertex compositeVertex = edge.getInVertex();
+                                    vertices.push(compositeVertex);
+                                }
                             }
                         }
                     }
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
index a9bf55a..0f9f763 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
@@ -51,6 +51,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasType;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.atlas.type.AtlasTypeUtil;
+import org.apache.atlas.utils.AtlasEntityUtil;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
@@ -73,7 +74,6 @@ import static org.apache.atlas.repository.graph.GraphHelper.string;
 public class EntityGraphMapper {
     private static final Logger LOG = LoggerFactory.getLogger(EntityGraphMapper.class);
 
-    private static final String SOFT_REF_FORMAT      = "%s:%s";
     private static final int    INDEXED_STR_SAFE_LEN = AtlasConfiguration.GRAPHSTORE_INDEXED_STRING_SAFE_LENGTH.getInt();
 
     private final GraphHelper             graphHelper = GraphHelper.getInstance();
@@ -353,25 +353,24 @@ public class EntityGraphMapper {
         }
     }
 
-    private Object mapSoftRefValue(AttributeMutationContext ctx, EntityMutationContext context) {
-        if(ctx.getValue() != null && !(ctx.getValue() instanceof AtlasObjectId)) {
-            LOG.warn("mapSoftRefValue: Was expecting AtlasObjectId, but found: {}", ctx.getValue().getClass());
-            return null;
-        }
+    private String mapSoftRefValue(AttributeMutationContext ctx, EntityMutationContext context) {
+        String ret = null;
 
-        String softRefValue = null;
-        if(ctx.getValue() != null) {
+        if (ctx.getValue() instanceof AtlasObjectId) {
             AtlasObjectId objectId = (AtlasObjectId) ctx.getValue();
-            String resolvedGuid = AtlasTypeUtil.isUnAssignedGuid(objectId.getGuid())
-                                    ? context.getGuidAssignments().get(objectId.getGuid())
-                                    : objectId.getGuid();
+            String        typeName = objectId.getTypeName();
+            String        guid     = AtlasTypeUtil.isUnAssignedGuid(objectId.getGuid()) ? context.getGuidAssignments().get(objectId.getGuid()) : objectId.getGuid();
 
-            softRefValue = String.format(SOFT_REF_FORMAT, objectId.getTypeName(), resolvedGuid);
-        }
+            ret = AtlasEntityUtil.formatSoftRefValue(typeName, guid);
 
-        AtlasGraphUtilsV1.setEncodedProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), softRefValue);
+            AtlasGraphUtilsV1.setEncodedProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), ret);
+        } else {
+            if (ctx.getValue() != null) {
+                LOG.warn("mapSoftRefValue: Was expecting AtlasObjectId, but found: {}", ctx.getValue().getClass());
+            }
+        }
 
-        return softRefValue;
+        return ret;
     }
 
     private void addInverseReference(AttributeMutationContext ctx, AtlasAttribute inverseAttribute, AtlasEdge edge) throws AtlasBaseException {
@@ -1172,12 +1171,4 @@ public class EntityGraphMapper {
 
         return ret;
     }
-
-    public static String getSoftRefFormattedValue(AtlasObjectId objectId) {
-        return getSoftRefFormattedString(objectId.getTypeName(), objectId.getGuid());
-    }
-
-    private static String getSoftRefFormattedString(String typeName, String resolvedGuid) {
-        return String.format(SOFT_REF_FORMAT, typeName, resolvedGuid);
-    }
 }
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
index 549e595..652265c 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
@@ -41,6 +41,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasType;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.atlas.type.AtlasTypeUtil;
+import org.apache.atlas.utils.AtlasEntityUtil;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -51,13 +52,7 @@ import org.springframework.stereotype.Component;
 import javax.inject.Inject;
 import java.math.BigDecimal;
 import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.*;
 import static org.apache.atlas.repository.graph.GraphHelper.EDGE_LABEL_PREFIX;
@@ -69,9 +64,6 @@ public final class EntityGraphRetriever {
 
     private static final String NAME           = "name";
     private static final String QUALIFIED_NAME = "qualifiedName";
-    private static final String SOFT_REFERENCE_FORMAT_SEPERATOR = ":";
-    private static final int SOFT_REFERENCE_FORMAT_INDEX_TYPE_NAME = 0;
-    private static final int SOFT_REFERENCE_FORMAT_INDEX_GUID = 1;
     private static final String MAP_VALUE_FORMAT = "%s.%s";
 
     private static final GraphHelper graphHelper = GraphHelper.getInstance();
@@ -475,21 +467,21 @@ public final class EntityGraphRetriever {
                 break;
             case OBJECT_ID_TYPE:
                 if(attribute.getAttributeDef().isSoftReferenced()) {
-                    ret = mapVertexToObjectIdForSoftRef(entityVertex, attribute.getVertexPropertyName());
+                    ret = mapVertexToObjectIdForSoftRef(entityVertex, attribute, entityExtInfo, isMinExtInfo);
                 } else {
                     ret = mapVertexToObjectId(entityVertex, edgeLabel, null, entityExtInfo, isOwnedAttribute, isMinExtInfo);
                 }
                 break;
             case ARRAY:
                 if(attribute.getAttributeDef().isSoftReferenced()) {
-                    ret = mapVertexToArrayForSoftRef(entityVertex, attribute.getVertexPropertyName());
+                    ret = mapVertexToArrayForSoftRef(entityVertex, attribute, entityExtInfo, isMinExtInfo);
                 } else {
                     ret = mapVertexToArray(entityVertex, (AtlasArrayType) attrType, qualifiedName, entityExtInfo, isOwnedAttribute, isMinExtInfo);
                 }
                 break;
             case MAP:
                 if(attribute.getAttributeDef().isSoftReferenced()) {
-                    ret = mapVertexToMapForSoftRef(entityVertex, attribute.getVertexPropertyName());
+                    ret = mapVertexToMapForSoftRef(entityVertex, attribute, entityExtInfo, isMinExtInfo);
                 } else {
                     ret = mapVertexToMap(entityVertex, (AtlasMapType) attrType, qualifiedName, entityExtInfo, isOwnedAttribute, isMinExtInfo);
                 }
@@ -502,76 +494,84 @@ public final class EntityGraphRetriever {
         return ret;
     }
 
-    private Map<String, AtlasObjectId> mapVertexToMapForSoftRef(AtlasVertex entityVertex, String propertyName) {
-        List mapKeys = entityVertex.getListProperty(propertyName);
-        if (CollectionUtils.isEmpty(mapKeys)) {
-            return null;
-        }
+    private Map<String, AtlasObjectId> mapVertexToMapForSoftRef(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) {
+        Map<String, AtlasObjectId> ret     = null;
+        List                       mapKeys = entityVertex.getListProperty(attribute.getVertexPropertyName());
 
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Mapping map attribute {} for vertex {}", propertyName, entityVertex);
-        }
+        if (CollectionUtils.isNotEmpty(mapKeys)) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Mapping map attribute {} for vertex {}", attribute.getVertexPropertyName(), entityVertex);
+            }
 
-        Map<String, AtlasObjectId> ret          = new HashMap<>(mapKeys.size());
+            ret = new HashMap<>(mapKeys.size());
 
-        for (Object mapKey : mapKeys) {
-            String        keyPropertyName        = String.format(MAP_VALUE_FORMAT, propertyName, mapKey);
-            String        encodedKeyPropertyName = encodePropertyKey(keyPropertyName);
-            AtlasObjectId mapValue               = mapVertexToObjectIdForSoftRef(entityVertex, encodedKeyPropertyName);
+            for (Object mapKey : mapKeys) {
+                String        keyPropertyName = String.format(MAP_VALUE_FORMAT, attribute.getVertexPropertyName(), encodePropertyKey(Objects.toString(mapKey)));
+                AtlasObjectId mapValue        = getAtlasObjectIdFromSoftRefFormat(entityVertex.getProperty(keyPropertyName, String.class), attribute, entityExtInfo, isMinExtInfo);
 
-            if (mapValue != null) {
-                ret.put((String) mapKey, mapValue);
+                if (mapValue != null) {
+                    ret.put(Objects.toString(mapKey), mapValue);
+                }
             }
         }
 
         return ret;
     }
 
-    private List<AtlasObjectId> mapVertexToArrayForSoftRef(AtlasVertex entityVertex, String propertyName) {
-        List list = entityVertex.getListProperty(propertyName);
-        if (CollectionUtils.isEmpty(list)) {
-            return null;
-        }
+    private List<AtlasObjectId> mapVertexToArrayForSoftRef(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) {
+        List<AtlasObjectId> ret  = null;
+        List                list = entityVertex.getListProperty(attribute.getVertexPropertyName());
 
-        List<AtlasObjectId> objectIds = new ArrayList<>();
-        for (Object o : list) {
-            if (!(o instanceof String)) {
-                continue;
-            }
+        if (CollectionUtils.isNotEmpty(list)) {
+            ret = new ArrayList<>();
 
-            AtlasObjectId objectId = getAtlasObjectIdFromSoftRefFormat((String) o);
-            if(objectId == null) {
-                continue;
-            }
+            for (Object o : list) {
+                AtlasObjectId objectId = getAtlasObjectIdFromSoftRefFormat(Objects.toString(o), attribute, entityExtInfo, isMinExtInfo);
 
-            objectIds.add(objectId);
+                if (objectId != null) {
+                    ret.add(objectId);
+                }
+            }
         }
 
-        return objectIds;
+        return ret;
     }
 
-    private AtlasObjectId mapVertexToObjectIdForSoftRef(AtlasVertex entityVertex, String vertexPropertyName) {
-        String rawValue = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, String.class);
-        if(StringUtils.isEmpty(rawValue)) {
-            return null;
-        }
+    private AtlasObjectId mapVertexToObjectIdForSoftRef(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) {
+        String rawValue = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, attribute.getVertexPropertyName(), String.class);
 
-        return getAtlasObjectIdFromSoftRefFormat(rawValue);
+        return StringUtils.isNotEmpty(rawValue) ? getAtlasObjectIdFromSoftRefFormat(rawValue, attribute, entityExtInfo, isMinExtInfo) : null;
     }
 
-    private AtlasObjectId getAtlasObjectIdFromSoftRefFormat(String rawValue) {
-        if(StringUtils.isEmpty(rawValue)) {
-            return null;
-        }
+    private AtlasObjectId getAtlasObjectIdFromSoftRefFormat(String rawValue, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) {
+        AtlasObjectId ret = AtlasEntityUtil.parseSoftRefValue(rawValue);
 
-        String[] objectIdParts = StringUtils.split(rawValue, SOFT_REFERENCE_FORMAT_SEPERATOR);
-        if(objectIdParts.length < 2) {
-            LOG.warn("Expecting value to be formatted for softRef. Instead found: {}", rawValue);
-            return null;
+        if (ret != null) {
+            if (entityExtInfo != null && attribute.isOwnedRef()) {
+                try {
+                    AtlasVertex referenceVertex = getEntityVertex(ret.getGuid());
+
+                    if (referenceVertex != null) {
+                        final AtlasEntity entity;
+
+                        if (isMinExtInfo) {
+                            entity = mapVertexToAtlasEntityMin(referenceVertex, entityExtInfo);
+                        } else {
+                            entity = mapVertexToAtlasEntity(referenceVertex, entityExtInfo);
+                        }
+
+                        if (entity != null) {
+                            ret = toAtlasObjectId(entity);
+                        }
+                    }
+                } catch (AtlasBaseException excp) {
+                    LOG.info("failed to retrieve soft-referenced entity(typeName={}, guid={}); errorCode={}. Ignoring", ret.getTypeName(), ret.getGuid(), excp.getAtlasErrorCode());
+                }
+
+            }
         }
 
-        return new AtlasObjectId(objectIdParts[SOFT_REFERENCE_FORMAT_INDEX_GUID],
-                objectIdParts[SOFT_REFERENCE_FORMAT_INDEX_TYPE_NAME]);
+        return ret;
     }
 
     private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasMapType atlasMapType, final String propertyName,
@@ -766,4 +766,25 @@ public final class EntityGraphRetriever {
     public AtlasEntityHeader toAtlasEntityHeader(AtlasVertex atlasVertex, Set<String> attributes) throws AtlasBaseException {
         return atlasVertex != null ? mapVertexToAtlasEntityHeader(atlasVertex, attributes) : null;
     }
+
+    public AtlasObjectId toAtlasObjectId(AtlasEntity entity) {
+        AtlasObjectId   ret        = null;
+        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
+
+        if (entityType != null) {
+            Map<String, Object> uniqueAttributes = new HashMap<>();
+
+            for (String attributeName : entityType.getUniqAttributes().keySet()) {
+                Object attrValue = entity.getAttribute(attributeName);
+
+                if (attrValue != null) {
+                    uniqueAttributes.put(attributeName, attrValue);
+                }
+            }
+
+            ret = new AtlasObjectId(entity.getGuid(), entity.getTypeName(), uniqueAttributes);
+        }
+
+        return ret;
+    }
 }