use of org.apache.atlas.model.instance.AtlasRelationship in project incubator-atlas by apache.
the class AtlasRelationshipStoreV1 method createRelationship.
private AtlasRelationship createRelationship(AtlasRelationship relationship, AtlasVertex end1Vertex, AtlasVertex end2Vertex) throws AtlasBaseException {
AtlasRelationship ret;
try {
AtlasEdge relationshipEdge = getRelationshipEdge(end1Vertex, end2Vertex, relationship);
if (relationshipEdge == null) {
relationshipEdge = createRelationshipEdge(end1Vertex, end2Vertex, relationship);
AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
if (MapUtils.isNotEmpty(relationType.getAllAttributes())) {
for (AtlasAttribute attr : relationType.getAllAttributes().values()) {
String attrName = attr.getName();
String attrVertexProperty = attr.getVertexPropertyName();
Object attrValue = relationship.getAttribute(attrName);
AtlasGraphUtilsV1.setProperty(relationshipEdge, attrVertexProperty, attrValue);
}
}
ret = mapEdgeToAtlasRelationship(relationshipEdge);
} else {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), relationship.getEnd1().getGuid(), relationship.getEnd2().getGuid());
}
} catch (RepositoryException e) {
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
}
return ret;
}
use of org.apache.atlas.model.instance.AtlasRelationship in project incubator-atlas by apache.
the class AtlasRelationshipStoreV1 method getById.
@Override
@GraphTransaction
public AtlasRelationship getById(String guid) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> getById({})", guid);
}
AtlasRelationship ret;
try {
AtlasEdge edge = graphHelper.getEdgeForGUID(guid);
ret = mapEdgeToAtlasRelationship(edge);
} catch (EntityNotFoundException ex) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, guid);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== getById({}): {}", guid, ret);
}
return ret;
}
use of org.apache.atlas.model.instance.AtlasRelationship in project atlas by apache.
the class EntityGraphRetriever method mapVertexToRelatedObjectId.
private AtlasRelatedObjectId mapVertexToRelatedObjectId(AtlasVertex entityVertex, AtlasEdge edge) throws AtlasBaseException {
AtlasRelatedObjectId ret = null;
if (GraphHelper.elementExists(edge)) {
AtlasVertex referenceVertex = edge.getInVertex();
if (StringUtils.equals(getIdFromVertex(referenceVertex), getIdFromVertex(entityVertex))) {
referenceVertex = edge.getOutVertex();
}
if (referenceVertex != null) {
String entityTypeName = getTypeName(referenceVertex);
String entityGuid = getGuid(referenceVertex);
AtlasRelationship relationship = mapEdgeToAtlasRelationship(edge);
ret = new AtlasRelatedObjectId(entityGuid, entityTypeName, relationship.getGuid(), new AtlasStruct(relationship.getTypeName(), relationship.getAttributes()));
Object displayText = getDisplayText(referenceVertex, entityTypeName);
if (displayText != null) {
ret.setDisplayText(displayText.toString());
}
}
}
return ret;
}
use of org.apache.atlas.model.instance.AtlasRelationship in project atlas by apache.
the class AtlasRelationshipStoreV1 method getOrCreate.
@Override
public AtlasRelationship getOrCreate(AtlasRelationship relationship) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> getOrCreate({})", relationship);
}
validateRelationship(relationship);
AtlasVertex end1Vertex = getVertexFromEndPoint(relationship.getEnd1());
AtlasVertex end2Vertex = getVertexFromEndPoint(relationship.getEnd2());
AtlasRelationship ret = null;
// check if relationship exists
AtlasEdge relationshipEdge = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName());
if (relationshipEdge == null) {
validateRelationship(relationship);
relationshipEdge = createRelationship(end1Vertex, end2Vertex, relationship);
}
if (relationshipEdge != null) {
ret = entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== getOrCreate({}): {}", relationship, ret);
}
return ret;
}
use of org.apache.atlas.model.instance.AtlasRelationship in project atlas by apache.
the class AtlasRelationshipStoreV1 method update.
@Override
@GraphTransaction
public AtlasRelationship update(AtlasRelationship relationship) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> update({})", relationship);
}
String guid = relationship.getGuid();
if (StringUtils.isEmpty(guid)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, guid);
}
AtlasEdge edge = graphHelper.getEdgeForGUID(guid);
String edgeType = AtlasGraphUtilsV1.getTypeName(edge);
AtlasVertex end1Vertex = edge.getOutVertex();
AtlasVertex end2Vertex = edge.getInVertex();
// update shouldn't change endType
if (StringUtils.isNotEmpty(relationship.getTypeName()) && !StringUtils.equalsIgnoreCase(edgeType, relationship.getTypeName())) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_UPDATE_TYPE_CHANGE_NOT_ALLOWED, guid, edgeType, relationship.getTypeName());
}
// update shouldn't change ends
if (relationship.getEnd1() != null) {
String updatedEnd1Guid = relationship.getEnd1().getGuid();
if (updatedEnd1Guid == null) {
AtlasVertex updatedEnd1Vertex = getVertexFromEndPoint(relationship.getEnd1());
updatedEnd1Guid = updatedEnd1Vertex == null ? null : AtlasGraphUtilsV1.getIdFromVertex(updatedEnd1Vertex);
}
if (updatedEnd1Guid != null) {
String end1Guid = AtlasGraphUtilsV1.getIdFromVertex(end1Vertex);
if (!StringUtils.equalsIgnoreCase(relationship.getEnd1().getGuid(), end1Guid)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_UPDATE_END_CHANGE_NOT_ALLOWED, edgeType, guid, end1Guid, relationship.getEnd1().getGuid());
}
}
}
// update shouldn't change ends
if (relationship.getEnd2() != null) {
String updatedEnd2Guid = relationship.getEnd2().getGuid();
if (updatedEnd2Guid == null) {
AtlasVertex updatedEnd2Vertex = getVertexFromEndPoint(relationship.getEnd2());
updatedEnd2Guid = updatedEnd2Vertex == null ? null : AtlasGraphUtilsV1.getIdFromVertex(updatedEnd2Vertex);
}
if (updatedEnd2Guid != null) {
String end2Guid = AtlasGraphUtilsV1.getIdFromVertex(end2Vertex);
if (!StringUtils.equalsIgnoreCase(relationship.getEnd2().getGuid(), end2Guid)) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_UPDATE_END_CHANGE_NOT_ALLOWED, AtlasGraphUtilsV1.getTypeName(edge), guid, end2Guid, relationship.getEnd2().getGuid());
}
}
}
validateRelationship(end1Vertex, end2Vertex, edgeType, relationship.getAttributes());
AtlasRelationship ret = updateRelationship(edge, relationship);
if (LOG.isDebugEnabled()) {
LOG.debug("<== update({}): {}", relationship, ret);
}
return ret;
}
Aggregations