Commit cc2e6af7 by Madhan Neethiraj

ATLAS-3611: updated AtlasEntityDef with addition of read-only field namespaceAttributeDefs

parent 4229cb3c
...@@ -27,6 +27,7 @@ import org.apache.atlas.model.PList; ...@@ -27,6 +27,7 @@ import org.apache.atlas.model.PList;
import org.apache.atlas.model.SearchFilter.SortType; import org.apache.atlas.model.SearchFilter.SortType;
import org.apache.atlas.model.TypeCategory; import org.apache.atlas.model.TypeCategory;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
...@@ -64,6 +65,11 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab ...@@ -64,6 +65,11 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
// the value of this field is derived from all the relationshipDefs this entityType is referenced in // the value of this field is derived from all the relationshipDefs this entityType is referenced in
private List<AtlasRelationshipAttributeDef> relationshipAttributeDefs; private List<AtlasRelationshipAttributeDef> relationshipAttributeDefs;
// this is a read-only field, any value provided during create & update operation is ignored
// the value of this field is derived from all the namespaceDefs this entityType is referenced in
private Map<String, List<AtlasAttributeDef>> namespaceAttributeDefs;
public AtlasEntityDef() { public AtlasEntityDef() {
this(null, null, null, null, null, null, null); this(null, null, null, null, null, null, null);
} }
...@@ -122,9 +128,13 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab ...@@ -122,9 +128,13 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
public AtlasEntityDef(AtlasEntityDef other) { public AtlasEntityDef(AtlasEntityDef other) {
super(other); super(other);
setSuperTypes(other != null ? other.getSuperTypes() : null); if (other != null) {
setSuperTypes(other.getSuperTypes());
setSubTypes(other.getSubTypes());
setRelationshipAttributeDefs(other.getRelationshipAttributeDefs());
setNamespaceAttributeDefs(other.getNamespaceAttributeDefs());
}
} }
...@@ -160,6 +170,14 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab ...@@ -160,6 +170,14 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
this.relationshipAttributeDefs = relationshipAttributeDefs; this.relationshipAttributeDefs = relationshipAttributeDefs;
} }
public Map<String, List<AtlasAttributeDef>> getNamespaceAttributeDefs() {
return namespaceAttributeDefs;
}
public void setNamespaceAttributeDefs(Map<String, List<AtlasAttributeDef>> namespaceAttributeDefs) {
this.namespaceAttributeDefs = namespaceAttributeDefs;
}
public boolean hasSuperType(String typeName) { public boolean hasSuperType(String typeName) {
return hasSuperType(superTypes, typeName); return hasSuperType(superTypes, typeName);
} }
...@@ -207,14 +225,46 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab ...@@ -207,14 +225,46 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
if (CollectionUtils.isNotEmpty(relationshipAttributeDefs)) { if (CollectionUtils.isNotEmpty(relationshipAttributeDefs)) {
int i = 0; int i = 0;
for (AtlasRelationshipAttributeDef attributeDef : relationshipAttributeDefs) { for (AtlasRelationshipAttributeDef attributeDef : relationshipAttributeDefs) {
attributeDef.toString(sb);
if (i > 0) { if (i > 0) {
sb.append(", "); sb.append(", ");
} }
attributeDef.toString(sb);
i++; i++;
} }
} }
sb.append(']'); sb.append(']');
sb.append(", namespaceAttributeDefs={");
if (MapUtils.isNotEmpty(namespaceAttributeDefs)) {
int nsIdx = 0;
for (Map.Entry<String, List<AtlasAttributeDef>> entry : namespaceAttributeDefs.entrySet()) {
String nsName = entry.getKey();
List<AtlasAttributeDef> nsAttrs = entry.getValue();
if (nsIdx > 0) {
sb.append(", ");
}
sb.append(nsName).append("=[");
int attrIdx = 0;
for (AtlasAttributeDef attributeDef : nsAttrs) {
if (attrIdx > 0) {
sb.append(", ");
}
attributeDef.toString(sb);
attrIdx++;
}
sb.append(']');
nsIdx++;
}
}
sb.append('}');
sb.append('}'); sb.append('}');
return sb; return sb;
......
...@@ -237,6 +237,28 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -237,6 +237,28 @@ public class AtlasEntityType extends AtlasStructType {
} }
} }
Map<String, List<AtlasNamespaceAttribute>> superTypeNamespaces = superType.getNamespaceAttributes();
if (MapUtils.isNotEmpty(superTypeNamespaces)) {
for (Map.Entry<String, List<AtlasNamespaceAttribute>> entry : superTypeNamespaces.entrySet()) {
String nsName = entry.getKey();
List<AtlasNamespaceAttribute> superTypeNsAttrs = entry.getValue();
List<AtlasNamespaceAttribute> nsAttrs = namespaceAttributes.get(nsName);
if (nsAttrs == null) {
nsAttrs = new ArrayList<>();
namespaceAttributes.put(nsName, nsAttrs);
}
for (AtlasNamespaceAttribute superTypeNsAttr : superTypeNsAttrs) {
if (!nsAttrs.contains(superTypeNsAttr)) {
nsAttrs.add(superTypeNsAttr);
}
}
}
}
tagPropagationEdges.addAll(superType.tagPropagationEdges); tagPropagationEdges.addAll(superType.tagPropagationEdges);
} }
...@@ -282,11 +304,29 @@ public class AtlasEntityType extends AtlasStructType { ...@@ -282,11 +304,29 @@ public class AtlasEntityType extends AtlasStructType {
entityDef.setRelationshipAttributeDefs(Collections.unmodifiableList(relationshipAttrDefs)); entityDef.setRelationshipAttributeDefs(Collections.unmodifiableList(relationshipAttrDefs));
Map<String, List<AtlasAttributeDef>> namespaceAttributeDefs = new HashMap<>();
for (Map.Entry<String, List<AtlasNamespaceAttribute>> entry : namespaceAttributes.entrySet()) {
String nsName = entry.getKey();
List<AtlasNamespaceAttribute> nsAttrs = entry.getValue();
List<AtlasAttributeDef> nsAttrDefs = new ArrayList<>();
for (AtlasNamespaceAttribute nsAttr : nsAttrs) {
nsAttrDefs.add(nsAttr.getAttributeDef());
}
namespaceAttributeDefs.put(nsName, nsAttrDefs);
}
entityDef.setNamespaceAttributeDefs(namespaceAttributeDefs);
this.parsedTemplates = parseDynAttributeTemplates(); this.parsedTemplates = parseDynAttributeTemplates();
populateDynFlagsInfo(); populateDynFlagsInfo();
LOG.info("resolveReferencesPhase3({}): tagPropagationEdges={}", getTypeName(), tagPropagationEdges); if (LOG.isDebugEnabled()) {
LOG.debug("resolveReferencesPhase3({}): tagPropagationEdges={}", getTypeName(), tagPropagationEdges);
}
} }
public Set<String> getSuperTypes() { public Set<String> getSuperTypes() {
......
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