Commit 1e75da0d by Madhan Neethiraj

ATLAS-2283: add subTypes field in AtlasClassificationDef and AtlasEntityDef

parent 12622e02
...@@ -55,6 +55,10 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se ...@@ -55,6 +55,10 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
private Set<String> superTypes; private Set<String> superTypes;
private Set<String> entityTypes; private Set<String> entityTypes;
// subTypes field below is derived from 'superTypes' specified in all AtlasClassificationDef
// this value is ignored during create & update operations
private Set<String> subTypes;
public AtlasClassificationDef() { public AtlasClassificationDef() {
this(null, null, null, null, null, null); this(null, null, null, null, null, null);
...@@ -119,6 +123,14 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se ...@@ -119,6 +123,14 @@ public class AtlasClassificationDef extends AtlasStructDef implements java.io.Se
} }
} }
public Set<String> getSubTypes() {
return subTypes;
}
public void setSubTypes(Set<String> subTypes) {
this.subTypes = subTypes;
}
public boolean hasSuperType(String typeName) { public boolean hasSuperType(String typeName) {
return hasSuperType(superTypes, typeName); return hasSuperType(superTypes, typeName);
} }
......
...@@ -54,6 +54,10 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab ...@@ -54,6 +54,10 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
private Set<String> superTypes; private Set<String> superTypes;
// subTypes field below is derived from 'superTypes' specified in all AtlasEntityDef
// this value is ignored during create & update operations
private Set<String> subTypes;
public AtlasEntityDef() { public AtlasEntityDef() {
this(null, null, null, null, null, null); this(null, null, null, null, null, null);
...@@ -109,6 +113,14 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab ...@@ -109,6 +113,14 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
} }
} }
public Set<String> getSubTypes() {
return subTypes;
}
public void setSubTypes(Set<String> subTypes) {
this.subTypes = subTypes;
}
public boolean hasSuperType(String typeName) { public boolean hasSuperType(String typeName) {
return hasSuperType(superTypes, typeName); return hasSuperType(superTypes, typeName);
} }
......
...@@ -41,6 +41,7 @@ public class AtlasClassificationType extends AtlasStructType { ...@@ -41,6 +41,7 @@ public class AtlasClassificationType extends AtlasStructType {
private List<AtlasClassificationType> superTypes = Collections.emptyList(); private List<AtlasClassificationType> superTypes = Collections.emptyList();
private Set<String> allSuperTypes = Collections.emptySet(); private Set<String> allSuperTypes = Collections.emptySet();
private Set<String> subTypes = Collections.emptySet();
private Set<String> allSubTypes = Collections.emptySet(); private Set<String> allSubTypes = Collections.emptySet();
private Set<String> typeAndAllSubTypes = Collections.emptySet(); private Set<String> typeAndAllSubTypes = Collections.emptySet();
private String typeAndAllSubTypesQryStr = ""; private String typeAndAllSubTypesQryStr = "";
...@@ -103,6 +104,7 @@ public class AtlasClassificationType extends AtlasStructType { ...@@ -103,6 +104,7 @@ public class AtlasClassificationType extends AtlasStructType {
this.allSuperTypes = Collections.unmodifiableSet(allS); this.allSuperTypes = Collections.unmodifiableSet(allS);
this.allAttributes = Collections.unmodifiableMap(allA); this.allAttributes = Collections.unmodifiableMap(allA);
this.uniqAttributes = getUniqueAttributes(this.allAttributes); this.uniqAttributes = getUniqueAttributes(this.allAttributes);
this.subTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
this.allSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2() this.allSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
this.typeAndAllSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2() this.typeAndAllSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
this.entityTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase3() this.entityTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase3()
...@@ -114,9 +116,13 @@ public class AtlasClassificationType extends AtlasStructType { ...@@ -114,9 +116,13 @@ public class AtlasClassificationType extends AtlasStructType {
void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
super.resolveReferencesPhase2(typeRegistry); super.resolveReferencesPhase2(typeRegistry);
for (AtlasClassificationType superType : superTypes) {
superType.addSubType(this);
}
for (String superTypeName : allSuperTypes) { for (String superTypeName : allSuperTypes) {
AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName); AtlasClassificationType superType = typeRegistry.getClassificationTypeByName(superTypeName);
superType.addSubType(this); superType.addToAllSubTypes(this);
} }
} }
...@@ -139,6 +145,7 @@ public class AtlasClassificationType extends AtlasStructType { ...@@ -139,6 +145,7 @@ public class AtlasClassificationType extends AtlasStructType {
*/ */
@Override @Override
void resolveReferencesPhase3(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { void resolveReferencesPhase3(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
subTypes = Collections.unmodifiableSet(subTypes);
allSubTypes = Collections.unmodifiableSet(allSubTypes); allSubTypes = Collections.unmodifiableSet(allSubTypes);
typeAndAllSubTypes = Collections.unmodifiableSet(typeAndAllSubTypes); typeAndAllSubTypes = Collections.unmodifiableSet(typeAndAllSubTypes);
typeAndAllSubTypesQryStr = ""; // will be computed on next access typeAndAllSubTypesQryStr = ""; // will be computed on next access
...@@ -206,9 +213,15 @@ public class AtlasClassificationType extends AtlasStructType { ...@@ -206,9 +213,15 @@ public class AtlasClassificationType extends AtlasStructType {
} }
} }
} }
classificationDef.setSubTypes(subTypes);
} }
private void addSubType(AtlasClassificationType subType) { private void addSubType(AtlasClassificationType subType) {
subTypes.add(subType.getTypeName());
}
private void addToAllSubTypes(AtlasClassificationType subType) {
allSubTypes.add(subType.getTypeName()); allSubTypes.add(subType.getTypeName());
typeAndAllSubTypes.add(subType.getTypeName()); typeAndAllSubTypes.add(subType.getTypeName());
} }
...@@ -219,6 +232,8 @@ public class AtlasClassificationType extends AtlasStructType { ...@@ -219,6 +232,8 @@ public class AtlasClassificationType extends AtlasStructType {
public Set<String> getAllSuperTypes() { return allSuperTypes; } public Set<String> getAllSuperTypes() { return allSuperTypes; }
public Set<String> getSubTypes() { return subTypes; }
public Set<String> getAllSubTypes() { return allSubTypes; } public Set<String> getAllSubTypes() { return allSubTypes; }
public Set<String> getTypeAndAllSubTypes() { return typeAndAllSubTypes; } public Set<String> getTypeAndAllSubTypes() { return typeAndAllSubTypes; }
......
...@@ -51,6 +51,7 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -51,6 +51,7 @@ public class AtlasEntityType extends AtlasStructType {
private List<AtlasEntityType> superTypes = Collections.emptyList(); private List<AtlasEntityType> superTypes = Collections.emptyList();
private Set<String> allSuperTypes = Collections.emptySet(); private Set<String> allSuperTypes = Collections.emptySet();
private Set<String> subTypes = Collections.emptySet();
private Set<String> allSubTypes = Collections.emptySet(); private Set<String> allSubTypes = Collections.emptySet();
private Set<String> typeAndAllSubTypes = Collections.emptySet(); private Set<String> typeAndAllSubTypes = Collections.emptySet();
private Set<String> typeAndAllSuperTypes = Collections.emptySet(); private Set<String> typeAndAllSuperTypes = Collections.emptySet();
...@@ -58,6 +59,7 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -58,6 +59,7 @@ public class AtlasEntityType extends AtlasStructType {
private Map<String, List<AtlasRelationshipType>> relationshipAttributesType = Collections.emptyMap(); private Map<String, List<AtlasRelationshipType>> relationshipAttributesType = Collections.emptyMap();
private String typeAndAllSubTypesQryStr = ""; private String typeAndAllSubTypesQryStr = "";
public AtlasEntityType(AtlasEntityDef entityDef) { public AtlasEntityType(AtlasEntityDef entityDef) {
super(entityDef); super(entityDef);
...@@ -98,6 +100,7 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -98,6 +100,7 @@ public class AtlasEntityType extends AtlasStructType {
this.allSuperTypes = Collections.unmodifiableSet(allS); this.allSuperTypes = Collections.unmodifiableSet(allS);
this.allAttributes = Collections.unmodifiableMap(allA); this.allAttributes = Collections.unmodifiableMap(allA);
this.uniqAttributes = getUniqueAttributes(this.allAttributes); this.uniqAttributes = getUniqueAttributes(this.allAttributes);
this.subTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
this.allSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2() this.allSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
this.typeAndAllSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2() this.typeAndAllSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
this.relationshipAttributes = new HashMap<>(); // this will be populated in resolveReferencesPhase3() this.relationshipAttributes = new HashMap<>(); // this will be populated in resolveReferencesPhase3()
...@@ -114,9 +117,13 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -114,9 +117,13 @@ public class AtlasEntityType extends AtlasStructType {
void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
super.resolveReferencesPhase2(typeRegistry); super.resolveReferencesPhase2(typeRegistry);
for (AtlasEntityType superType : superTypes) {
superType.addSubType(this);
}
for (String superTypeName : allSuperTypes) { for (String superTypeName : allSuperTypes) {
AtlasEntityType superType = typeRegistry.getEntityTypeByName(superTypeName); AtlasEntityType superType = typeRegistry.getEntityTypeByName(superTypeName);
superType.addSubType(this); superType.addToAllSubTypes(this);
} }
} }
...@@ -150,11 +157,14 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -150,11 +157,14 @@ public class AtlasEntityType extends AtlasStructType {
} }
} }
subTypes = Collections.unmodifiableSet(subTypes);
allSubTypes = Collections.unmodifiableSet(allSubTypes); allSubTypes = Collections.unmodifiableSet(allSubTypes);
typeAndAllSubTypes = Collections.unmodifiableSet(typeAndAllSubTypes); typeAndAllSubTypes = Collections.unmodifiableSet(typeAndAllSubTypes);
typeAndAllSubTypesQryStr = ""; // will be computed on next access typeAndAllSubTypesQryStr = ""; // will be computed on next access
relationshipAttributes = Collections.unmodifiableMap(relationshipAttributes); relationshipAttributes = Collections.unmodifiableMap(relationshipAttributes);
relationshipAttributesType = Collections.unmodifiableMap(relationshipAttributesType); relationshipAttributesType = Collections.unmodifiableMap(relationshipAttributesType);
entityDef.setSubTypes(subTypes);
} }
public Set<String> getSuperTypes() { public Set<String> getSuperTypes() {
...@@ -165,6 +175,8 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -165,6 +175,8 @@ public class AtlasEntityType extends AtlasStructType {
return allSuperTypes; return allSuperTypes;
} }
public Set<String> getSubTypes() { return subTypes; }
public Set<String> getAllSubTypes() { return allSubTypes; } public Set<String> getAllSubTypes() { return allSubTypes; }
public Set<String> getTypeAndAllSubTypes() { return typeAndAllSubTypes; } public Set<String> getTypeAndAllSubTypes() { return typeAndAllSubTypes; }
...@@ -435,6 +447,10 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -435,6 +447,10 @@ public class AtlasEntityType extends AtlasStructType {
} }
private void addSubType(AtlasEntityType subType) { private void addSubType(AtlasEntityType subType) {
subTypes.add(subType.getTypeName());
}
private void addToAllSubTypes(AtlasEntityType subType) {
allSubTypes.add(subType.getTypeName()); allSubTypes.add(subType.getTypeName());
typeAndAllSubTypes.add(subType.getTypeName()); typeAndAllSubTypes.add(subType.getTypeName());
} }
...@@ -679,4 +695,4 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -679,4 +695,4 @@ public class AtlasEntityType extends AtlasStructType {
return ret; return ret;
} }
} }
\ No newline at end of file
...@@ -101,15 +101,15 @@ public class TestAtlasTypeRegistry { ...@@ -101,15 +101,15 @@ public class TestAtlasTypeRegistry {
assertNull(failureMsg); assertNull(failureMsg);
validateSuperTypes(typeRegistry, "L0", new HashSet<String>()); validateAllSuperTypes(typeRegistry, "L0", new HashSet<String>());
validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0"))); validateAllSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0"))); validateAllSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0"))); validateAllSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0"))); validateAllSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2"))); validateAllSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0"))); validateAllSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));
validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4"))); validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2")));
validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3"))); validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4"))); validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
validateSubTypes(typeRegistry, "L2-1", new HashSet<String>()); validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
...@@ -117,6 +117,14 @@ public class TestAtlasTypeRegistry { ...@@ -117,6 +117,14 @@ public class TestAtlasTypeRegistry {
validateSubTypes(typeRegistry, "L2-3", new HashSet<String>()); validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
validateSubTypes(typeRegistry, "L2-4", new HashSet<String>()); validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());
validateAllSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
validateAllSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
validateAllSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
validateAllSubTypes(typeRegistry, "L2-1", new HashSet<String>());
validateAllSubTypes(typeRegistry, "L2-2", new HashSet<String>());
validateAllSubTypes(typeRegistry, "L2-3", new HashSet<String>());
validateAllSubTypes(typeRegistry, "L2-4", new HashSet<String>());
validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1"))); validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1"))); validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1"))); validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
...@@ -273,15 +281,15 @@ public class TestAtlasTypeRegistry { ...@@ -273,15 +281,15 @@ public class TestAtlasTypeRegistry {
} }
assertNull(failureMsg); assertNull(failureMsg);
validateSuperTypes(typeRegistry, "L0", new HashSet<String>()); validateAllSuperTypes(typeRegistry, "L0", new HashSet<String>());
validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0"))); validateAllSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0"))); validateAllSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0"))); validateAllSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0"))); validateAllSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2"))); validateAllSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0"))); validateAllSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));
validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4"))); validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2")));
validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3"))); validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4"))); validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
validateSubTypes(typeRegistry, "L2-1", new HashSet<String>()); validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
...@@ -289,6 +297,14 @@ public class TestAtlasTypeRegistry { ...@@ -289,6 +297,14 @@ public class TestAtlasTypeRegistry {
validateSubTypes(typeRegistry, "L2-3", new HashSet<String>()); validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
validateSubTypes(typeRegistry, "L2-4", new HashSet<String>()); validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());
validateAllSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
validateAllSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
validateAllSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
validateAllSubTypes(typeRegistry, "L2-1", new HashSet<String>());
validateAllSubTypes(typeRegistry, "L2-2", new HashSet<String>());
validateAllSubTypes(typeRegistry, "L2-3", new HashSet<String>());
validateAllSubTypes(typeRegistry, "L2-4", new HashSet<String>());
validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1"))); validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1"))); validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1"))); validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
...@@ -519,11 +535,11 @@ public class TestAtlasTypeRegistry { ...@@ -519,11 +535,11 @@ public class TestAtlasTypeRegistry {
} }
assertNull(failureMsg); assertNull(failureMsg);
validateSuperTypes(typeRegistry, "L0", new HashSet<String>()); validateAllSuperTypes(typeRegistry, "L0", new HashSet<String>());
validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1"))); validateAllSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1")));
validateSuperTypes(typeRegistry, "L1", new HashSet<>(Arrays.asList("L0"))); validateAllSuperTypes(typeRegistry, "L1", new HashSet<>(Arrays.asList("L0")));
validateSubTypes(typeRegistry, "L1", new HashSet<String>()); validateAllSubTypes(typeRegistry, "L1", new HashSet<String>());
// create a circular reference // create a circular reference
...@@ -552,11 +568,11 @@ public class TestAtlasTypeRegistry { ...@@ -552,11 +568,11 @@ public class TestAtlasTypeRegistry {
assertNull(typeRegistry.getEntityTypeByName("L2")); assertNull(typeRegistry.getEntityTypeByName("L2"));
validateSuperTypes(typeRegistry, "L0", new HashSet<String>()); validateAllSuperTypes(typeRegistry, "L0", new HashSet<String>());
validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1"))); validateAllSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1")));
validateSuperTypes(typeRegistry, "L1", new HashSet<>(Arrays.asList("L0"))); validateAllSuperTypes(typeRegistry, "L1", new HashSet<>(Arrays.asList("L0")));
validateSubTypes(typeRegistry, "L1", new HashSet<String>()); validateAllSubTypes(typeRegistry, "L1", new HashSet<String>());
} }
private boolean addType(AtlasTypeRegistry typeRegistry, AtlasBaseTypeDef typeDef) { private boolean addType(AtlasTypeRegistry typeRegistry, AtlasBaseTypeDef typeDef) {
...@@ -578,7 +594,7 @@ public class TestAtlasTypeRegistry { ...@@ -578,7 +594,7 @@ public class TestAtlasTypeRegistry {
return ret; return ret;
} }
private void validateSuperTypes(AtlasTypeRegistry typeRegistry, String typeName, Set<String> expectedSuperTypes) { private void validateAllSuperTypes(AtlasTypeRegistry typeRegistry, String typeName, Set<String> expectedSuperTypes) {
AtlasType type = null; AtlasType type = null;
try { try {
...@@ -599,7 +615,7 @@ public class TestAtlasTypeRegistry { ...@@ -599,7 +615,7 @@ public class TestAtlasTypeRegistry {
assertEquals(superTypes, expectedSuperTypes); assertEquals(superTypes, expectedSuperTypes);
} }
private void validateSubTypes(AtlasTypeRegistry typeRegistry, String typeName, Set<String> expectedSubTypes) { private void validateAllSubTypes(AtlasTypeRegistry typeRegistry, String typeName, Set<String> expectedSubTypes) {
AtlasType type = null; AtlasType type = null;
try { try {
...@@ -620,6 +636,27 @@ public class TestAtlasTypeRegistry { ...@@ -620,6 +636,27 @@ public class TestAtlasTypeRegistry {
assertEquals(subTypes, expectedSubTypes); assertEquals(subTypes, expectedSubTypes);
} }
private void validateSubTypes(AtlasTypeRegistry typeRegistry, String typeName, Set<String> expectedSubTypes) {
AtlasType type = null;
try {
type = typeRegistry.getType(typeName);
} catch (AtlasBaseException excp) {
}
Set<String> subTypes = null;
if (type != null) {
if (type instanceof AtlasEntityType) {
subTypes = ((AtlasEntityType) type).getSubTypes();
} else if (type instanceof AtlasClassificationType) {
subTypes = ((AtlasClassificationType) type).getSubTypes();
}
}
assertEquals(subTypes, expectedSubTypes);
}
private void validateAttributeNames(AtlasTypeRegistry typeRegistry, String typeName, Set<String> attributeNames) { private void validateAttributeNames(AtlasTypeRegistry typeRegistry, String typeName, Set<String> attributeNames) {
AtlasType type = null; AtlasType type = null;
......
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