Commit 5651f934 by Madhan Neethiraj

ATLAS-3063: updated entity create/update to enable relationship-type to be…

ATLAS-3063: updated entity create/update to enable relationship-type to be specified for relationship attributes
parent ffa96f75
...@@ -43,14 +43,17 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ ...@@ -43,14 +43,17 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_
public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable { public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static final String KEY_RELATIONSHIP_TYPE = "relationshipType";
public static final String KEY_RELATIONSHIP_GUID = "relationshipGuid"; public static final String KEY_RELATIONSHIP_GUID = "relationshipGuid";
public static final String KEY_RELATIONSHIP_STATUS = "relationshipStatus";
public static final String KEY_RELATIONSHIP_ATTRIBUTES = "relationshipAttributes"; public static final String KEY_RELATIONSHIP_ATTRIBUTES = "relationshipAttributes";
private AtlasEntity.Status entityStatus = null; private AtlasEntity.Status entityStatus = null;
private String displayText = null; private String displayText = null;
private String relationshipType = null;
private String relationshipGuid = null; private String relationshipGuid = null;
private AtlasRelationship.Status relationshipStatus = null; private AtlasRelationship.Status relationshipStatus = null;
private AtlasStruct relationshipAttributes; private AtlasStruct relationshipAttributes = null;
public AtlasRelatedObjectId() { } public AtlasRelatedObjectId() { }
...@@ -76,17 +79,76 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable ...@@ -76,17 +79,76 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable
setRelationshipAttributes(relationshipAttributes); setRelationshipAttributes(relationshipAttributes);
} }
public AtlasRelatedObjectId(AtlasObjectId other) {
super(other);
}
public AtlasRelatedObjectId(Map objIdMap) {
super(objIdMap);
if (objIdMap != null) {
Object g = objIdMap.get(KEY_RELATIONSHIP_GUID);
Object t = objIdMap.get(KEY_RELATIONSHIP_TYPE);
Object a = objIdMap.get(KEY_RELATIONSHIP_ATTRIBUTES);
Object s = objIdMap.get(KEY_RELATIONSHIP_STATUS);
if (g != null) {
setRelationshipGuid(g.toString());
}
if (a instanceof Map) {
setRelationshipAttributes(new AtlasStruct((Map) a));
} else if (a instanceof AtlasStruct) {
setRelationshipAttributes(new AtlasStruct((AtlasStruct) a));
}
if (t != null) {
setRelationshipType(t.toString());
}
if (s != null) {
setRelationshipStatus(AtlasRelationship.Status.valueOf(s.toString()));
}
}
}
public AtlasEntity.Status getEntityStatus() {
return entityStatus;
}
public void setEntityStatus(AtlasEntity.Status entityStatus) {
this.entityStatus = entityStatus;
}
public String getDisplayText() { return displayText; } public String getDisplayText() { return displayText; }
public void setDisplayText(String displayText) { this.displayText = displayText; } public void setDisplayText(String displayText) { this.displayText = displayText; }
public String getRelationshipType() { return relationshipType; }
public void setRelationshipType(String relationshipType) { this.relationshipType = relationshipType; }
public String getRelationshipGuid() { return relationshipGuid; } public String getRelationshipGuid() { return relationshipGuid; }
public void setRelationshipGuid(String relationshipGuid) { this.relationshipGuid = relationshipGuid; } public void setRelationshipGuid(String relationshipGuid) { this.relationshipGuid = relationshipGuid; }
public AtlasRelationship.Status getRelationshipStatus() {
return relationshipStatus;
}
public void setRelationshipStatus(final AtlasRelationship.Status relationshipStatus) {
this.relationshipStatus = relationshipStatus;
}
public AtlasStruct getRelationshipAttributes() { return relationshipAttributes; } public AtlasStruct getRelationshipAttributes() { return relationshipAttributes; }
public void setRelationshipAttributes(AtlasStruct relationshipAttributes) { this.relationshipAttributes = relationshipAttributes; } public void setRelationshipAttributes(AtlasStruct relationshipAttributes) {
this.relationshipAttributes = relationshipAttributes;
if (relationshipAttributes != null && relationshipAttributes.getTypeName() != null) {
setRelationshipType(relationshipAttributes.getTypeName());
}
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
...@@ -96,6 +158,7 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable ...@@ -96,6 +158,7 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable
AtlasRelatedObjectId that = (AtlasRelatedObjectId) o; AtlasRelatedObjectId that = (AtlasRelatedObjectId) o;
return Objects.equals(entityStatus, that.entityStatus) && return Objects.equals(entityStatus, that.entityStatus) &&
Objects.equals(displayText, that.displayText) && Objects.equals(displayText, that.displayText) &&
Objects.equals(relationshipType, that.relationshipType) &&
Objects.equals(relationshipGuid, that.relationshipGuid) && Objects.equals(relationshipGuid, that.relationshipGuid) &&
Objects.equals(relationshipStatus, that.relationshipStatus) && Objects.equals(relationshipStatus, that.relationshipStatus) &&
Objects.equals(relationshipAttributes, that.relationshipAttributes); Objects.equals(relationshipAttributes, that.relationshipAttributes);
...@@ -103,7 +166,7 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable ...@@ -103,7 +166,7 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(super.hashCode(), displayText, relationshipGuid, relationshipStatus, relationshipAttributes); return Objects.hash(super.hashCode(), displayText, relationshipType, relationshipGuid, relationshipStatus, relationshipAttributes);
} }
@Override @Override
...@@ -121,6 +184,7 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable ...@@ -121,6 +184,7 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable
super.toString(sb); super.toString(sb);
sb.append("entityStatus='").append(entityStatus).append('\''); sb.append("entityStatus='").append(entityStatus).append('\'');
sb.append(", displayText='").append(displayText).append('\''); sb.append(", displayText='").append(displayText).append('\'');
sb.append(", relationshipType='").append(relationshipType).append('\'');
sb.append(", relationshipGuid='").append(relationshipGuid).append('\''); sb.append(", relationshipGuid='").append(relationshipGuid).append('\'');
sb.append(", relationshipStatus='").append(relationshipStatus).append('\''); sb.append(", relationshipStatus='").append(relationshipStatus).append('\'');
sb.append(", relationshipAttributes=").append(relationshipAttributes); sb.append(", relationshipAttributes=").append(relationshipAttributes);
...@@ -128,20 +192,4 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable ...@@ -128,20 +192,4 @@ public class AtlasRelatedObjectId extends AtlasObjectId implements Serializable
return sb; return sb;
} }
public AtlasRelationship.Status getRelationshipStatus() {
return relationshipStatus;
}
public void setRelationshipStatus(final AtlasRelationship.Status relationshipStatus) {
this.relationshipStatus = relationshipStatus;
}
public AtlasEntity.Status getEntityStatus() {
return entityStatus;
}
public void setEntityStatus(AtlasEntity.Status entityStatus) {
this.entityStatus = entityStatus;
}
} }
\ No newline at end of file
...@@ -123,9 +123,9 @@ public class AtlasRelationshipType extends AtlasStructType { ...@@ -123,9 +123,9 @@ public class AtlasRelationshipType extends AtlasStructType {
relationshipLabel = getLegacyEdgeLabel(end2Type, endDef2.getName()); relationshipLabel = getLegacyEdgeLabel(end2Type, endDef2.getName());
} }
addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel, relationshipDef.getRelationshipCategory()); addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel);
addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel, relationshipDef.getRelationshipCategory()); addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel);
// add relationship edge direction information // add relationship edge direction information
addRelationshipEdgeDirection(); addRelationshipEdgeDirection();
...@@ -138,12 +138,12 @@ public class AtlasRelationshipType extends AtlasStructType { ...@@ -138,12 +138,12 @@ public class AtlasRelationshipType extends AtlasStructType {
if (StringUtils.equals(endDef1.getType(), endDef2.getType()) && if (StringUtils.equals(endDef1.getType(), endDef2.getType()) &&
StringUtils.equals(endDef1.getName(), endDef2.getName())) { StringUtils.equals(endDef1.getName(), endDef2.getName())) {
AtlasAttribute endAttribute = end1Type.getRelationshipAttribute(endDef1.getName()); AtlasAttribute endAttribute = end1Type.getRelationshipAttribute(endDef1.getName(), relationshipDef.getName());
endAttribute.setRelationshipEdgeDirection(BOTH); endAttribute.setRelationshipEdgeDirection(BOTH);
} else { } else {
AtlasAttribute end1Attribute = end1Type.getRelationshipAttribute(endDef1.getName()); AtlasAttribute end1Attribute = end1Type.getRelationshipAttribute(endDef1.getName(), relationshipDef.getName());
AtlasAttribute end2Attribute = end2Type.getRelationshipAttribute(endDef2.getName()); AtlasAttribute end2Attribute = end2Type.getRelationshipAttribute(endDef2.getName(), relationshipDef.getName());
//default relationship edge direction is end1 (out) -> end2 (in) //default relationship edge direction is end1 (out) -> end2 (in)
AtlasRelationshipEdgeDirection end1Direction = OUT; AtlasRelationshipEdgeDirection end1Direction = OUT;
...@@ -296,7 +296,7 @@ public class AtlasRelationshipType extends AtlasStructType { ...@@ -296,7 +296,7 @@ public class AtlasRelationshipType extends AtlasStructType {
} }
private void addRelationshipAttributeToEndType(AtlasRelationshipEndDef endDef, AtlasEntityType entityType, String attrTypeName, private void addRelationshipAttributeToEndType(AtlasRelationshipEndDef endDef, AtlasEntityType entityType, String attrTypeName,
AtlasTypeRegistry typeRegistry, String relationshipLabel, RelationshipCategory relationshipCategory) throws AtlasBaseException { AtlasTypeRegistry typeRegistry, String relationshipLabel) throws AtlasBaseException {
String attrName = (endDef != null) ? endDef.getName() : null; String attrName = (endDef != null) ? endDef.getName() : null;
...@@ -321,7 +321,7 @@ public class AtlasRelationshipType extends AtlasStructType { ...@@ -321,7 +321,7 @@ public class AtlasRelationshipType extends AtlasStructType {
attrTypeName = AtlasBaseTypeDef.getArrayTypeName(attrTypeName); attrTypeName = AtlasBaseTypeDef.getArrayTypeName(attrTypeName);
} }
if (relationshipCategory == RelationshipCategory.COMPOSITION) { if (relationshipDef.getRelationshipCategory() == RelationshipCategory.COMPOSITION) {
if (endDef.getIsContainer()) { if (endDef.getIsContainer()) {
constraint = new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF); constraint = new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF);
} else { } else {
...@@ -344,9 +344,7 @@ public class AtlasRelationshipType extends AtlasStructType { ...@@ -344,9 +344,7 @@ public class AtlasRelationshipType extends AtlasStructType {
attribute.setRelationshipEdgeLabel(relationshipLabel); attribute.setRelationshipEdgeLabel(relationshipLabel);
} }
entityType.addRelationshipAttribute(attrName, attribute); entityType.addRelationshipAttribute(attrName, attribute, this);
entityType.addRelationshipAttributeType(attrName, this);
} }
private String getLegacyEdgeLabel(AtlasEntityType entityType, String attributeName) { private String getLegacyEdgeLabel(AtlasEntityType entityType, String attributeName) {
......
...@@ -852,7 +852,7 @@ public class AtlasStructType extends AtlasType { ...@@ -852,7 +852,7 @@ public class AtlasStructType extends AtlasType {
} }
private String getRelationshipEdgeLabel(String relationshipLabel) { private String getRelationshipEdgeLabel(String relationshipLabel) {
return (relationshipLabel == null) ? getEdgeLabel(vertexPropertyName) : relationshipLabel; return (relationshipLabel == null) ? getEdgeLabel(qualifiedName) : relationshipLabel;
} }
private static String getQualifiedAttributeName(AtlasStructDef structDef, String attrName) { private static String getQualifiedAttributeName(AtlasStructDef structDef, String attrName) {
......
...@@ -18,11 +18,8 @@ ...@@ -18,11 +18,8 @@
package org.apache.atlas.utils; package org.apache.atlas.utils;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -123,4 +120,21 @@ public class AtlasEntityUtil { ...@@ -123,4 +120,21 @@ public class AtlasEntityUtil {
return ret; return ret;
} }
public static String getRelationshipType(Object val) {
final String ret;
if (val instanceof AtlasRelatedObjectId) {
ret = ((AtlasRelatedObjectId) val).getRelationshipType();
} else if (val instanceof Map) {
Object relTypeName = ((Map) val).get(AtlasRelatedObjectId.KEY_RELATIONSHIP_TYPE);
ret = relTypeName != null ? relTypeName.toString() : null;
} else {
ret = null;
}
return ret;
}
} }
...@@ -140,7 +140,7 @@ public class TestAtlasRelationshipType { ...@@ -140,7 +140,7 @@ public class TestAtlasRelationshipType {
@Test(dependsOnMethods = "createTypesAndRelationships") @Test(dependsOnMethods = "createTypesAndRelationships")
public void testRelationshipAttributes() throws Exception { public void testRelationshipAttributes() throws Exception {
Map<String, AtlasAttribute> employeeRelationAttrs = getRelationAttrsForType(EMPLOYEE_TYPE); Map<String, Map<String, AtlasAttribute>> employeeRelationAttrs = getRelationAttrsForType(EMPLOYEE_TYPE);
Assert.assertNotNull(employeeRelationAttrs); Assert.assertNotNull(employeeRelationAttrs);
Assert.assertEquals(employeeRelationAttrs.size(), 2); Assert.assertEquals(employeeRelationAttrs.size(), 2);
...@@ -148,28 +148,28 @@ public class TestAtlasRelationshipType { ...@@ -148,28 +148,28 @@ public class TestAtlasRelationshipType {
Assert.assertTrue(employeeRelationAttrs.containsKey("department")); Assert.assertTrue(employeeRelationAttrs.containsKey("department"));
Assert.assertTrue(employeeRelationAttrs.containsKey("address")); Assert.assertTrue(employeeRelationAttrs.containsKey("address"));
AtlasAttribute deptAttr = employeeRelationAttrs.get("department"); AtlasAttribute deptAttr = employeeRelationAttrs.get("department").values().iterator().next();
Assert.assertEquals(deptAttr.getTypeName(), DEPARTMENT_TYPE); Assert.assertEquals(deptAttr.getTypeName(), DEPARTMENT_TYPE);
AtlasAttribute addrAttr = employeeRelationAttrs.get("address"); AtlasAttribute addrAttr = employeeRelationAttrs.get("address").values().iterator().next();
Assert.assertEquals(addrAttr.getTypeName(), ADDRESS_TYPE); Assert.assertEquals(addrAttr.getTypeName(), ADDRESS_TYPE);
Map<String, AtlasAttribute> deptRelationAttrs = getRelationAttrsForType(DEPARTMENT_TYPE); Map<String, Map<String, AtlasAttribute>> deptRelationAttrs = getRelationAttrsForType(DEPARTMENT_TYPE);
Assert.assertNotNull(deptRelationAttrs); Assert.assertNotNull(deptRelationAttrs);
Assert.assertEquals(deptRelationAttrs.size(), 1); Assert.assertEquals(deptRelationAttrs.size(), 1);
Assert.assertTrue(deptRelationAttrs.containsKey("employees")); Assert.assertTrue(deptRelationAttrs.containsKey("employees"));
AtlasAttribute employeesAttr = deptRelationAttrs.get("employees"); AtlasAttribute employeesAttr = deptRelationAttrs.get("employees").values().iterator().next();
Assert.assertEquals(employeesAttr.getTypeName(),AtlasBaseTypeDef.getArrayTypeName(EMPLOYEE_TYPE)); Assert.assertEquals(employeesAttr.getTypeName(),AtlasBaseTypeDef.getArrayTypeName(EMPLOYEE_TYPE));
Map<String, AtlasAttribute> addressRelationAttrs = getRelationAttrsForType(ADDRESS_TYPE); Map<String, Map<String, AtlasAttribute>> addressRelationAttrs = getRelationAttrsForType(ADDRESS_TYPE);
Assert.assertNotNull(addressRelationAttrs); Assert.assertNotNull(addressRelationAttrs);
Assert.assertEquals(addressRelationAttrs.size(), 1); Assert.assertEquals(addressRelationAttrs.size(), 1);
Assert.assertTrue(addressRelationAttrs.containsKey("employees")); Assert.assertTrue(addressRelationAttrs.containsKey("employees"));
AtlasAttribute employeesAttr1 = addressRelationAttrs.get("employees"); AtlasAttribute employeesAttr1 = addressRelationAttrs.get("employees").values().iterator().next();
Assert.assertEquals(employeesAttr1.getTypeName(),AtlasBaseTypeDef.getArrayTypeName(EMPLOYEE_TYPE)); Assert.assertEquals(employeesAttr1.getTypeName(),AtlasBaseTypeDef.getArrayTypeName(EMPLOYEE_TYPE));
} }
...@@ -182,7 +182,7 @@ public class TestAtlasRelationshipType { ...@@ -182,7 +182,7 @@ public class TestAtlasRelationshipType {
createType(employeePhoneRelationDef); createType(employeePhoneRelationDef);
Map<String, AtlasAttribute> employeeRelationshipAttrs = getRelationAttrsForType(EMPLOYEE_TYPE); Map<String, Map<String, AtlasAttribute>> employeeRelationshipAttrs = getRelationAttrsForType(EMPLOYEE_TYPE);
Map<String, AtlasAttribute> employeeAttrs = getAttrsForType(EMPLOYEE_TYPE); Map<String, AtlasAttribute> employeeAttrs = getAttrsForType(EMPLOYEE_TYPE);
// validate if phone_no exists in both relationAttributes and attributes // validate if phone_no exists in both relationAttributes and attributes
...@@ -245,7 +245,7 @@ public class TestAtlasRelationshipType { ...@@ -245,7 +245,7 @@ public class TestAtlasRelationshipType {
return typeName + " description"; return typeName + " description";
} }
private Map<String, AtlasAttribute> getRelationAttrsForType(String typeName) { private Map<String, Map<String, AtlasAttribute>> getRelationAttrsForType(String typeName) {
return typeRegistry.getEntityTypeByName(typeName).getRelationshipAttributes(); return typeRegistry.getEntityTypeByName(typeName).getRelationshipAttributes();
} }
......
...@@ -81,7 +81,6 @@ import static org.apache.atlas.model.TypeCategory.MAP; ...@@ -81,7 +81,6 @@ import static org.apache.atlas.model.TypeCategory.MAP;
import static org.apache.atlas.model.TypeCategory.OBJECT_ID_TYPE; import static org.apache.atlas.model.TypeCategory.OBJECT_ID_TYPE;
import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE; import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE;
import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED; import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED;
import static org.apache.atlas.repository.graph.GraphHelper.EDGE_LABEL_PREFIX;
import static org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery.*; import static org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery.*;
@Component @Component
...@@ -539,7 +538,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService { ...@@ -539,7 +538,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
if (attribute != null) { if (attribute != null) {
if (isRelationshipAttribute(attribute)) { if (isRelationshipAttribute(attribute)) {
relation = EDGE_LABEL_PREFIX + attribute.getQualifiedName(); relation = attribute.getRelationshipEdgeLabel();
} else { } else {
throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_ATTRIBUTE, relation, attribute.getTypeName()); throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_ATTRIBUTE, relation, attribute.getTypeName());
} }
......
...@@ -31,6 +31,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph; ...@@ -31,6 +31,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery; import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever;
import org.apache.atlas.type.AtlasClassificationType; import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType; import org.apache.atlas.type.AtlasStructType;
...@@ -239,7 +240,7 @@ public class SearchContext { ...@@ -239,7 +240,7 @@ public class SearchContext {
private List<AtlasVertex> getAssignedEntities(AtlasVertex glossaryTerm) { private List<AtlasVertex> getAssignedEntities(AtlasVertex glossaryTerm) {
List<AtlasVertex> ret = new ArrayList<>(); List<AtlasVertex> ret = new ArrayList<>();
AtlasEntityType termType = getTermEntityType(); AtlasEntityType termType = getTermEntityType();
AtlasAttribute attr = termType.getRelationshipAttribute(TermSearchProcessor.ATLAS_GLOSSARY_TERM_ATTR_ASSIGNED_ENTITIES); AtlasAttribute attr = termType.getRelationshipAttribute(TermSearchProcessor.ATLAS_GLOSSARY_TERM_ATTR_ASSIGNED_ENTITIES, EntityGraphRetriever.TERM_RELATION_NAME);
Iterator<AtlasEdge> edges = GraphHelper.getEdgesForLabel(glossaryTerm, attr.getRelationshipEdgeLabel(), attr.getRelationshipEdgeDirection()); Iterator<AtlasEdge> edges = GraphHelper.getEdgesForLabel(glossaryTerm, attr.getRelationshipEdgeLabel(), attr.getRelationshipEdgeDirection());
boolean excludeDeletedEntities = searchParameters.getExcludeDeletedEntities(); boolean excludeDeletedEntities = searchParameters.getExcludeDeletedEntities();
......
...@@ -31,7 +31,6 @@ import org.apache.atlas.model.instance.AtlasEntity.Status; ...@@ -31,7 +31,6 @@ import org.apache.atlas.model.instance.AtlasEntity.Status;
import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.repository.graphdb.AtlasVertexQuery; import org.apache.atlas.repository.graphdb.AtlasVertexQuery;
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
import org.apache.atlas.type.AtlasArrayType; import org.apache.atlas.type.AtlasArrayType;
...@@ -51,7 +50,6 @@ import org.apache.atlas.repository.graphdb.AtlasGraph; ...@@ -51,7 +50,6 @@ import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasGraphQuery; import org.apache.atlas.repository.graphdb.AtlasGraphQuery;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.exception.EntityNotFoundException; import org.apache.atlas.exception.EntityNotFoundException;
import org.apache.atlas.util.AttributeValueMap; import org.apache.atlas.util.AttributeValueMap;
...@@ -1058,7 +1056,7 @@ public final class GraphHelper { ...@@ -1058,7 +1056,7 @@ public final class GraphHelper {
} }
public static String getEdgeLabel(AtlasAttribute aInfo) throws AtlasException { public static String getEdgeLabel(AtlasAttribute aInfo) throws AtlasException {
return GraphHelper.EDGE_LABEL_PREFIX + aInfo.getQualifiedName(); return aInfo.getRelationshipEdgeLabel();
} }
public static Id getIdFromVertex(String dataTypeName, AtlasVertex vertex) { public static Id getIdFromVertex(String dataTypeName, AtlasVertex vertex) {
...@@ -1774,40 +1772,27 @@ public final class GraphHelper { ...@@ -1774,40 +1772,27 @@ public final class GraphHelper {
* resolve by comparing all incoming edges typename with relationDefs name returned for an attribute * resolve by comparing all incoming edges typename with relationDefs name returned for an attribute
* to pick the right relationshipDef name * to pick the right relationshipDef name
*/ */
public String getRelationshipDefName(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) { public String getRelationshipTypeName(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) {
AtlasRelationshipDef relationshipDef = getRelationshipDef(entityVertex, entityType, attributeName); String ret = null;
Collection<String> relationshipTypes = entityType.getAttributeRelationshipTypes(attributeName);
return (relationshipDef != null) ? relationshipDef.getName() : null; if (CollectionUtils.isNotEmpty(relationshipTypes)) {
}
public AtlasRelationshipDef getRelationshipDef(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) {
List<AtlasRelationshipType> relationshipTypes = entityType.getRelationshipAttributeType(attributeName);
AtlasRelationshipDef ret = null;
if (relationshipTypes.size() > 1) {
Iterator<AtlasEdge> iter = entityVertex.getEdges(AtlasEdgeDirection.IN).iterator(); Iterator<AtlasEdge> iter = entityVertex.getEdges(AtlasEdgeDirection.IN).iterator();
while (iter.hasNext() && ret == null) { while (iter.hasNext() && ret == null) {
String edgeTypeName = AtlasGraphUtilsV2.getTypeName(iter.next()); String edgeTypeName = AtlasGraphUtilsV2.getTypeName(iter.next());
for (AtlasRelationshipType relationType : relationshipTypes) { if (relationshipTypes.contains(edgeTypeName)) {
AtlasRelationshipDef relationshipDef = relationType.getRelationshipDef(); ret = edgeTypeName;
if (StringUtils.equals(edgeTypeName, relationshipDef.getName())) {
ret = relationshipDef;
break; break;
} }
} }
}
if (ret == null) { if (ret == null) {
ret = relationshipTypes.get(0).getRelationshipDef();
}
} else {
//relationshipTypes will have at least one relationshipDef //relationshipTypes will have at least one relationshipDef
ret = relationshipTypes.get(0).getRelationshipDef(); ret = relationshipTypes.iterator().next();
}
} }
return ret; return ret;
......
...@@ -620,7 +620,7 @@ public class ExportService { ...@@ -620,7 +620,7 @@ public class ExportService {
} else if (type instanceof AtlasEnumType) { } else if (type instanceof AtlasEnumType) {
addEnumType((AtlasEnumType)type, context); addEnumType((AtlasEnumType)type, context);
} else if (type instanceof AtlasRelationshipType) { } else if (type instanceof AtlasRelationshipType) {
addRelationshipType((AtlasRelationshipType)type, context); addRelationshipType(type.getTypeName(), context);
} }
} }
...@@ -667,15 +667,19 @@ public class ExportService { ...@@ -667,15 +667,19 @@ public class ExportService {
} }
} }
private void addRelationshipType(AtlasRelationshipType relationshipType, ExportContext context) { private void addRelationshipType(String relationshipTypeName, ExportContext context) {
if (!context.relationshipTypes.contains(relationshipType.getTypeName())) { if (!context.relationshipTypes.contains(relationshipTypeName)) {
context.relationshipTypes.add(relationshipType.getTypeName()); AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName);
if (relationshipType != null) {
context.relationshipTypes.add(relationshipTypeName);
addAttributeTypes(relationshipType, context); addAttributeTypes(relationshipType, context);
addEntityType(relationshipType.getEnd1Type(), context); addEntityType(relationshipType.getEnd1Type(), context);
addEntityType(relationshipType.getEnd2Type(), context); addEntityType(relationshipType.getEnd2Type(), context);
} }
} }
}
private void addAttributeTypes(AtlasStructType structType, ExportContext context) { private void addAttributeTypes(AtlasStructType structType, ExportContext context) {
for (AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) { for (AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) {
...@@ -684,8 +688,8 @@ public class ExportService { ...@@ -684,8 +688,8 @@ public class ExportService {
} }
private void addRelationshipTypes(AtlasEntityType entityType, ExportContext context) { private void addRelationshipTypes(AtlasEntityType entityType, ExportContext context) {
for (List<AtlasRelationshipType> relationshipTypes : entityType.getRelationshipAttributesType().values()) { for (Map.Entry<String, Map<String, AtlasAttribute>> entry : entityType.getRelationshipAttributes().entrySet()) {
for (AtlasRelationshipType relationshipType : relationshipTypes) { for (String relationshipType : entry.getValue().keySet()) {
addRelationshipType(relationshipType, context); addRelationshipType(relationshipType, context);
} }
} }
......
...@@ -36,7 +36,7 @@ import org.apache.commons.collections.CollectionUtils; ...@@ -36,7 +36,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List; import java.util.Map;
class ExportTypeProcessor { class ExportTypeProcessor {
private static final Logger LOG = LoggerFactory.getLogger(ExportTypeProcessor.class); private static final Logger LOG = LoggerFactory.getLogger(ExportTypeProcessor.class);
...@@ -110,7 +110,7 @@ class ExportTypeProcessor { ...@@ -110,7 +110,7 @@ class ExportTypeProcessor {
} else if (type instanceof AtlasEnumType) { } else if (type instanceof AtlasEnumType) {
addEnumType((AtlasEnumType)type, context); addEnumType((AtlasEnumType)type, context);
} else if (type instanceof AtlasRelationshipType) { } else if (type instanceof AtlasRelationshipType) {
addRelationshipType((AtlasRelationshipType)type, context); addRelationshipType(type.getTypeName(), context);
} }
} }
...@@ -157,15 +157,19 @@ class ExportTypeProcessor { ...@@ -157,15 +157,19 @@ class ExportTypeProcessor {
} }
} }
private void addRelationshipType(AtlasRelationshipType relationshipType, ExportService.ExportContext context) { private void addRelationshipType(String relationshipTypeName, ExportService.ExportContext context) {
if (!context.relationshipTypes.contains(relationshipType.getTypeName())) { if (!context.relationshipTypes.contains(relationshipTypeName)) {
context.relationshipTypes.add(relationshipType.getTypeName()); AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName);
if (relationshipType != null) {
context.relationshipTypes.add(relationshipTypeName);
addAttributeTypes(relationshipType, context); addAttributeTypes(relationshipType, context);
addEntityType(relationshipType.getEnd1Type(), context); addEntityType(relationshipType.getEnd1Type(), context);
addEntityType(relationshipType.getEnd2Type(), context); addEntityType(relationshipType.getEnd2Type(), context);
} }
} }
}
private void addAttributeTypes(AtlasStructType structType, ExportService.ExportContext context) { private void addAttributeTypes(AtlasStructType structType, ExportService.ExportContext context) {
for (AtlasStructDef.AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) { for (AtlasStructDef.AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) {
...@@ -174,8 +178,8 @@ class ExportTypeProcessor { ...@@ -174,8 +178,8 @@ class ExportTypeProcessor {
} }
private void addRelationshipTypes(AtlasEntityType entityType, ExportService.ExportContext context) { private void addRelationshipTypes(AtlasEntityType entityType, ExportService.ExportContext context) {
for (List<AtlasRelationshipType> relationshipTypes : entityType.getRelationshipAttributesType().values()) { for (Map.Entry<String, Map<String, AtlasStructType.AtlasAttribute>> entry : entityType.getRelationshipAttributes().entrySet()) {
for (AtlasRelationshipType relationshipType : relationshipTypes) { for (String relationshipType : entry.getValue().keySet()) {
addRelationshipType(relationshipType, context); addRelationshipType(relationshipType, context);
} }
} }
......
...@@ -36,6 +36,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute; ...@@ -36,6 +36,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AtlasEntityUtil;
import org.apache.atlas.utils.AtlasPerfMetrics.MetricRecorder; import org.apache.atlas.utils.AtlasPerfMetrics.MetricRecorder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -330,16 +331,23 @@ public class AtlasEntityGraphDiscoveryV2 implements EntityGraphDiscovery { ...@@ -330,16 +331,23 @@ public class AtlasEntityGraphDiscoveryV2 implements EntityGraphDiscovery {
} }
private void visitRelationships(AtlasEntityType entityType, AtlasEntity entity, List<String> visitedAttributes) throws AtlasBaseException { private void visitRelationships(AtlasEntityType entityType, AtlasEntity entity, List<String> visitedAttributes) throws AtlasBaseException {
for (AtlasAttribute attribute : entityType.getRelationshipAttributes().values()) { for (String attrName : entityType.getRelationshipAttributes().keySet()) {
String attrName = attribute.getName();
// if attribute is not in 'relationshipAttributes', try 'attributes' // if attribute is not in 'relationshipAttributes', try 'attributes'
if (entity.hasRelationshipAttribute(attrName)) { if (entity.hasRelationshipAttribute(attrName)) {
visitAttribute(attribute.getAttributeType(), entity.getRelationshipAttribute(attrName)); Object attrVal = entity.getRelationshipAttribute(attrName);
String relationshipType = AtlasEntityUtil.getRelationshipType(attrVal);
AtlasAttribute attribute = entityType.getRelationshipAttribute(attrName, relationshipType);
visitAttribute(attribute.getAttributeType(), attrVal);
visitedAttributes.add(attrName); visitedAttributes.add(attrName);
} else if (entity.hasAttribute(attrName)) { } else if (entity.hasAttribute(attrName)) {
visitAttribute(attribute.getAttributeType(), entity.getAttribute(attrName)); Object attrVal = entity.getAttribute(attrName);
String relationshipType = AtlasEntityUtil.getRelationshipType(attrVal);
AtlasAttribute attribute = entityType.getRelationshipAttribute(attrName, relationshipType);
visitAttribute(attribute.getAttributeType(), attrVal);
visitedAttributes.add(attrName); visitedAttributes.add(attrName);
} }
......
...@@ -41,6 +41,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute; ...@@ -41,6 +41,7 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AtlasEntityUtil;
import org.apache.atlas.utils.AtlasPerfMetrics.MetricRecorder; import org.apache.atlas.utils.AtlasPerfMetrics.MetricRecorder;
import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -760,12 +761,14 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore { ...@@ -760,12 +761,14 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
} }
if (!hasUpdates && MapUtils.isNotEmpty(entity.getRelationshipAttributes())) { // check of relationsship-attribute value change if (!hasUpdates && MapUtils.isNotEmpty(entity.getRelationshipAttributes())) { // check of relationsship-attribute value change
for (AtlasAttribute attribute : entityType.getRelationshipAttributes().values()) { for (String attributeName : entityType.getRelationshipAttributes().keySet()) {
if (!entity.getRelationshipAttributes().containsKey(attribute.getName())) { // if value is not provided, current value will not be updated if (!entity.getRelationshipAttributes().containsKey(attributeName)) { // if value is not provided, current value will not be updated
continue; continue;
} }
Object newVal = entity.getRelationshipAttribute(attribute.getName()); Object newVal = entity.getRelationshipAttribute(attributeName);
String relationshipType = AtlasEntityUtil.getRelationshipType(newVal);
AtlasAttribute attribute = entityType.getRelationshipAttribute(attributeName, relationshipType);
Object currVal = entityRetriever.getEntityAttribute(vertex, attribute); Object currVal = entityRetriever.getEntityAttribute(vertex, attribute);
if (!attribute.getAttributeType().areEqualValues(currVal, newVal, context.getGuidAssignments())) { if (!attribute.getAttributeType().areEqualValues(currVal, newVal, context.getGuidAssignments())) {
......
...@@ -126,10 +126,6 @@ public class AtlasGraphUtilsV2 { ...@@ -126,10 +126,6 @@ public class AtlasGraphUtilsV2 {
return GraphHelper.EDGE_LABEL_PREFIX + property; return GraphHelper.EDGE_LABEL_PREFIX + property;
} }
public static String getAttributeEdgeLabel(AtlasStructType fromType, String attributeName) throws AtlasBaseException {
return getEdgeLabel(getQualifiedAttributePropertyKey(fromType, attributeName));
}
public static String getQualifiedAttributePropertyKey(AtlasStructType fromType, String attributeName) throws AtlasBaseException { public static String getQualifiedAttributePropertyKey(AtlasStructType fromType, String attributeName) throws AtlasBaseException {
switch (fromType.getTypeCategory()) { switch (fromType.getTypeCategory()) {
case ENTITY: case ENTITY:
......
...@@ -459,6 +459,7 @@ public class AtlasRelationshipDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasRe ...@@ -459,6 +459,7 @@ public class AtlasRelationshipDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasRe
// Update RelationshipCategory // Update RelationshipCategory
vertex.setProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, relationshipCategory); vertex.setProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, relationshipCategory);
vertex.setProperty(Constants.RELATIONSHIPTYPE_LABEL_KEY, relationshipDef.getRelationshipLabel());
vertex.setProperty(Constants.RELATIONSHIPTYPE_LABEL_KEY, relationshipDef.getRelationshipLabel()); vertex.setProperty(Constants.RELATIONSHIPTYPE_LABEL_KEY, relationshipDef.getRelationshipLabel());
......
...@@ -810,12 +810,11 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -810,12 +810,11 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) { if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) {
String attributeName = endDef1.getName(); String attributeName = endDef1.getName();
attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName); attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName, relationshipTypeName);
} else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) { } else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) {
String attributeName = endDef2.getName(); String attributeName = endDef2.getName();
attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName); attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName, relationshipTypeName);
} }
if (attribute != null) { if (attribute != null) {
......
...@@ -339,17 +339,21 @@ public class EntityGraphMapper { ...@@ -339,17 +339,21 @@ public class EntityGraphMapper {
MetricRecorder metric = RequestContext.get().startMetricRecord("mapRelationshipAttributes"); MetricRecorder metric = RequestContext.get().startMetricRecord("mapRelationshipAttributes");
if (op.equals(CREATE)) { if (op.equals(CREATE)) {
for (AtlasAttribute attribute : entityType.getRelationshipAttributes().values()) { for (String attrName : entityType.getRelationshipAttributes().keySet()) {
Object attrValue = entity.getRelationshipAttribute(attribute.getName()); Object attrValue = entity.getRelationshipAttribute(attrName);
String relationType = AtlasEntityUtil.getRelationshipType(attrValue);
AtlasAttribute attribute = entityType.getRelationshipAttribute(attrName, relationType);
mapAttribute(attribute, attrValue, vertex, op, context); mapAttribute(attribute, attrValue, vertex, op, context);
} }
} else if (op.equals(UPDATE)) { } else if (op.equals(UPDATE)) {
// relationship attributes mapping // relationship attributes mapping
for (AtlasAttribute attribute : entityType.getRelationshipAttributes().values()) { for (String attrName : entityType.getRelationshipAttributes().keySet()) {
if (attribute != null && entity.hasRelationshipAttribute(attribute.getName())) { if (entity.hasRelationshipAttribute(attrName)) {
Object attrValue = entity.getRelationshipAttribute(attribute.getName()); Object attrValue = entity.getRelationshipAttribute(attrName);
String relationType = AtlasEntityUtil.getRelationshipType(attrValue);
AtlasAttribute attribute = entityType.getRelationshipAttribute(attrName, relationType);
mapAttribute(attribute, attrValue, vertex, op, context); mapAttribute(attribute, attrValue, vertex, op, context);
} }
...@@ -599,7 +603,7 @@ public class EntityGraphMapper { ...@@ -599,7 +603,7 @@ public class EntityGraphMapper {
AtlasEntityType entityType = (AtlasEntityType) inverseAttributeType; AtlasEntityType entityType = (AtlasEntityType) inverseAttributeType;
if (entityType.hasRelationshipAttribute(inverseAttributeName)) { if (entityType.hasRelationshipAttribute(inverseAttributeName)) {
String relationshipName = graphHelper.getRelationshipDefName(inverseVertex, entityType, inverseAttributeName); String relationshipName = graphHelper.getRelationshipTypeName(inverseVertex, entityType, inverseAttributeName);
ret = getOrCreateRelationship(inverseVertex, vertex, relationshipName, relationshipAttributes); ret = getOrCreateRelationship(inverseVertex, vertex, relationshipName, relationshipAttributes);
...@@ -843,7 +847,7 @@ public class EntityGraphMapper { ...@@ -843,7 +847,7 @@ public class EntityGraphMapper {
ret = updateRelationship(ctx.getCurrentEdge(), entityVertex, attributeVertex, edgeDirection, relationshipAttributes); ret = updateRelationship(ctx.getCurrentEdge(), entityVertex, attributeVertex, edgeDirection, relationshipAttributes);
} else { } else {
String relationshipName = graphHelper.getRelationshipDefName(entityVertex, entityType, attributeName); String relationshipName = graphHelper.getRelationshipTypeName(entityVertex, entityType, attributeName);
AtlasVertex fromVertex; AtlasVertex fromVertex;
AtlasVertex toVertex; AtlasVertex toVertex;
...@@ -1900,8 +1904,7 @@ public class EntityGraphMapper { ...@@ -1900,8 +1904,7 @@ public class EntityGraphMapper {
// move/remove relationship-attributes present in 'attributes' // move/remove relationship-attributes present in 'attributes'
private static void compactAttributes(AtlasEntity entity, AtlasEntityType entityType) { private static void compactAttributes(AtlasEntity entity, AtlasEntityType entityType) {
if (entity != null) { if (entity != null) {
for (AtlasAttribute attribute : entityType.getRelationshipAttributes().values()) { for (String attrName : entityType.getRelationshipAttributes().keySet()) {
String attrName = attribute.getName();
if (entity.hasAttribute(attrName)) { if (entity.hasAttribute(attrName)) {
Object attrValue = entity.getAttribute(attrName); Object attrValue = entity.getAttribute(attrName);
......
...@@ -100,8 +100,8 @@ import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelation ...@@ -100,8 +100,8 @@ import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelation
public class EntityGraphRetriever { public class EntityGraphRetriever {
private static final Logger LOG = LoggerFactory.getLogger(EntityGraphRetriever.class); private static final Logger LOG = LoggerFactory.getLogger(EntityGraphRetriever.class);
private static final String TERM_RELATION_NAME = "AtlasGlossarySemanticAssignment";
private static final String GLOSSARY_TERM_DISPLAY_NAME_ATTR = "AtlasGlossaryTerm.name"; private static final String GLOSSARY_TERM_DISPLAY_NAME_ATTR = "AtlasGlossaryTerm.name";
public static final String TERM_RELATION_NAME = "AtlasGlossarySemanticAssignment";
public static final String NAME = "name"; public static final String NAME = "name";
public static final String DISPLAY_NAME = "displayName"; public static final String DISPLAY_NAME = "displayName";
...@@ -655,7 +655,7 @@ public class EntityGraphRetriever { ...@@ -655,7 +655,7 @@ public class EntityGraphRetriever {
private Object mapVertexToAttribute(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) throws AtlasBaseException { private Object mapVertexToAttribute(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) throws AtlasBaseException {
Object ret = null; Object ret = null;
AtlasType attrType = attribute.getAttributeType(); AtlasType attrType = attribute.getAttributeType();
String edgeLabel = EDGE_LABEL_PREFIX + attribute.getQualifiedName(); String edgeLabel = attribute.getRelationshipEdgeLabel();
boolean isOwnedAttribute = attribute.isOwnedRef(); boolean isOwnedAttribute = attribute.isOwnedRef();
AtlasRelationshipEdgeDirection edgeDirection = attribute.getRelationshipEdgeDirection(); AtlasRelationshipEdgeDirection edgeDirection = attribute.getRelationshipEdgeDirection();
...@@ -997,30 +997,32 @@ public class EntityGraphRetriever { ...@@ -997,30 +997,32 @@ public class EntityGraphRetriever {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, entity.getTypeName()); throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, entity.getTypeName());
} }
for (AtlasAttribute attribute : entityType.getRelationshipAttributes().values()) { for (String attributeName : entityType.getRelationshipAttributes().keySet()) {
Object attrValue = mapVertexToRelationshipAttribute(entityVertex, entityType, attribute); Object attrValue = mapVertexToRelationshipAttribute(entityVertex, entityType, attributeName);
entity.setRelationshipAttribute(attribute.getName(), attrValue); entity.setRelationshipAttribute(attributeName, attrValue);
} }
} }
private Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, AtlasAttribute attribute) throws AtlasBaseException { private Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) throws AtlasBaseException {
Object ret = null; Object ret = null;
AtlasRelationshipDef relationshipDef = graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName()); String relationshipTypeName = graphHelper.getRelationshipTypeName(entityVertex, entityType, attributeName);
AtlasRelationshipType relationshipType = relationshipTypeName != null ? typeRegistry.getRelationshipTypeByName(relationshipTypeName) : null;
if (relationshipDef == null) { if (relationshipType == null) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null"); throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null");
} }
AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef();
AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1(); AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2(); AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType()); AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType());
AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType()); AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType());
AtlasRelationshipEndDef attributeEndDef = null; AtlasRelationshipEndDef attributeEndDef = null;
if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attribute.getName())) { if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attributeName)) {
attributeEndDef = endDef1; attributeEndDef = endDef1;
} else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attribute.getName())) { } else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attributeName)) {
attributeEndDef = endDef2; attributeEndDef = endDef2;
} }
...@@ -1030,12 +1032,12 @@ public class EntityGraphRetriever { ...@@ -1030,12 +1032,12 @@ public class EntityGraphRetriever {
switch (attributeEndDef.getCardinality()) { switch (attributeEndDef.getCardinality()) {
case SINGLE: case SINGLE:
ret = mapRelatedVertexToObjectId(entityVertex, attribute); ret = mapRelatedVertexToObjectId(entityVertex, entityType.getRelationshipAttribute(attributeName, relationshipTypeName));
break; break;
case LIST: case LIST:
case SET: case SET:
ret = mapRelationshipArrayAttribute(entityVertex, attribute); ret = mapRelationshipArrayAttribute(entityVertex, entityType.getRelationshipAttribute(attributeName, relationshipTypeName));
break; break;
} }
......
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