You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by am...@apache.org on 2018/10/16 17:36:47 UTC
atlas git commit: ATLAS-2922: Multiplicity computation updated for
SET/optional
Repository: atlas
Updated Branches:
refs/heads/master c6aaef08e -> 2fbea9f2b
ATLAS-2922: Multiplicity computation updated for SET/optional
Project: http://git-wip-us.apache.org/repos/asf/atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/2fbea9f2
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/2fbea9f2
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/2fbea9f2
Branch: refs/heads/master
Commit: 2fbea9f2b52283a82a2769e8e389db4729317e78
Parents: c6aaef0
Author: Ashutosh Mestry <am...@hortonworks.com>
Authored: Tue Oct 16 09:24:26 2018 -0700
Committer: Ashutosh Mestry <am...@hortonworks.com>
Committed: Tue Oct 16 10:12:36 2018 -0700
----------------------------------------------------------------------
.../atlas/model/typedef/AtlasStructDef.java | 1 +
.../org/apache/atlas/type/AtlasTypeUtil.java | 19 +++----
.../atlas/v1/model/typedef/Multiplicity.java | 18 ++++---
.../org/apache/atlas/type/TestMultiplicity.java | 54 ++++++++++++++++++++
.../store/graph/v2/AtlasStructDefStoreV2.java | 25 +--------
5 files changed, 76 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/atlas/blob/2fbea9f2/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
index 013c753..921cf3f 100644
--- a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
+++ b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
@@ -441,6 +441,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
}
+ @JsonIgnore
public boolean isSoftReferenced() {
return this.options != null &&
getOptions().containsKey(AtlasAttributeDef.ATTRDEF_OPTION_SOFT_REFERENCE) &&
http://git-wip-us.apache.org/repos/asf/atlas/blob/2fbea9f2/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java b/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
index 78df622..ff0c1fc 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasTypeUtil.java
@@ -482,11 +482,15 @@ public class AtlasTypeUtil {
ret.setDefaultValue(attributeDef.getDefaultValue());
ret.setDescription(attributeDef.getDescription());
ret.setOptions(attributeDef.getOptions());
+ ret.setMultiplicity(getMultiplicity(attributeDef));
- final int lower;
- final int upper;
+ return ret;
+ }
- if (attributeDef.getCardinality() == AtlasAttributeDef.Cardinality.SINGLE) {
+ public static Multiplicity getMultiplicity(AtlasAttributeDef attributeDef) {
+ int lower;
+ int upper;
+ if (attributeDef.getCardinality() == Cardinality.SINGLE) {
lower = attributeDef.getIsOptional() ? 0 : 1;
upper = 1;
} else {
@@ -499,14 +503,7 @@ public class AtlasTypeUtil {
upper = attributeDef.getValuesMaxCount() < 2 ? Integer.MAX_VALUE : attributeDef.getValuesMaxCount();
}
- Multiplicity multiplicity = new Multiplicity();
- multiplicity.setLower(lower);
- multiplicity.setUpper(upper);
- multiplicity.setIsUnique(AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality()));
-
- ret.setMultiplicity(multiplicity);
-
- return ret;
+ return new Multiplicity(lower, upper, Cardinality.SET.equals(attributeDef.getCardinality()));
}
public static Map<String, Object> toMap(AtlasEntity entity) {
http://git-wip-us.apache.org/repos/asf/atlas/blob/2fbea9f2/intg/src/main/java/org/apache/atlas/v1/model/typedef/Multiplicity.java
----------------------------------------------------------------------
diff --git a/intg/src/main/java/org/apache/atlas/v1/model/typedef/Multiplicity.java b/intg/src/main/java/org/apache/atlas/v1/model/typedef/Multiplicity.java
index 6da4ce5..45a8e15 100644
--- a/intg/src/main/java/org/apache/atlas/v1/model/typedef/Multiplicity.java
+++ b/intg/src/main/java/org/apache/atlas/v1/model/typedef/Multiplicity.java
@@ -125,15 +125,21 @@ public class Multiplicity implements Serializable {
@Override
public void serialize(Multiplicity value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
if (value != null) {
- if (value.equals(Multiplicity.REQUIRED)) {
- jgen.writeString("required");
- } else if (value.equals(Multiplicity.OPTIONAL)) {
- jgen.writeString("optional");
+ final String serializedValue;
+
+ if (value.getLower() < 1) {
+ serializedValue = "optional";
} else if (value.equals(Multiplicity.COLLECTION)) {
- jgen.writeString("collection");
+ serializedValue = "collection";
} else if (value.equals(Multiplicity.SET)) {
- jgen.writeString("set");
+ serializedValue = "set";
+ } else if (value.equals(Multiplicity.REQUIRED)) {
+ serializedValue = "required";
+ } else { // default value
+ serializedValue = "required";
}
+
+ jgen.writeString(serializedValue);
}
}
}
http://git-wip-us.apache.org/repos/asf/atlas/blob/2fbea9f2/intg/src/test/java/org/apache/atlas/type/TestMultiplicity.java
----------------------------------------------------------------------
diff --git a/intg/src/test/java/org/apache/atlas/type/TestMultiplicity.java b/intg/src/test/java/org/apache/atlas/type/TestMultiplicity.java
new file mode 100644
index 0000000..d403af3
--- /dev/null
+++ b/intg/src/test/java/org/apache/atlas/type/TestMultiplicity.java
@@ -0,0 +1,54 @@
+/**
+ * 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.type;
+
+import org.apache.atlas.model.typedef.AtlasStructDef;
+import org.apache.atlas.v1.model.typedef.AttributeDefinition;
+import org.apache.atlas.v1.model.typedef.Multiplicity;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+public class TestMultiplicity {
+ @Test
+ public void verify() {
+
+ assertMultiplicity(AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE, false, 1, 1);
+ assertMultiplicity(AtlasStructDef.AtlasAttributeDef.Cardinality.LIST, false, 1, Integer.MAX_VALUE);
+ assertMultiplicity(AtlasStructDef.AtlasAttributeDef.Cardinality.SET, true, 0, Integer.MAX_VALUE);
+ }
+
+ private void assertMultiplicity(AtlasStructDef.AtlasAttributeDef.Cardinality cardinality,
+ boolean optionality, int expectedLower, int expectedUpper) {
+ AtlasStructDef.AtlasAttributeDef attributeDef = new AtlasStructDef.AtlasAttributeDef();
+ attributeDef.setCardinality(cardinality);
+ attributeDef.setIsOptional(optionality);
+
+
+ Multiplicity multiplicity = AtlasTypeUtil.getMultiplicity(attributeDef);
+ assertNotNull(multiplicity);
+ assertEquals(multiplicity.getLower(), expectedLower);
+ assertEquals(multiplicity.getUpper(), expectedUpper);
+
+ AttributeDefinition attributeDefinition = new AttributeDefinition();
+ attributeDefinition.setMultiplicity(multiplicity);
+ assertNotNull(AtlasType.toJson(attributeDefinition));
+ }
+}
http://git-wip-us.apache.org/repos/asf/atlas/blob/2fbea9f2/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java
----------------------------------------------------------------------
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java
index 3c21465..f043e0d 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java
@@ -585,29 +585,6 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
return ret;
}
- public static Multiplicity getMultiplicity(AtlasAttributeDef attributeDef) {
- final int lower;
- final int upper;
- final boolean isUnique = AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality());
-
- if (attributeDef.getCardinality() == AtlasAttributeDef.Cardinality.SINGLE) {
- lower = attributeDef.getIsOptional() ? 0 : 1;
- upper = 1;
- } else {
- if(attributeDef.getIsOptional()) {
- lower = 0;
- } else {
- lower = attributeDef.getValuesMinCount() < 1 ? 1 : attributeDef.getValuesMinCount();
- }
-
- upper = attributeDef.getValuesMaxCount() < 2 ? Integer.MAX_VALUE : attributeDef.getValuesMaxCount();
- }
-
- Multiplicity ret = new Multiplicity(lower, upper, isUnique);
-
- return ret;
- }
-
public static AttributeDefinition toAttributeDefinition(AtlasAttribute attribute) {
final AtlasAttributeDef attrDef = attribute.getAttributeDef();
@@ -615,7 +592,7 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
ret.setName(attrDef.getName());
ret.setDataTypeName(attrDef.getTypeName());
- ret.setMultiplicity(getMultiplicity(attrDef));
+ ret.setMultiplicity(AtlasTypeUtil.getMultiplicity(attrDef));
ret.setIsComposite(attribute.isOwnedRef());
ret.setIsUnique(attrDef.getIsUnique());
ret.setIsIndexable(attrDef.getIsIndexable());