This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 437dc67  ATLAS-3611: updated AtlasEntityDef with addition of read-only 
field namespaceAttributeDefs
437dc67 is described below

commit 437dc67fd973f65e92997a9f6c59796d0485a73c
Author: Madhan Neethiraj <mad...@apache.org>
AuthorDate: Sun Feb 9 09:16:45 2020 -0800

    ATLAS-3611: updated AtlasEntityDef with addition of read-only field 
namespaceAttributeDefs
    
    (cherry picked from commit cc2e6af70586ade872181e51792577934a2141eb)
---
 .../apache/atlas/model/typedef/AtlasEntityDef.java | 56 ++++++++++++++++++++--
 .../org/apache/atlas/type/AtlasEntityType.java     | 44 ++++++++++++++++-
 2 files changed, 95 insertions(+), 5 deletions(-)

diff --git 
a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasEntityDef.java 
b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasEntityDef.java
index 14b3f03..dcae716 100644
--- a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasEntityDef.java
+++ b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasEntityDef.java
@@ -27,6 +27,7 @@ import org.apache.atlas.model.PList;
 import org.apache.atlas.model.SearchFilter.SortType;
 import org.apache.atlas.model.TypeCategory;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -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
     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() {
         this(null, null, null, null, null, null, null);
     }
@@ -122,12 +128,16 @@ public class AtlasEntityDef extends AtlasStructDef 
implements java.io.Serializab
     public AtlasEntityDef(AtlasEntityDef other) {
         super(other);
 
-        setSuperTypes(other != null ? other.getSuperTypes() : null);
+        if (other != null) {
+            setSuperTypes(other.getSuperTypes());
+            setSubTypes(other.getSubTypes());
+            setRelationshipAttributeDefs(other.getRelationshipAttributeDefs());
+            setNamespaceAttributeDefs(other.getNamespaceAttributeDefs());
+        }
     }
 
 
 
-
        public Set<String> getSuperTypes() {
         return superTypes;
     }
@@ -160,6 +170,14 @@ public class AtlasEntityDef extends AtlasStructDef 
implements java.io.Serializab
         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) {
         return hasSuperType(superTypes, typeName);
     }
@@ -207,14 +225,46 @@ public class AtlasEntityDef extends AtlasStructDef 
implements java.io.Serializab
         if (CollectionUtils.isNotEmpty(relationshipAttributeDefs)) {
             int i = 0;
             for (AtlasRelationshipAttributeDef attributeDef : 
relationshipAttributeDefs) {
-                attributeDef.toString(sb);
                 if (i > 0) {
                     sb.append(", ");
                 }
+
+                attributeDef.toString(sb);
+
                 i++;
             }
         }
         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('}');
 
         return sb;
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java 
b/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
index 02d6d58..7594153 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
@@ -90,7 +90,7 @@ public class AtlasEntityType extends AtlasStructType {
     private List<AtlasAttribute>                       
dynEvalTriggerAttributes   = Collections.emptyList();
     private Map<String,List<TemplateToken>>            parsedTemplates         
   = Collections.emptyMap();
     private Set<String>                                tagPropagationEdges     
   = Collections.emptySet();
-    private Map<String, List<AtlasNamespaceAttribute>> namespaceAttributes     
 = Collections.emptyMap();
+    private Map<String, List<AtlasNamespaceAttribute>> namespaceAttributes     
   = Collections.emptyMap();
 
     public AtlasEntityType(AtlasEntityDef entityDef) {
         super(entityDef);
@@ -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);
         }
 
@@ -282,11 +304,29 @@ public class AtlasEntityType extends AtlasStructType {
 
         
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();
 
         populateDynFlagsInfo();
 
-        LOG.info("resolveReferencesPhase3({}): tagPropagationEdges={}", 
getTypeName(), tagPropagationEdges);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("resolveReferencesPhase3({}): tagPropagationEdges={}", 
getTypeName(), tagPropagationEdges);
+        }
     }
 
     public Set<String> getSuperTypes() {

Reply via email to