Search in sources :

Example 11 with AtlasRelationshipType

use of org.apache.atlas.type.AtlasRelationshipType in project atlas by apache.

the class AtlasRelationshipStoreV1 method validateRelationship.

private void validateRelationship(AtlasRelationship relationship) throws AtlasBaseException {
    if (relationship == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "AtlasRelationship is null");
    }
    String relationshipName = relationship.getTypeName();
    String end1TypeName = getTypeNameFromObjectId(relationship.getEnd1());
    String end2TypeName = getTypeNameFromObjectId(relationship.getEnd2());
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);
    if (relationshipType == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
    }
    if (relationship.getEnd1() == null || relationship.getEnd2() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "end1/end2 is null");
    }
    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);
    }
    validateEnds(relationship);
    validateAndNormalize(relationship);
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 12 with AtlasRelationshipType

use of org.apache.atlas.type.AtlasRelationshipType in project atlas by apache.

the class AtlasRelationshipStoreV1 method createRelationship.

private AtlasEdge createRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException {
    AtlasEdge ret = null;
    try {
        ret = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName());
        if (ret == null) {
            ret = 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(ret, attrVertexProperty, attrValue);
                }
            }
        } else {
            throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), AtlasGraphUtilsV1.getIdFromVertex(end1Vertex), AtlasGraphUtilsV1.getIdFromVertex(end2Vertex));
        }
    } catch (RepositoryException e) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) RepositoryException(org.apache.atlas.repository.RepositoryException) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 13 with AtlasRelationshipType

use of org.apache.atlas.type.AtlasRelationshipType in project incubator-atlas by apache.

the class AtlasRelationshipStoreV1 method validateAndNormalize.

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);
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList)

Example 14 with AtlasRelationshipType

use of org.apache.atlas.type.AtlasRelationshipType in project incubator-atlas by apache.

the class AtlasRelationshipStoreV1 method mapAttributes.

private void mapAttributes(AtlasEdge edge, AtlasRelationship relationship) throws AtlasBaseException {
    AtlasType objType = typeRegistry.getType(relationship.getTypeName());
    if (!(objType instanceof AtlasRelationshipType)) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, relationship.getTypeName());
    }
    AtlasRelationshipType relationshipType = (AtlasRelationshipType) objType;
    for (AtlasAttribute attribute : relationshipType.getAllAttributes().values()) {
        // mapping only primitive attributes
        Object attrValue = entityRetriever.mapVertexToPrimitive(edge, attribute.getQualifiedName(), attribute.getAttributeDef());
        relationship.setAttribute(attribute.getName(), attrValue);
    }
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType)

Example 15 with AtlasRelationshipType

use of org.apache.atlas.type.AtlasRelationshipType in project incubator-atlas by apache.

the class AtlasRelationshipStoreV1 method validateRelationship.

private void validateRelationship(AtlasRelationship relationship) throws AtlasBaseException {
    if (relationship == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "AtlasRelationship is null");
    }
    String relationshipName = relationship.getTypeName();
    String end1TypeName = getTypeNameFromObjectId(relationship.getEnd1());
    String end2TypeName = getTypeNameFromObjectId(relationship.getEnd2());
    AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);
    if (relationshipType == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
    }
    if (relationship.getEnd1() == null || relationship.getEnd2() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "end1/end2 is null");
    }
    if (!relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName) && !relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end1TypeName)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName, relationshipType.getEnd2Type().getTypeName(), end1TypeName);
    }
    if (!relationshipType.getEnd2Type().isTypeOrSuperTypeOf(end2TypeName) && !relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end2TypeName)) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_RELATIONSHIP_END_TYPE, relationshipName, relationshipType.getEnd1Type().getTypeName(), end2TypeName);
    }
    validateEnd(relationship.getEnd1());
    validateEnd(relationship.getEnd2());
    validateAndNormalize(relationship);
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Aggregations

AtlasRelationshipType (org.apache.atlas.type.AtlasRelationshipType)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)9 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)8 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)4 ArrayList (java.util.ArrayList)3 AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)3 AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)3 AtlasRelationship (org.apache.atlas.model.instance.AtlasRelationship)2 RepositoryException (org.apache.atlas.repository.RepositoryException)2 AtlasType (org.apache.atlas.type.AtlasType)2 PropagateTags (org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags)1 GraphHelper.getPropagateTags (org.apache.atlas.repository.graph.GraphHelper.getPropagateTags)1 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)1