Commit 07192bc8 by Madhan Neethiraj

ATLAS-3107: updated AtlasEntityDef with addition of read-only field relationshipAttributeDefs

parent 14037eed
......@@ -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.
......
......@@ -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() {
......
......@@ -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);
......
......@@ -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;
}
......
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