use of org.apache.atlas.model.instance.AtlasRelationship in project atlas by apache.
the class AtlasRelationshipStoreV1 method create.
@Override
@GraphTransaction
public AtlasRelationship create(AtlasRelationship relationship) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> create({})", relationship);
}
AtlasVertex end1Vertex = getVertexFromEndPoint(relationship.getEnd1());
AtlasVertex end2Vertex = getVertexFromEndPoint(relationship.getEnd2());
validateRelationship(end1Vertex, end2Vertex, relationship.getTypeName(), relationship.getAttributes());
AtlasEdge edge = createRelationship(end1Vertex, end2Vertex, relationship);
AtlasRelationship ret = edge != null ? entityRetriever.mapEdgeToAtlasRelationship(edge) : null;
if (LOG.isDebugEnabled()) {
LOG.debug("<== create({}): {}", relationship, ret);
}
return ret;
}
use of org.apache.atlas.model.instance.AtlasRelationship 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.model.instance.AtlasRelationship in project atlas by apache.
the class EntityGraphRetriever method mapEdgeToAtlasRelationship.
public AtlasRelationship mapEdgeToAtlasRelationship(AtlasEdge edge) throws AtlasBaseException {
AtlasRelationship ret = new AtlasRelationship();
mapSystemAttributes(edge, ret);
mapAttributes(edge, ret);
return ret;
}
use of org.apache.atlas.model.instance.AtlasRelationship in project incubator-atlas by apache.
the class EntityGraphMapper method getOrCreateRelationship.
private AtlasEdge getOrCreateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, AtlasAttribute attribute) throws AtlasBaseException {
AtlasEdge ret = null;
AtlasObjectId end1 = new AtlasObjectId(getIdFromVertex(end1Vertex), AtlasGraphUtilsV1.getTypeName(end1Vertex));
AtlasObjectId end2 = new AtlasObjectId(getIdFromVertex(end2Vertex), AtlasGraphUtilsV1.getTypeName(end2Vertex));
AtlasRelationship relationship = relationshipStore.getOrCreate(new AtlasRelationship(relationshipName, end1, end2));
// return newly created AtlasEdge
// if multiple edges are returned, compare using guid to pick the right one
Iterator<AtlasEdge> outEdges = graphHelper.getOutGoingEdgesByLabel(end1Vertex, relationship.getLabel());
while (outEdges.hasNext()) {
AtlasEdge edge = outEdges.next();
if (getIdFromVertex(end2Vertex).equals(getIdFromVertex(edge.getInVertex()))) {
ret = edge;
break;
}
}
return ret;
}
use of org.apache.atlas.model.instance.AtlasRelationship in project incubator-atlas by apache.
the class AtlasRelationshipStoreV1 method mapEdgeToAtlasRelationship.
private AtlasRelationship mapEdgeToAtlasRelationship(AtlasEdge edge) throws AtlasBaseException {
AtlasRelationship ret = new AtlasRelationship();
mapSystemAttributes(edge, ret);
mapAttributes(edge, ret);
return ret;
}
Aggregations