Search in sources :

Example 36 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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);
    }
    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) AtlasType(org.apache.atlas.type.AtlasType)

Example 37 with AtlasRelationshipDef

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

the class AtlasRelationshipDefStoreV1 method updateByGuid.

@Override
public AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.updateByGuid({})", guid);
    }
    validateType(relationshipDef);
    AtlasType type = typeRegistry.getTypeByGuid(guid);
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex);
    // updates should not effect the edges between the types as we do not allow updates that change the endpoints.
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.updateByGuid({}): {}", 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) AtlasType(org.apache.atlas.type.AtlasType)

Example 38 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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 39 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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 40 with AtlasRelationshipDef

use of org.apache.atlas.model.typedef.AtlasRelationshipDef in project incubator-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)

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