You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2019/03/31 20:57:49 UTC
[atlas] branch master updated: ATLAS-3107: updated AtlasEntityDef
with addition of read-only field relationshipAttributeDefs
This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new 07192bc ATLAS-3107: updated AtlasEntityDef with addition of read-only field relationshipAttributeDefs
07192bc is described below
commit 07192bc82c213896dec29d219056633ef56c13f8
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Thu Mar 28 07:53:34 2019 -0700
ATLAS-3107: updated AtlasEntityDef with addition of read-only field relationshipAttributeDefs
---
.../apache/atlas/model/typedef/AtlasEntityDef.java | 105 ++++++++++++++++++++-
.../org/apache/atlas/type/AtlasEntityType.java | 16 ++++
.../apache/atlas/type/AtlasRelationshipType.java | 2 +
.../org/apache/atlas/type/AtlasStructType.java | 5 +
4 files changed, 126 insertions(+), 2 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 29dbf09..14b3f03 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
@@ -32,6 +32,7 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
+import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -55,10 +56,13 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
private Set<String> superTypes;
- // subTypes field below is derived from 'superTypes' specified in all AtlasEntityDef
- // this value is ignored during create & update operations
+ // this is a read-only field, any value provided during create & update operation is ignored
+ // the value of this field is derived from 'superTypes' specified in all AtlasEntityDef
private Set<String> subTypes;
+ // 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 relationshipDefs this entityType is referenced in
+ private List<AtlasRelationshipAttributeDef> relationshipAttributeDefs;
public AtlasEntityDef() {
this(null, null, null, null, null, null, null);
@@ -148,6 +152,14 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
this.subTypes = subTypes;
}
+ public List<AtlasRelationshipAttributeDef> getRelationshipAttributeDefs() {
+ return relationshipAttributeDefs;
+ }
+
+ public void setRelationshipAttributeDefs(List<AtlasRelationshipAttributeDef> relationshipAttributeDefs) {
+ this.relationshipAttributeDefs = relationshipAttributeDefs;
+ }
+
public boolean hasSuperType(String typeName) {
return hasSuperType(superTypes, typeName);
}
@@ -191,6 +203,18 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
sb.append(", superTypes=[");
dumpObjects(superTypes, sb);
sb.append("]");
+ sb.append(", relationshipAttributeDefs=[");
+ if (CollectionUtils.isNotEmpty(relationshipAttributeDefs)) {
+ int i = 0;
+ for (AtlasRelationshipAttributeDef attributeDef : relationshipAttributeDefs) {
+ attributeDef.toString(sb);
+ if (i > 0) {
+ sb.append(", ");
+ }
+ i++;
+ }
+ }
+ sb.append(']');
sb.append('}');
return sb;
@@ -216,6 +240,83 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
return toString(new StringBuilder()).toString();
}
+ /**
+ * class that captures details of a struct-attribute.
+ */
+ @JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
+ @JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
+ @JsonIgnoreProperties(ignoreUnknown=true)
+ @XmlRootElement
+ @XmlAccessorType(XmlAccessType.PROPERTY)
+ public static class AtlasRelationshipAttributeDef extends AtlasAttributeDef implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private String relationshipTypeName;
+ private boolean isLegacyAttribute;
+
+ public AtlasRelationshipAttributeDef() { }
+
+ public AtlasRelationshipAttributeDef(String relationshipTypeName, boolean isLegacyAttribute, AtlasAttributeDef attributeDef) {
+ super(attributeDef);
+
+ this.relationshipTypeName = relationshipTypeName;
+ this.isLegacyAttribute = isLegacyAttribute;
+ }
+
+ public String getRelationshipTypeName() {
+ return relationshipTypeName;
+ }
+
+ public void setRelationshipTypeName(String relationshipTypeName) {
+ this.relationshipTypeName = relationshipTypeName;
+ }
+
+ public boolean getIsLegacyAttribute() {
+ return isLegacyAttribute;
+ }
+
+ public void setIsLegacyAttribute(boolean isLegacyAttribute) {
+ this.isLegacyAttribute = isLegacyAttribute;
+ }
+
+ public StringBuilder toString(StringBuilder sb) {
+ if (sb == null) {
+ sb = new StringBuilder();
+ }
+
+ sb.append("AtlasRelationshipAttributeDef{");
+ super.toString(sb);
+ sb.append(", relationshipTypeName='").append(relationshipTypeName).append('\'');
+ sb.append(", isLegacyAttribute='").append(isLegacyAttribute).append('\'');
+ sb.append('}');
+
+ return sb;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AtlasRelationshipAttributeDef that = (AtlasRelationshipAttributeDef) o;
+
+ return super.equals(that) &&
+ isLegacyAttribute == that.isLegacyAttribute &&
+ Objects.equals(relationshipTypeName, that.relationshipTypeName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), relationshipTypeName, isLegacyAttribute);
+ }
+
+ @Override
+ public String toString() {
+ return toString(new StringBuilder()).toString();
+ }
+ }
+
/**
* REST serialization friendly list.
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 87a327a..1ce776e 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
@@ -24,6 +24,7 @@ import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasEntityDef;
+import org.apache.atlas.model.typedef.AtlasEntityDef.AtlasRelationshipAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.type.AtlasBuiltInTypes.AtlasObjectIdType;
import org.apache.atlas.utils.AtlasEntityUtil;
@@ -241,6 +242,21 @@ public class AtlasEntityType extends AtlasStructType {
ownedRefAttributes = Collections.unmodifiableList(ownedRefAttributes);
entityDef.setSubTypes(subTypes);
+
+ List<AtlasRelationshipAttributeDef> relationshipAttrDefs = new ArrayList<>();
+
+ for (Map.Entry<String, Map<String, AtlasAttribute>> attrEntry : relationshipAttributes.entrySet()) {
+ Map<String, AtlasAttribute> relations = attrEntry.getValue();
+
+ for (Map.Entry<String, AtlasAttribute> relationsEntry : relations.entrySet()) {
+ String relationshipType = relationsEntry.getKey();
+ AtlasAttribute relationshipAttr = relationsEntry.getValue();
+
+ relationshipAttrDefs.add(new AtlasRelationshipAttributeDef(relationshipType, relationshipAttr.isLegacyAttribute(), relationshipAttr.getAttributeDef()));
+ }
+ }
+
+ entityDef.setRelationshipAttributeDefs(Collections.unmodifiableList(relationshipAttrDefs));
}
public Set<String> getSuperTypes() {
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
index 183772b..585d176 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
@@ -349,11 +349,13 @@ public class AtlasRelationshipType extends AtlasStructType {
attribute = new AtlasAttribute(entityType, attributeDef,
typeRegistry.getType(attrTypeName), getTypeName(), relationshipLabel);
+ attribute.setLegacyAttribute(endDef.getIsLegacyAttribute());
} else {
// attribute already exists (legacy attribute which is also a relationship attribute)
// add relationshipLabel information to existing attribute
attribute.setRelationshipName(getTypeName());
attribute.setRelationshipEdgeLabel(relationshipLabel);
+ attribute.setLegacyAttribute(true);
}
entityType.addRelationshipAttribute(attrName, attribute, this);
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java b/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
index 0be7e18..fb24df0 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
@@ -708,6 +708,7 @@ public class AtlasStructType extends AtlasType {
private String relationshipName;
private String relationshipEdgeLabel;
private AtlasRelationshipEdgeDirection relationshipEdgeDirection;
+ private boolean isLegacyAttribute;
public AtlasAttribute(AtlasStructType definedInType, AtlasAttributeDef attrDef, AtlasType attributeType, String relationshipName, String relationshipLabel) {
this.definedInType = definedInType;
@@ -815,6 +816,10 @@ public class AtlasStructType extends AtlasType {
this.relationshipEdgeDirection = relationshipEdgeDirection;
}
+ public boolean isLegacyAttribute() { return isLegacyAttribute; }
+
+ public void setLegacyAttribute(boolean legacyAttribute) { isLegacyAttribute = legacyAttribute; }
+
public static String getEdgeLabel(String property) {
return "__" + property;
}