use of org.apache.atlas.type.AtlasRelationshipType in project atlas by apache.
the class AtlasRelationshipStoreV1 method updateRelationship.
private AtlasRelationship updateRelationship(AtlasEdge relationshipEdge, AtlasRelationship relationship) throws AtlasBaseException {
AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
updateTagPropagations(relationshipEdge, relationship.getPropagateTags());
AtlasGraphUtilsV1.setProperty(relationshipEdge, Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, relationship.getPropagateTags().name());
if (MapUtils.isNotEmpty(relationType.getAllAttributes())) {
for (AtlasAttribute attr : relationType.getAllAttributes().values()) {
String attrName = attr.getName();
String attrVertexProperty = attr.getVertexPropertyName();
if (relationship.hasAttribute(attrName)) {
AtlasGraphUtilsV1.setProperty(relationshipEdge, attrVertexProperty, relationship.getAttribute(attrName));
}
}
}
return entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge);
}
use of org.apache.atlas.type.AtlasRelationshipType in project atlas by apache.
the class AtlasRelationshipStoreV1 method getRelationshipTagPropagation.
private PropagateTags getRelationshipTagPropagation(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) {
AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1();
AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2();
Set<String> fromVertexTypes = getTypeAndAllSuperTypes(getTypeName(fromVertex));
Set<String> toVertexTypes = getTypeAndAllSuperTypes(getTypeName(toVertex));
PropagateTags ret = relationshipType.getRelationshipDef().getPropagateTags();
// swap the tagPropagation property for such cases.
if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) {
if (ret == ONE_TO_TWO) {
ret = TWO_TO_ONE;
} else if (ret == TWO_TO_ONE) {
ret = ONE_TO_TWO;
}
}
return ret;
}
use of org.apache.atlas.type.AtlasRelationshipType in project atlas by apache.
the class AtlasRelationshipStoreV1 method validateRelationship.
private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, Map<String, Object> attributes) throws AtlasBaseException {
String end1TypeName = AtlasGraphUtilsV1.getTypeName(end1Vertex);
String end2TypeName = AtlasGraphUtilsV1.getTypeName(end2Vertex);
AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);
if (relationshipType == null) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
}
boolean validEndTypes = false;
if (relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName)) {
validEndTypes = relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end2TypeName);
} else if (relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end1TypeName)) {
validEndTypes = relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end2TypeName);
}
if (!validEndTypes) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName, relationshipType.getEnd2Type().getTypeName(), end1TypeName);
}
List<String> messages = new ArrayList<>();
AtlasRelationship relationship = new AtlasRelationship(relationshipName, attributes);
relationshipType.validateValue(relationship, relationshipName, messages);
if (!messages.isEmpty()) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages);
}
relationshipType.getNormalizedValue(relationship);
}
use of org.apache.atlas.type.AtlasRelationshipType in project atlas by apache.
the class AtlasRelationshipStoreV1 method getRelationshipEdgeLabel.
private String getRelationshipEdgeLabel(String typeName, String relationshipTypeName) {
AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipTypeName);
AtlasRelationshipDef relationshipDef = relationshipType.getRelationshipDef();
AtlasEntityType end1Type = relationshipType.getEnd1Type();
AtlasEntityType end2Type = relationshipType.getEnd2Type();
Set<String> vertexTypes = getTypeAndAllSuperTypes(typeName);
AtlasAttribute attribute = null;
if (vertexTypes.contains(end1Type.getTypeName())) {
String attributeName = relationshipDef.getEndDef1().getName();
attribute = (attributeName != null) ? end1Type.getAttribute(attributeName) : null;
} else if (vertexTypes.contains(end2Type.getTypeName())) {
String attributeName = relationshipDef.getEndDef2().getName();
attribute = (attributeName != null) ? end2Type.getAttribute(attributeName) : null;
}
return (attribute != null) ? attribute.getRelationshipEdgeLabel() : null;
}
use of org.apache.atlas.type.AtlasRelationshipType in project incubator-atlas by apache.
the class AtlasRelationshipStoreV1 method getRelationshipEdgeLabel.
private String getRelationshipEdgeLabel(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) {
AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
String ret = relationshipType.getRelationshipDef().getRelationshipLabel();
AtlasRelationshipEndDef endDef1 = relationshipType.getRelationshipDef().getEndDef1();
AtlasRelationshipEndDef endDef2 = relationshipType.getRelationshipDef().getEndDef2();
Set<String> fromVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV1.getTypeName(fromVertex));
Set<String> toVertexTypes = getTypeAndAllSuperTypes(AtlasGraphUtilsV1.getTypeName(toVertex));
AtlasAttribute attribute = null;
// e.g. [hive_process -> hive_table] -> [Process -> DataSet]
if (fromVertexTypes.contains(endDef1.getType()) && toVertexTypes.contains(endDef2.getType())) {
String attributeName = endDef1.getName();
attribute = relationshipType.getEnd1Type().getRelationshipAttribute(attributeName);
} else if (fromVertexTypes.contains(endDef2.getType()) && toVertexTypes.contains(endDef1.getType())) {
String attributeName = endDef2.getName();
attribute = relationshipType.getEnd2Type().getRelationshipAttribute(attributeName);
}
if (attribute != null) {
ret = attribute.getRelationshipEdgeLabel();
}
return ret;
}
Aggregations