Search in sources :

Example 1 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef 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;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 2 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class EntityGraphRetriever method mapVertexToRelationshipAttribute.

private Object mapVertexToRelationshipAttribute(AtlasVertex entityVertex, AtlasEntityType entityType, AtlasAttribute attribute) throws AtlasBaseException {
    Object ret = null;
    AtlasRelationshipDef relationshipDef = graphHelper.getRelationshipDef(entityVertex, entityType, attribute.getName());
    if (relationshipDef == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, "relationshipDef is null");
    }
    AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
    AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
    AtlasEntityType endDef1Type = typeRegistry.getEntityTypeByName(endDef1.getType());
    AtlasEntityType endDef2Type = typeRegistry.getEntityTypeByName(endDef2.getType());
    AtlasRelationshipEndDef attributeEndDef = null;
    if (endDef1Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef1.getName(), attribute.getName())) {
        attributeEndDef = endDef1;
    } else if (endDef2Type.isTypeOrSuperTypeOf(entityType.getTypeName()) && StringUtils.equals(endDef2.getName(), attribute.getName())) {
        attributeEndDef = endDef2;
    }
    if (attributeEndDef == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_INVALID, relationshipDef.toString());
    }
    switch(attributeEndDef.getCardinality()) {
        case SINGLE:
            ret = mapRelatedVertexToObjectId(entityVertex, attribute);
            break;
        case LIST:
        case SET:
            ret = mapRelationshipArrayAttribute(entityVertex, attribute);
            break;
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 3 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method update.

@Override
public AtlasRelationshipDef update(AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.update({})", relationshipDef);
    }
    validateType(relationshipDef);
    AtlasRelationshipDef ret = StringUtils.isNotBlank(relationshipDef.getGuid()) ? updateByGuid(relationshipDef.getGuid(), relationshipDef) : updateByName(relationshipDef.getName(), relationshipDef);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.update({}): {}", relationshipDef, ret);
    }
    return ret;
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef)

Example 4 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method updateByName.

@Override
public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef);
    }
    AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-def ", name);
    validateType(relationshipDef);
    AtlasType type = typeRegistry.getType(relationshipDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex);
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasType(org.apache.atlas.type.AtlasType)

Example 5 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method toRelationshipDef.

private AtlasRelationshipDef toRelationshipDef(AtlasVertex vertex) throws AtlasBaseException {
    AtlasRelationshipDef ret = null;
    if (vertex != null && typeDefStore.isTypeVertex(vertex, TypeCategory.RELATIONSHIP)) {
        String name = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);
        String description = vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class);
        String version = vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class);
        String end1Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_END1_KEY, String.class);
        String end2Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_END2_KEY, String.class);
        String relationStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, String.class);
        String propagateStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, String.class);
        // set the ends
        AtlasRelationshipEndDef endDef1 = AtlasType.fromJson(end1Str, AtlasRelationshipEndDef.class);
        AtlasRelationshipEndDef endDef2 = AtlasType.fromJson(end2Str, AtlasRelationshipEndDef.class);
        // set the relationship Category
        RelationshipCategory relationshipCategory = null;
        for (RelationshipCategory value : RelationshipCategory.values()) {
            if (value.name().equals(relationStr)) {
                relationshipCategory = value;
            }
        }
        // set the propagateTags
        PropagateTags propagateTags = null;
        for (PropagateTags value : PropagateTags.values()) {
            if (value.name().equals(propagateStr)) {
                propagateTags = value;
            }
        }
        ret = new AtlasRelationshipDef(name, description, version, relationshipCategory, propagateTags, endDef1, endDef2);
        // add in the attributes
        AtlasStructDefStoreV1.toStructDef(vertex, ret, typeDefStore);
    }
    return ret;
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) PropagateTags(org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) RelationshipCategory(org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory)

Aggregations

AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)46 AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)25 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)13 DataProvider (org.testng.annotations.DataProvider)10 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)5 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)4 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 AtlasType (org.apache.atlas.type.AtlasType)4 Test (org.testng.annotations.Test)4 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)3 AtlasRelationshipType (org.apache.atlas.type.AtlasRelationshipType)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 PropagateTags (org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags)2 RelationshipCategory (org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 ArrayList (java.util.ArrayList)1