Commit 4d9cf456 by Suma Shivaprasad

ATLAS-1229 Add TypeCategory and methods to access attribute definitiions in AtlasTypes (sumasai)

parent d185522b
...@@ -48,7 +48,7 @@ public class AtlasArrayType extends AtlasType { ...@@ -48,7 +48,7 @@ public class AtlasArrayType extends AtlasType {
} }
public AtlasArrayType(AtlasType elementType, int minCount, int maxCount) { public AtlasArrayType(AtlasType elementType, int minCount, int maxCount) {
super(AtlasBaseTypeDef.getArrayTypeName(elementType.getTypeName())); super(AtlasBaseTypeDef.getArrayTypeName(elementType.getTypeName()), TypeCategory.ARRAY);
this.elementTypeName = elementType.getTypeName(); this.elementTypeName = elementType.getTypeName();
this.minCount = minCount; this.minCount = minCount;
...@@ -61,7 +61,7 @@ public class AtlasArrayType extends AtlasType { ...@@ -61,7 +61,7 @@ public class AtlasArrayType extends AtlasType {
} }
public AtlasArrayType(String elementTypeName, int minCount, int maxCount) { public AtlasArrayType(String elementTypeName, int minCount, int maxCount) {
super(AtlasBaseTypeDef.getArrayTypeName(elementTypeName)); super(AtlasBaseTypeDef.getArrayTypeName(elementTypeName), TypeCategory.ARRAY);
this.elementTypeName = elementTypeName; this.elementTypeName = elementTypeName;
this.minCount = minCount; this.minCount = minCount;
...@@ -75,7 +75,7 @@ public class AtlasArrayType extends AtlasType { ...@@ -75,7 +75,7 @@ public class AtlasArrayType extends AtlasType {
public AtlasArrayType(String elementTypeName, int minCount, int maxCount, AtlasTypeRegistry typeRegistry) public AtlasArrayType(String elementTypeName, int minCount, int maxCount, AtlasTypeRegistry typeRegistry)
throws AtlasBaseException { throws AtlasBaseException {
super(AtlasBaseTypeDef.getArrayTypeName(elementTypeName)); super(AtlasBaseTypeDef.getArrayTypeName(elementTypeName), TypeCategory.ARRAY);
this.elementTypeName = elementTypeName; this.elementTypeName = elementTypeName;
this.minCount = minCount; this.minCount = minCount;
......
...@@ -41,7 +41,7 @@ public class AtlasBuiltInTypes { ...@@ -41,7 +41,7 @@ public class AtlasBuiltInTypes {
private static final Boolean DEFAULT_VALUE = Boolean.FALSE; private static final Boolean DEFAULT_VALUE = Boolean.FALSE;
public AtlasBooleanType() { public AtlasBooleanType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN); super(AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -75,7 +75,7 @@ public class AtlasBuiltInTypes { ...@@ -75,7 +75,7 @@ public class AtlasBuiltInTypes {
private static final Byte DEFAULT_VALUE = new Byte((byte)0); private static final Byte DEFAULT_VALUE = new Byte((byte)0);
public AtlasByteType() { public AtlasByteType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_BYTE); super(AtlasBaseTypeDef.ATLAS_TYPE_BYTE, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -119,7 +119,7 @@ public class AtlasBuiltInTypes { ...@@ -119,7 +119,7 @@ public class AtlasBuiltInTypes {
private static final Short DEFAULT_VALUE = new Short((short)0); private static final Short DEFAULT_VALUE = new Short((short)0);
public AtlasShortType() { public AtlasShortType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_SHORT); super(AtlasBaseTypeDef.ATLAS_TYPE_SHORT, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -163,7 +163,7 @@ public class AtlasBuiltInTypes { ...@@ -163,7 +163,7 @@ public class AtlasBuiltInTypes {
private static final Integer DEFAULT_VALUE = new Integer(0); private static final Integer DEFAULT_VALUE = new Integer(0);
public AtlasIntType() { public AtlasIntType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_INT); super(AtlasBaseTypeDef.ATLAS_TYPE_INT, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -207,7 +207,7 @@ public class AtlasBuiltInTypes { ...@@ -207,7 +207,7 @@ public class AtlasBuiltInTypes {
private static final Long DEFAULT_VALUE = new Long(0); private static final Long DEFAULT_VALUE = new Long(0);
public AtlasLongType() { public AtlasLongType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_LONG); super(AtlasBaseTypeDef.ATLAS_TYPE_LONG, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -251,7 +251,7 @@ public class AtlasBuiltInTypes { ...@@ -251,7 +251,7 @@ public class AtlasBuiltInTypes {
private static final Float DEFAULT_VALUE = new Float(0); private static final Float DEFAULT_VALUE = new Float(0);
public AtlasFloatType() { public AtlasFloatType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_FLOAT); super(AtlasBaseTypeDef.ATLAS_TYPE_FLOAT, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -295,7 +295,7 @@ public class AtlasBuiltInTypes { ...@@ -295,7 +295,7 @@ public class AtlasBuiltInTypes {
private static final Double DEFAULT_VALUE = new Double(0); private static final Double DEFAULT_VALUE = new Double(0);
public AtlasDoubleType() { public AtlasDoubleType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE); super(AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -341,7 +341,7 @@ public class AtlasBuiltInTypes { ...@@ -341,7 +341,7 @@ public class AtlasBuiltInTypes {
private static final BigInteger DEFAULT_VALUE = BigInteger.ZERO; private static final BigInteger DEFAULT_VALUE = BigInteger.ZERO;
public AtlasBigIntegerType() { public AtlasBigIntegerType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER); super(AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -385,7 +385,7 @@ public class AtlasBuiltInTypes { ...@@ -385,7 +385,7 @@ public class AtlasBuiltInTypes {
private static final BigDecimal DEFAULT_VALUE = BigDecimal.ZERO; private static final BigDecimal DEFAULT_VALUE = BigDecimal.ZERO;
public AtlasBigDecimalType() { public AtlasBigDecimalType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL); super(AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -429,7 +429,7 @@ public class AtlasBuiltInTypes { ...@@ -429,7 +429,7 @@ public class AtlasBuiltInTypes {
private static final Date DEFAULT_VALUE = new Date(0); private static final Date DEFAULT_VALUE = new Date(0);
public AtlasDateType() { public AtlasDateType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_DATE); super(AtlasBaseTypeDef.ATLAS_TYPE_DATE, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -478,7 +478,7 @@ public class AtlasBuiltInTypes { ...@@ -478,7 +478,7 @@ public class AtlasBuiltInTypes {
private static final String DEFAULT_VALUE = ""; private static final String DEFAULT_VALUE = "";
public AtlasStringType() { public AtlasStringType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_STRING); super(AtlasBaseTypeDef.ATLAS_TYPE_STRING, TypeCategory.PRIMITIVE);
} }
@Override @Override
...@@ -506,7 +506,7 @@ public class AtlasBuiltInTypes { ...@@ -506,7 +506,7 @@ public class AtlasBuiltInTypes {
*/ */
public static class AtlasObjectIdType extends AtlasType { public static class AtlasObjectIdType extends AtlasType {
public AtlasObjectIdType() { public AtlasObjectIdType() {
super(AtlasBaseTypeDef.ATLAS_TYPE_OBJECT_ID); super(AtlasBaseTypeDef.ATLAS_TYPE_OBJECT_ID, TypeCategory.OBJECT_ID_TYPE);
} }
@Override @Override
......
...@@ -46,7 +46,7 @@ public class AtlasClassificationType extends AtlasStructType { ...@@ -46,7 +46,7 @@ public class AtlasClassificationType extends AtlasStructType {
private Set<String> allSuperTypes = Collections.emptySet(); private Set<String> allSuperTypes = Collections.emptySet();
public AtlasClassificationType(AtlasClassificationDef classificationDef) { public AtlasClassificationType(AtlasClassificationDef classificationDef) {
super(classificationDef); super(classificationDef, TypeCategory.CLASSIFICATION);
this.classificationDef = classificationDef; this.classificationDef = classificationDef;
} }
......
...@@ -45,7 +45,7 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -45,7 +45,7 @@ public class AtlasEntityType extends AtlasStructType {
private Set<String> allSuperTypes = Collections.emptySet(); private Set<String> allSuperTypes = Collections.emptySet();
public AtlasEntityType(AtlasEntityDef entityDef) { public AtlasEntityType(AtlasEntityDef entityDef) {
super(entityDef); super(entityDef, TypeCategory.ENTITY);
this.entityDef = entityDef; this.entityDef = entityDef;
} }
......
...@@ -36,7 +36,7 @@ public class AtlasEnumType extends AtlasType { ...@@ -36,7 +36,7 @@ public class AtlasEnumType extends AtlasType {
private final String defaultValue; private final String defaultValue;
public AtlasEnumType(AtlasEnumDef enumDef) { public AtlasEnumType(AtlasEnumDef enumDef) {
super(enumDef.getName()); super(enumDef.getName(), TypeCategory.PRIMITIVE);
Map<String, AtlasEnumElementDef> e = new HashMap<String, AtlasEnumElementDef>(); Map<String, AtlasEnumElementDef> e = new HashMap<String, AtlasEnumElementDef>();
......
...@@ -39,14 +39,14 @@ public class AtlasMapType extends AtlasType { ...@@ -39,14 +39,14 @@ public class AtlasMapType extends AtlasType {
private AtlasType valueType; private AtlasType valueType;
public AtlasMapType(String keyTypeName, String valueTypeName) { public AtlasMapType(String keyTypeName, String valueTypeName) {
super(AtlasBaseTypeDef.getMapTypeName(keyTypeName, valueTypeName)); super(AtlasBaseTypeDef.getMapTypeName(keyTypeName, valueTypeName), TypeCategory.MAP);
this.keyTypeName = keyTypeName; this.keyTypeName = keyTypeName;
this.valueTypeName = valueTypeName; this.valueTypeName = valueTypeName;
} }
public AtlasMapType(AtlasType keyType, AtlasType valueType) { public AtlasMapType(AtlasType keyType, AtlasType valueType) {
super(AtlasBaseTypeDef.getMapTypeName(keyType.getTypeName(), valueType.getTypeName())); super(AtlasBaseTypeDef.getMapTypeName(keyType.getTypeName(), valueType.getTypeName()), TypeCategory.MAP);
this.keyTypeName = keyType.getTypeName(); this.keyTypeName = keyType.getTypeName();
this.valueTypeName = valueType.getTypeName(); this.valueTypeName = valueType.getTypeName();
...@@ -56,7 +56,7 @@ public class AtlasMapType extends AtlasType { ...@@ -56,7 +56,7 @@ public class AtlasMapType extends AtlasType {
public AtlasMapType(String keyTypeName, String valueTypeName, AtlasTypeRegistry typeRegistry) public AtlasMapType(String keyTypeName, String valueTypeName, AtlasTypeRegistry typeRegistry)
throws AtlasBaseException { throws AtlasBaseException {
super(AtlasBaseTypeDef.getMapTypeName(keyTypeName, valueTypeName)); super(AtlasBaseTypeDef.getMapTypeName(keyTypeName, valueTypeName), TypeCategory.MAP);
this.keyTypeName = keyTypeName; this.keyTypeName = keyTypeName;
this.valueTypeName = valueTypeName; this.valueTypeName = valueTypeName;
......
...@@ -48,13 +48,19 @@ public class AtlasStructType extends AtlasType { ...@@ -48,13 +48,19 @@ public class AtlasStructType extends AtlasType {
public AtlasStructType(AtlasStructDef structDef) { public AtlasStructType(AtlasStructDef structDef) {
super(structDef.getName()); super(structDef.getName(), TypeCategory.STRUCT);
this.structDef = structDef;
}
public AtlasStructType(AtlasStructDef structDef, TypeCategory category) {
super(structDef.getName(), category);
this.structDef = structDef; this.structDef = structDef;
} }
public AtlasStructType(AtlasStructDef structDef, AtlasTypeRegistry typeRegistry) throws AtlasBaseException { public AtlasStructType(AtlasStructDef structDef, AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
super(structDef.getName()); super(structDef.getName(), TypeCategory.STRUCT);
this.structDef = structDef; this.structDef = structDef;
...@@ -432,4 +438,8 @@ public class AtlasStructType extends AtlasType { ...@@ -432,4 +438,8 @@ public class AtlasStructType extends AtlasType {
this.attributeName = attributeName; this.attributeName = attributeName;
} }
} }
public AtlasStructDef getStructDefinition() {
return structDef;
}
} }
...@@ -31,13 +31,20 @@ import java.util.List; ...@@ -31,13 +31,20 @@ import java.util.List;
*/ */
public abstract class AtlasType { public abstract class AtlasType {
public enum TypeCategory {
PRIMITIVE, ARRAY, MAP, ENTITY, STRUCT, CLASSIFICATION, OBJECT_ID_TYPE
}
private static final Gson GSON = private static final Gson GSON =
new GsonBuilder().setDateFormat(AtlasBaseTypeDef.SERIALIZED_DATE_FORMAT_STR).create(); new GsonBuilder().setDateFormat(AtlasBaseTypeDef.SERIALIZED_DATE_FORMAT_STR).create();
private final String typeName; private final String typeName;
public AtlasType(String typeName) { private final TypeCategory typeCategory;
protected AtlasType(String typeName, TypeCategory category) {
this.typeName = typeName; this.typeName = typeName;
this.typeCategory = category;
} }
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
...@@ -51,6 +58,10 @@ public abstract class AtlasType { ...@@ -51,6 +58,10 @@ public abstract class AtlasType {
public abstract Object getNormalizedValue(Object obj); public abstract Object getNormalizedValue(Object obj);
public TypeCategory getTypeCategory() {
return typeCategory;
}
public boolean validateValue(Object obj, String objName, List<String> messages) { public boolean validateValue(Object obj, String objName, List<String> messages) {
boolean ret = isValidValue(obj); boolean ret = isValidValue(obj);
......
...@@ -9,7 +9,8 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,7 +9,8 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1227 Added support for attribute constraints in the API ATLAS-1229 Add TypeCategory and methods to access attribute definitiions in AtlasTypes (sumasai)
ATLAS-1227 Added support for attribute constraints in the API (mneethiraj)
ATLAS-1225 Optimize AtlasTypeDefGraphStore to use typeRegistry (mneethiraj via sumasai) ATLAS-1225 Optimize AtlasTypeDefGraphStore to use typeRegistry (mneethiraj via sumasai)
ATLAS-1221 build failure in windows SyntaxError: invalid syntax (zhangqiang2 via shwethags) ATLAS-1221 build failure in windows SyntaxError: invalid syntax (zhangqiang2 via shwethags)
ATLAS-1226 Servlet init-params in web.xml are unused (mneethiraj via shwethags) ATLAS-1226 Servlet init-params in web.xml are unused (mneethiraj via shwethags)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment