Repository: incubator-atlas
Updated Branches:
  refs/heads/master a7870cded -> 5d8fae555


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5d8fae55/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/MapVertexMapper.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/MapVertexMapper.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/MapVertexMapper.java
index efafcc9..bb7aeb6 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/MapVertexMapper.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/MapVertexMapper.java
@@ -20,16 +20,13 @@ package org.apache.atlas.repository.store.graph.v1;
 
 import com.google.common.base.Optional;
 import com.google.inject.Inject;
-import com.google.inject.Singleton;
 import org.apache.atlas.AtlasErrorCode;
 import org.apache.atlas.AtlasException;
 import org.apache.atlas.exception.AtlasBaseException;
-import org.apache.atlas.model.TypeCategory;
-import org.apache.atlas.model.typedef.AtlasStructDef;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
 import org.apache.atlas.repository.graph.GraphHelper;
 import org.apache.atlas.repository.graphdb.AtlasEdge;
 import org.apache.atlas.repository.graphdb.AtlasVertex;
-import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasMapType;
 import org.apache.atlas.type.AtlasStructType;
 import org.apache.atlas.type.AtlasType;
@@ -37,7 +34,6 @@ import org.apache.commons.collections.MapUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.inject.Provider;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -158,7 +154,7 @@ public class MapVertexMapper implements 
InstanceGraphMapper<Map> {
     //Remove unused entries from map
     private Map<String, Object> removeUnusedMapEntries(
         AtlasStructType entityType,
-        AtlasMapType mapType, AtlasStructDef.AtlasAttributeDef attributeDef,
+        AtlasMapType mapType, AtlasAttributeDef attributeDef,
         AtlasVertex instanceVertex, String propertyName,
         Map<String, Object> currentMap,
         Map<String, Object> newMap)

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5d8fae55/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/StructVertexMapper.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/StructVertexMapper.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/StructVertexMapper.java
index 22851ca..ff1a702 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/StructVertexMapper.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/StructVertexMapper.java
@@ -25,10 +25,9 @@ import org.apache.atlas.model.TypeCategory;
 import org.apache.atlas.model.instance.AtlasEntity;
 import org.apache.atlas.model.instance.AtlasStruct;
 import org.apache.atlas.model.instance.EntityMutations;
-import org.apache.atlas.model.typedef.AtlasStructDef;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
 import org.apache.atlas.repository.Constants;
 import org.apache.atlas.repository.RepositoryException;
-import org.apache.atlas.repository.graph.AtlasEdgeLabel;
 import org.apache.atlas.repository.graph.AtlasGraphProvider;
 import org.apache.atlas.repository.graph.GraphHelper;
 import org.apache.atlas.repository.graphdb.AtlasEdge;
@@ -86,7 +85,7 @@ public class StructVertexMapper implements 
InstanceGraphMapper<AtlasEdge> {
     }
 
     public static boolean shouldManageChildReferences(AtlasStructType type, 
String attributeName) {
-        return type.isMappedFromRefAttribute(attributeName);
+        return (type instanceof AtlasEntityType) && 
((AtlasEntityType)type).isMappedFromRefAttribute(attributeName);
     }
 
     /**
@@ -186,7 +185,7 @@ public class StructVertexMapper implements 
InstanceGraphMapper<AtlasEdge> {
         return ctx.getValue();
     }
 
-    private AtlasEdge createVertex(AtlasStructType parentType, AtlasStructType 
attrType, AtlasStructDef.AtlasAttributeDef attributeDef, AtlasStruct struct, 
AtlasVertex referringVertex, String edgeLabel) throws AtlasBaseException {
+    private AtlasEdge createVertex(AtlasStructType parentType, AtlasStructType 
attrType, AtlasAttributeDef attributeDef, AtlasStruct struct, AtlasVertex 
referringVertex, String edgeLabel) throws AtlasBaseException {
         AtlasVertex vertex = createVertexTemplate(struct, attrType);
         mapAttributestoVertex(EntityMutations.EntityOperation.CREATE, 
attrType, struct, vertex);
 
@@ -198,7 +197,7 @@ public class StructVertexMapper implements 
InstanceGraphMapper<AtlasEdge> {
         }
     }
 
-    private void updateVertex(AtlasStructType parentType, AtlasStructType 
structAttributeType, AtlasStructDef.AtlasAttributeDef attributeDef, AtlasStruct 
value, AtlasVertex structVertex) throws AtlasBaseException {
+    private void updateVertex(AtlasStructType parentType, AtlasStructType 
structAttributeType, AtlasAttributeDef attributeDef, AtlasStruct value, 
AtlasVertex structVertex) throws AtlasBaseException {
         mapAttributestoVertex(EntityMutations.EntityOperation.CREATE, 
structAttributeType, value, structVertex);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5d8fae55/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
----------------------------------------------------------------------
diff --git 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
index 2698504..76308a0 100644
--- 
a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
+++ 
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/UniqAttrBasedEntityResolver.java
@@ -107,7 +107,7 @@ public class UniqAttrBasedEntityResolver implements 
EntityResolver {
 
         for (AtlasStructType.AtlasAttribute attr : 
entityType.getAllAttributes().values()) {
             if (attr.getAttributeDef().getIsUnique()) {
-                Object attrVal = 
entity.getAttribute(attr.getAttributeDef().getName());
+                Object attrVal = entity.getAttribute(attr.getName());
                 if (attrVal != null) {
                     String qualifiedAttrName = 
attr.getQualifiedAttributeName();
                     AtlasVertex vertex = null;

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5d8fae55/webapp/src/main/java/org/apache/atlas/util/RestUtils.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/util/RestUtils.java 
b/webapp/src/main/java/org/apache/atlas/util/RestUtils.java
index 5e69262..f928a06 100644
--- a/webapp/src/main/java/org/apache/atlas/util/RestUtils.java
+++ b/webapp/src/main/java/org/apache/atlas/util/RestUtils.java
@@ -479,7 +479,7 @@ public final class RestUtils {
                 // 2. [ foreignKey(onDelete=cascade) -> reverseAttribute ]
                 AtlasStructType structType      = (AtlasStructType) 
registry.getType(structDef.getName());
                 boolean         isForeignKey    = 
structType.isForeignKeyAttribute(attrDef.getName());
-                boolean         isMappedFromRef = 
structType.isMappedFromRefAttribute(attrDef.getName());
+                boolean         isMappedFromRef = (structType instanceof 
AtlasEntityType) && 
((AtlasEntityType)structType).isMappedFromRefAttribute(attrDef.getName());
                 AtlasType       attrType        = 
structType.getAttributeType(attrDef.getName());
 
                 if (attrType != null && isForeignKey) {
@@ -488,7 +488,7 @@ public final class RestUtils {
                     }
 
                     if (attrType.getTypeCategory() == TypeCategory.ENTITY) {
-                        reverseAttribName = ((AtlasStructType) attrType).
+                        reverseAttribName = ((AtlasEntityType) attrType).
                                                  
getMappedFromRefAttribute(structType.getTypeName(), attrDef.getName());
                     }
                 }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5d8fae55/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasStructFormatConverter.java
----------------------------------------------------------------------
diff --git 
a/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasStructFormatConverter.java
 
b/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasStructFormatConverter.java
index 8777510..8a5c9be 100644
--- 
a/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasStructFormatConverter.java
+++ 
b/webapp/src/main/java/org/apache/atlas/web/adapters/AtlasStructFormatConverter.java
@@ -124,20 +124,20 @@ public class AtlasStructFormatConverter extends 
AtlasAbstractFormatConverter {
         if (MapUtils.isNotEmpty(attributes)) {
             ret = new HashMap<>();
 
-            for (AtlasStructType.AtlasAttribute attr : 
getAttributes(structType)) {
-                AtlasType attrType = 
structType.getAttributeType(attr.getAttributeDef().getName());
+            for (AtlasStructType.AtlasAttribute attr : 
structType.getAllAttributes().values()) {
+                AtlasType attrType = attr.getAttributeType();
 
                 if (attrType == null) {
-                    LOG.warn("ignored attribute {}.{}: failed to find 
AtlasType", structType.getTypeName(), attr.getAttributeDef().getName());
+                    LOG.warn("ignored attribute {}.{}: failed to find 
AtlasType", structType.getTypeName(), attr.getName());
                     continue;
                 }
 
                 AtlasFormatConverter attrConverter = 
converterRegistry.getConverter(attrType.getTypeCategory());
 
-                Object v2Value = 
attributes.get(attr.getAttributeDef().getName());
+                Object v2Value = attributes.get(attr.getName());
                 Object v1Value = attrConverter.fromV2ToV1(v2Value, attrType);
 
-                ret.put(attr.getAttributeDef().getName(), v1Value);
+                ret.put(attr.getName(), v1Value);
             }
         }
 
@@ -150,11 +150,11 @@ public class AtlasStructFormatConverter extends 
AtlasAbstractFormatConverter {
         if (MapUtils.isNotEmpty(attributes)) {
             ret = new HashMap<>();
 
-            for (AtlasStructType.AtlasAttribute attr : 
getAttributes(structType)) {
-                AtlasType            attrType      = 
structType.getAttributeType(attr.getAttributeDef().getName());
+            for (AtlasStructType.AtlasAttribute attr : 
structType.getAllAttributes().values()) {
+                AtlasType            attrType      = attr.getAttributeType();
                 AtlasFormatConverter attrConverter = 
converterRegistry.getConverter(attrType.getTypeCategory());
 
-                Object v1Value = 
attributes.get(attr.getAttributeDef().getName());
+                Object v1Value = attributes.get(attr.getName());
                 Object v2Value = attrConverter.fromV1ToV2(v1Value, attrType);
 
                 ret.put(attr.getAttributeDef().getName(), v2Value);

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5d8fae55/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
----------------------------------------------------------------------
diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java 
b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
index ee1174a..aa209f9 100644
--- a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
+++ b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java
@@ -26,7 +26,7 @@ import org.apache.atlas.model.instance.AtlasClassification;
 import org.apache.atlas.model.instance.AtlasEntity;
 import org.apache.atlas.model.instance.AtlasEntityWithAssociations;
 import org.apache.atlas.model.instance.EntityMutationResponse;
-import org.apache.atlas.model.typedef.AtlasStructDef;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
 import org.apache.atlas.services.MetadataService;
 import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasType;
@@ -390,8 +390,9 @@ public class EntityREST {
      * @param attributeName  the name of the attribute
      */
     private void validateUniqueAttribute(AtlasEntityType entityType, String 
attributeName) throws AtlasBaseException {
-        AtlasStructDef.AtlasAttributeDef attribute = 
entityType.getAttributeDef(attributeName);
-        if (attribute != null && !attribute.getIsUnique()) {
+        AtlasAttributeDef attribute = 
entityType.getAttributeDef(attributeName);
+
+        if (attribute == null || !attribute.getIsUnique()) {
             throw new 
AtlasBaseException(AtlasErrorCode.ATTRIBUTE_UNIQUE_INVALID, 
entityType.getTypeName(), attributeName);
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/5d8fae55/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java
----------------------------------------------------------------------
diff --git 
a/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java
 
b/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java
index 8eacc73..243d099 100644
--- 
a/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java
+++ 
b/webapp/src/test/java/org/apache/atlas/web/resources/TypedefsJerseyResourceIT.java
@@ -30,6 +30,7 @@ import org.apache.atlas.model.typedef.AtlasEntityDef;
 import org.apache.atlas.model.typedef.AtlasEnumDef;
 import org.apache.atlas.model.typedef.AtlasStructDef;
 import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
 import org.apache.atlas.model.typedef.AtlasTypesDef;
 import org.apache.atlas.type.AtlasTypeUtil;
 import org.apache.atlas.typesystem.types.DataTypes;
@@ -243,7 +244,7 @@ public class TypedefsJerseyResourceIT extends 
BaseResourceIT {
 
     @Test
     public void testListTypesByFilter() throws Exception {
-        AtlasStructDef.AtlasAttributeDef attr = 
AtlasTypeUtil.createOptionalAttrDef("attr", "string");
+        AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", 
"string");
         AtlasEntityDef classDefA = AtlasTypeUtil.createClassTypeDef("A" + 
randomString(), ImmutableSet.<String>of(), attr);
         AtlasEntityDef classDefA1 = AtlasTypeUtil.createClassTypeDef("A1" + 
randomString(), ImmutableSet.of(classDefA.getName()), attr);
         AtlasEntityDef classDefB = AtlasTypeUtil.createClassTypeDef("B" + 
randomString(), ImmutableSet.<String>of(), attr);
@@ -296,7 +297,7 @@ public class TypedefsJerseyResourceIT extends 
BaseResourceIT {
                                 false,
                                 Cardinality.SINGLE, 1, 1,
                                 true, true,
-                                
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
+                                Collections.<AtlasConstraintDef>emptyList()));
         atlasTypesDef.getEntityDefs().add(tableTypeDefinition);
 
         AtlasClassificationDef fetlTypeDefinition = AtlasTypeUtil

Reply via email to