Java Code Examples for org.apache.atlas.AtlasErrorCode#RELATIONSHIP_GUID_NOT_FOUND

The following examples show how to use org.apache.atlas.AtlasErrorCode#RELATIONSHIP_GUID_NOT_FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasRelationshipStoreV2.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalize(AtlasRelationship relationship) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();

    if (! AtlasTypeUtil.isValidGuid(relationship.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, relationship.getGuid());
    }

    AtlasRelationshipType type = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.RELATIONSHIP.name(), relationship.getTypeName());
    }

    type.validateValue(relationship, relationship.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages);
    }

    type.getNormalizedValue(relationship);
}
 
Example 2
Source File: AtlasRelationshipStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: AtlasRelationshipStoreV1.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private void validateAndNormalize(AtlasRelationship relationship) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();

    if (! AtlasTypeUtil.isValidGuid(relationship.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, relationship.getGuid());
    }

    AtlasRelationshipType type = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());

    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.RELATIONSHIP.name(), relationship.getTypeName());
    }

    type.validateValue(relationship, relationship.getTypeName(), messages);

    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages);
    }

    type.getNormalizedValue(relationship);
}
 
Example 4
Source File: GraphHelper.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasEdge getEdgeForGUID(String guid) throws AtlasBaseException {
    AtlasEdge ret;

    try {
        ret = findEdge(Constants.RELATIONSHIP_GUID_PROPERTY_KEY, guid);
    } catch (EntityNotFoundException e) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, guid);
    }

    return ret;
}
 
Example 5
Source File: AtlasRelationshipStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public void deleteById(String guid, boolean forceDelete) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> deleteById({}, {})", guid, forceDelete);
    }

    if (StringUtils.isEmpty(guid)) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, " empty/null guid");
    }

    AtlasEdge edge = graphHelper.getEdgeForGUID(guid);


    if (edge == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, guid);
    }

    if (getState(edge) == DELETED) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_DELETED, guid);
    }

    String            relationShipType = graphHelper.getTypeName(edge);
    AtlasEntityHeader end1Entity       = entityRetriever.toAtlasEntityHeaderWithClassifications(edge.getOutVertex());
    AtlasEntityHeader end2Entity       = entityRetriever.toAtlasEntityHeaderWithClassifications(edge.getInVertex());

    AtlasAuthorizationUtils.verifyAccess(new AtlasRelationshipAccessRequest(typeRegistry,AtlasPrivilege.RELATIONSHIP_REMOVE, relationShipType, end1Entity, end2Entity ));


    deleteDelegate.getHandler().deleteRelationships(Collections.singleton(edge), forceDelete);

    sendNotifications(entityRetriever.mapEdgeToAtlasRelationship(edge), OperationType.RELATIONSHIP_DELETE);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== deleteById({}): {}", guid);
    }
}
 
Example 6
Source File: AtlasRelationshipStoreV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
@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   = AtlasGraphUtilsV2.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 : AtlasGraphUtilsV2.getIdFromVertex(updatedEnd1Vertex);
        }

        if (updatedEnd1Guid != null) {
            String end1Guid = AtlasGraphUtilsV2.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 : AtlasGraphUtilsV2.getIdFromVertex(updatedEnd2Vertex);
        }

        if (updatedEnd2Guid != null) {
            String end2Guid = AtlasGraphUtilsV2.getIdFromVertex(end2Vertex);

            if (!StringUtils.equalsIgnoreCase(relationship.getEnd2().getGuid(), end2Guid)) {
                throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_UPDATE_END_CHANGE_NOT_ALLOWED, AtlasGraphUtilsV2.getTypeName(edge), guid, end2Guid, relationship.getEnd2().getGuid());
            }
        }
    }

    boolean relationshipTypeNotExists = false;
    if (StringUtils.isEmpty(relationship.getTypeName())) {
        relationship.setTypeName(edgeType);
        relationshipTypeNotExists = true;
    }
    validateRelationship(end1Vertex, end2Vertex, relationship);

    if (relationshipTypeNotExists) {
        relationship.setTypeName(null);
    }

    AtlasRelationship ret = updateRelationship(edge, relationship);
    sendNotifications(ret, OperationType.RELATIONSHIP_UPDATE);

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== update({}): {}", relationship, ret);
    }

    return ret;
}