atlas-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject incubator-atlas git commit: ATLAS-1646: added validation of classification attributes
Date Tue, 07 Mar 2017 02:18:43 GMT
Repository: incubator-atlas
Updated Branches:
  refs/heads/master dc89e7f44 -> 6a4fcb95d


ATLAS-1646: added validation of classification attributes


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

Branch: refs/heads/master
Commit: 6a4fcb95dc1b6479cde4d0e29442b98564c219d0
Parents: dc89e7f
Author: ashutoshm <amestry@hortonworks.com>
Authored: Mon Mar 6 17:19:25 2017 -0800
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Mon Mar 6 18:08:10 2017 -0800

----------------------------------------------------------------------
 .../apache/atlas/type/AtlasBuiltInTypes.java    | 16 ++++++++-----
 .../apache/atlas/type/TestAtlasDateType.java    |  6 ++---
 .../store/graph/v1/AtlasEntityStoreV1.java      | 25 ++++++++++++++++++++
 3 files changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6a4fcb95/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java b/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
index 0b124b2..2c80aa3 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasBuiltInTypes.java
@@ -18,18 +18,18 @@
 package org.apache.atlas.type;
 
 
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.ParseException;
-import java.util.Date;
-import java.util.Map;
-
 import org.apache.atlas.model.TypeCategory;
 import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.lang.StringUtils;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Map;
+
 
 /**
  * Built-in types in Atlas.
@@ -449,6 +449,10 @@ public class AtlasBuiltInTypes {
                 return true;
             }
 
+            if (obj instanceof String && StringUtils.isEmpty((String) obj)) {
+                return true;
+            }
+
             return getNormalizedValue(obj) != null;
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6a4fcb95/intg/src/test/java/org/apache/atlas/type/TestAtlasDateType.java
----------------------------------------------------------------------
diff --git a/intg/src/test/java/org/apache/atlas/type/TestAtlasDateType.java b/intg/src/test/java/org/apache/atlas/type/TestAtlasDateType.java
index 1b3bbc7..6236a6d 100644
--- a/intg/src/test/java/org/apache/atlas/type/TestAtlasDateType.java
+++ b/intg/src/test/java/org/apache/atlas/type/TestAtlasDateType.java
@@ -34,7 +34,7 @@ public class TestAtlasDateType {
     private final AtlasDateType dateType = new AtlasDateType();
 
     private final Object[] validValues    = {
-        null, Byte.valueOf((byte)1), Short.valueOf((short)1), Integer.valueOf(1), Long.valueOf(1L),
Float.valueOf(1),
+        null, "", Byte.valueOf((byte)1), Short.valueOf((short)1), Integer.valueOf(1), Long.valueOf(1L),
Float.valueOf(1),
         Double.valueOf(1), BigInteger.valueOf(1), BigDecimal.valueOf(1), "1",
     };
 
@@ -43,7 +43,7 @@ public class TestAtlasDateType {
         Double.valueOf(-1), BigInteger.valueOf(-1), BigDecimal.valueOf(-1), "-1",
     };
 
-    private final Object[] invalidValues  = { "", "12ab", "abcd", "-12ab", };
+    private final Object[] invalidValues  = { "12ab", "abcd", "-12ab", };
 
     private final Date   now    = new Date();
     private final String strNow = AtlasBaseTypeDef.DATE_FORMATTER.format(now);
@@ -78,7 +78,7 @@ public class TestAtlasDateType {
         assertNull(dateType.getNormalizedValue(null), "value=" + null);
 
         for (Object value : validValues) {
-            if (value == null) {
+            if (value == null || value == "") {
                 continue;
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6a4fcb95/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
index 518b52b..cce3fca 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java
@@ -36,6 +36,7 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
 import org.apache.atlas.repository.store.graph.AtlasEntityStore;
 import org.apache.atlas.repository.store.graph.EntityGraphDiscovery;
 import org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext;
+import org.apache.atlas.type.AtlasClassificationType;
 import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
 import org.apache.atlas.type.AtlasType;
@@ -427,6 +428,10 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
             LOG.debug("Adding classifications={} to entity={}", classifications, guid);
         }
 
+        for (AtlasClassification classification : classifications) {
+            validateAndNormalize(classification);
+        }
+
         EntityGraphMapper graphMapper = new EntityGraphMapper(deleteHandler, typeRegistry);
         graphMapper.addClassifications(new EntityMutationContext(), guid, classifications);
 
@@ -450,6 +455,8 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
 
         EntityGraphMapper graphMapper = new EntityGraphMapper(deleteHandler, typeRegistry);
 
+        validateAndNormalize(classification);
+
         List<AtlasClassification> classifications = Collections.singletonList(classification);
 
         for (String guid : guids) {
@@ -573,4 +580,22 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore {
 
         return response;
     }
+
+    private void validateAndNormalize(AtlasClassification classification) throws AtlasBaseException
{
+        AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());
+
+        if (type == null) {
+            throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
+        }
+
+        List<String> messages = new ArrayList<>();
+
+        type.validateValue(classification, classification.getTypeName(), messages);
+
+        if (!messages.isEmpty()) {
+            throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
+        }
+
+        type.getNormalizedValue(classification);
+    }
 }


Mime
View raw message