Search in sources :

Example 21 with AtlasRelationshipDef

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

the class GraphHelper method getRelationshipDef.

public AtlasRelationshipDef getRelationshipDef(AtlasVertex entityVertex, AtlasEntityType entityType, String attributeName) {
    List<AtlasRelationshipType> relationshipTypes = entityType.getRelationshipAttributeType(attributeName);
    AtlasRelationshipDef ret = null;
    if (relationshipTypes.size() > 1) {
        Iterator<AtlasEdge> iter = entityVertex.getEdges(AtlasEdgeDirection.IN).iterator();
        while (iter.hasNext() && ret == null) {
            String edgeTypeName = AtlasGraphUtilsV1.getTypeName(iter.next());
            for (AtlasRelationshipType relationType : relationshipTypes) {
                AtlasRelationshipDef relationshipDef = relationType.getRelationshipDef();
                if (StringUtils.equals(edgeTypeName, relationshipDef.getName())) {
                    ret = relationshipDef;
                    break;
                }
            }
        }
        if (ret == null) {
            ret = relationshipTypes.get(0).getRelationshipDef();
        }
    } else {
        // relationshipTypes will have at least one relationshipDef
        ret = relationshipTypes.get(0).getRelationshipDef();
    }
    return ret;
}
Also used : AtlasRelationshipType(org.apache.atlas.type.AtlasRelationshipType) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 22 with AtlasRelationshipDef

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

the class AtlasRelationshipDefStoreV1 method preDeleteByGuid.

@Override
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.preDeleteByGuid({})", guid);
    }
    AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete relationship-def ", (existingDef != null ? existingDef.getName() : guid));
    AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP);
    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    String typeName = AtlasGraphUtilsV1.getProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class);
    if (AtlasGraphUtilsV1.relationshipTypeHasInstanceEdges(typeName)) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName);
    }
    typeDefStore.deleteTypeVertexOutEdges(ret);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.preDeleteByGuid({}): {}", guid, 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)

Example 23 with AtlasRelationshipDef

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

the class AtlasRelationshipDefStoreV1 method getByGuid.

@Override
public AtlasRelationshipDef getByGuid(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.getByGuid({})", guid);
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.getByGuid({}): {}", guid, 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)

Example 24 with AtlasRelationshipDef

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

the class AtlasRelationshipDefStoreV1 method preUpdateCheck.

private void preUpdateCheck(AtlasRelationshipDef newRelationshipDef, AtlasRelationshipType relationshipType, AtlasVertex vertex) throws AtlasBaseException {
    // We will not support an update to endpoints or category key
    AtlasRelationshipDef existingRelationshipDef = toRelationshipDef(vertex);
    preUpdateCheck(newRelationshipDef, existingRelationshipDef);
    // we do allow change to tag propagation and the addition of new attributes.
    AtlasStructDefStoreV1.updateVertexPreUpdate(newRelationshipDef, relationshipType, vertex, typeDefStore);
    setVertexPropertiesFromRelationshipDef(newRelationshipDef, vertex);
}
Also used : AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef)

Example 25 with AtlasRelationshipDef

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

the class AtlasRelationshipDefStoreV1 method preDeleteByName.

@Override
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.preDeleteByName({})", name);
    }
    AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete relationship-def ", name);
    AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP);
    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    if (AtlasGraphUtilsV1.relationshipTypeHasInstanceEdges(name)) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, name);
    }
    typeDefStore.deleteTypeVertexOutEdges(ret);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.preDeleteByName({}): {}", name, 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)

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