ATLAS-1949: Fix coverity scan issues and IT failures due to ATLAS-1943

Signed-off-by: Madhan Neethiraj <mad...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/c3808cf1
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/c3808cf1
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/c3808cf1

Branch: refs/heads/feature-odf
Commit: c3808cf1f9010467801a0a1567d60a407fed4f79
Parents: 18745cf
Author: Sarath Subramanian <ssubraman...@hortonworks.com>
Authored: Thu Jul 13 13:06:59 2017 -0700
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Thu Jul 13 13:29:14 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/atlas/AtlasErrorCode.java   |  1 +
 .../atlas/repository/graph/GraphHelper.java     |  4 ++++
 .../store/graph/v1/EntityGraphMapper.java       |  8 +++----
 .../store/graph/v1/EntityGraphRetriever.java    | 23 ++++++++++++++------
 4 files changed, 25 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/c3808cf1/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java 
b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
index fd1b004..b24f99f 100644
--- a/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
+++ b/intg/src/main/java/org/apache/atlas/AtlasErrorCode.java
@@ -88,6 +88,7 @@ public enum AtlasErrorCode {
     RELATIONSHIPDEF_END1_NAME_INVALID(400, "ATLAS-400-00-041", "{0}: invalid 
end1 name. Name must not contain query keywords"),
     RELATIONSHIPDEF_END2_NAME_INVALID(400, "ATLAS-400-00-042", "{0}: invalid 
end2 name. Name must not contain query keywords"),
     RELATIONSHIPDEF_NOT_DEFINED(400, "ATLAS-400-00-043", "No relationshipDef 
defined between {0} and {1} on attribute: {2}"),
+    RELATIONSHIPDEF_INVALID(400, "ATLAS-400-00-044", "Invalid relationshipDef: 
{0}"),
     // All Not found enums go here
     TYPE_NAME_NOT_FOUND(404, "ATLAS-404-00-001", "Given typename {0} was 
invalid"),
     TYPE_GUID_NOT_FOUND(404, "ATLAS-404-00-002", "Given type guid {0} was 
invalid"),

http://git-wip-us.apache.org/repos/asf/atlas/blob/c3808cf1/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java 
b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
index c5e32d8..6f6d74b 100755
--- 
a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
@@ -1269,6 +1269,10 @@ public final class GraphHelper {
                 }
             }
 
+            if (ret == null) {
+                ret = relationshipTypes.get(0).getRelationshipDef();
+            }
+
         } else {
             //relationshipTypes will have at least one relationshipDef
             ret = relationshipTypes.get(0).getRelationshipDef();

http://git-wip-us.apache.org/repos/asf/atlas/blob/c3808cf1/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
----------------------------------------------------------------------
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 68f8370..157f8cd 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
@@ -328,7 +328,7 @@ public class EntityGraphMapper {
 
                     newEdge = mapObjectIdValueUsingRelationship(ctx, context);
 
-                    if (ctx.getAttribute().getInverseRefAttribute() != null) {
+                    if (newEdge != null && 
ctx.getAttribute().getInverseRefAttribute() != null) {
                         // Update the inverse reference using relationship on 
the target entity
                         
addInverseReference(ctx.getAttribute().getInverseRefAttribute(), newEdge);
                     }
@@ -380,13 +380,13 @@ public class EntityGraphMapper {
         case ARRAY:
             // Add edge ID to property value
             List<String> elements = inverseVertex.getProperty(propertyName, 
List.class);
-            if (elements == null) {
+            if (newEdge != null && elements == null) {
                 elements = new ArrayList<>();
                 elements.add(newEdge.getId().toString());
                 inverseVertex.setProperty(propertyName, elements);
             }
             else {
-               if (!elements.contains(newEdge.getId().toString())) {
+               if (newEdge != null && 
!elements.contains(newEdge.getId().toString())) {
                     elements.add(newEdge.getId().toString());
                     inverseVertex.setProperty(propertyName, elements);
                }
@@ -945,7 +945,7 @@ public class EntityGraphMapper {
         String    newEntityId     = 
AtlasGraphUtilsV1.getIdFromVertex(entityVertex);
         AtlasEdge ret             = currentEdge;
 
-        if (!currentEntityId.equals(newEntityId) && entityVertex != null) {
+        if (!currentEntityId.equals(newEntityId)) {
             // create a new relationship edge to the new attribute vertex from 
the instance
             String relationshipName = 
AtlasGraphUtilsV1.getTypeName(currentEdge);
 

http://git-wip-us.apache.org/repos/asf/atlas/blob/c3808cf1/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java
----------------------------------------------------------------------
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 e919d1c..4ac00a3 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
@@ -419,13 +419,18 @@ public final class EntityGraphRetriever {
 
     private Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, 
AtlasEntityType entityType, AtlasAttribute attribute,
                                                     AtlasEntityExtInfo 
entityExtInfo) throws AtlasBaseException {
-        Object                  ret                = null;
-        AtlasRelationshipDef    relationshipDef    = 
graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName());
-        AtlasRelationshipEndDef endDef1            = 
relationshipDef.getEndDef1();
-        AtlasRelationshipEndDef endDef2            = 
relationshipDef.getEndDef2();
-        AtlasEntityType         endDef1Type        = 
typeRegistry.getEntityTypeByName(endDef1.getType());
-        AtlasEntityType         endDef2Type        = 
typeRegistry.getEntityTypeByName(endDef2.getType());
-        AtlasRelationshipEndDef attributeEndDef    = null;
+        Object               ret             = null;
+        AtlasRelationshipDef relationshipDef = 
graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName());
+
+        if (relationshipDef == null) {
+            throw new 
AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is 
null");
+        }
+
+        AtlasRelationshipEndDef endDef1         = relationshipDef.getEndDef1();
+        AtlasRelationshipEndDef endDef2         = relationshipDef.getEndDef2();
+        AtlasEntityType         endDef1Type     = 
typeRegistry.getEntityTypeByName(endDef1.getType());
+        AtlasEntityType         endDef2Type     = 
typeRegistry.getEntityTypeByName(endDef2.getType());
+        AtlasRelationshipEndDef attributeEndDef = null;
 
         if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && 
StringUtils.equals(endDef1.getName(), attribute.getName())) {
             attributeEndDef = endDef1;
@@ -434,6 +439,10 @@ public final class EntityGraphRetriever {
             attributeEndDef = endDef2;
         }
 
+        if (attributeEndDef == null) {
+            throw new 
AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, 
relationshipDef.toString());
+        }
+
         String relationshipLabel = attribute.getRelationshipEdgeLabel();
 
         switch (attributeEndDef.getCardinality()) {

Reply via email to