Search in sources :

Example 76 with AtlasType

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

the class EntityGraphMapper method createInverseReferenceUsingRelationship.

private AtlasEdge createInverseReferenceUsingRelationship(AtlasAttribute inverseAttribute, AtlasEdge edge) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createInverseReferenceUsingRelationship()");
    }
    String inverseAttributeName = inverseAttribute.getName();
    AtlasType inverseAttributeType = inverseAttribute.getDefinedInType();
    AtlasVertex inverseVertex = edge.getInVertex();
    AtlasVertex vertex = edge.getOutVertex();
    AtlasEdge ret;
    if (inverseAttributeType instanceof AtlasEntityType) {
        AtlasEntityType entityType = (AtlasEntityType) inverseAttributeType;
        if (entityType.hasRelationshipAttribute(inverseAttributeName)) {
            String relationshipName = graphHelper.getRelationshipDefName(inverseVertex, entityType, inverseAttributeName);
            ret = getOrCreateRelationship(inverseVertex, vertex, relationshipName, inverseAttribute);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No RelationshipDef defined between {} and {} on attribute: {}", inverseAttributeType, AtlasGraphUtilsV1.getTypeName(vertex), inverseAttributeName);
            }
            // if no RelationshipDef found, use legacy way to create edges
            ret = createInverseReference(inverseAttribute, (AtlasStructType) inverseAttributeType, inverseVertex, vertex);
        }
    } else {
        // inverseAttribute not of type AtlasEntityType, use legacy way to create edges
        ret = createInverseReference(inverseAttribute, (AtlasStructType) inverseAttributeType, inverseVertex, vertex);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== createInverseReferenceUsingRelationship()");
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 77 with AtlasType

use of org.apache.atlas.type.AtlasType 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 78 with AtlasType

use of org.apache.atlas.type.AtlasType 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 79 with AtlasType

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

the class AtlasRelationshipDefStoreV1 method preCreate.

@Override
public AtlasVertex preCreate(AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.preCreate({})", 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 relationshipDefVertex = typeDefStore.findTypeVertexByName(relationshipDef.getName());
    if (relationshipDefVertex != null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, relationshipDef.getName());
    }
    relationshipDefVertex = typeDefStore.createTypeVertex(relationshipDef);
    updateVertexPreCreate(relationshipDef, (AtlasRelationshipType) type, relationshipDefVertex);
    final AtlasRelationshipEndDef endDef1 = relationshipDef.getEndDef1();
    final AtlasRelationshipEndDef endDef2 = relationshipDef.getEndDef2();
    final String type1 = endDef1.getType();
    final String type2 = endDef2.getType();
    final String name1 = endDef1.getName();
    final String name2 = endDef2.getName();
    final AtlasVertex end1TypeVertex = typeDefStore.findTypeVertexByName(type1);
    final AtlasVertex end2TypeVertex = typeDefStore.findTypeVertexByName(type2);
    if (end1TypeVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type1);
    }
    if (end2TypeVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIPDEF_END_TYPE_NAME_NOT_FOUND, relationshipDef.getName(), type2);
    }
    // create an edge between the relationshipDef and each of the entityDef vertices.
    AtlasEdge edge1 = typeDefStore.getOrCreateEdge(relationshipDefVertex, end1TypeVertex, AtlasGraphUtilsV1.RELATIONSHIPTYPE_EDGE_LABEL);
    if (type1.equals(type2) && name1.equals(name2)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("AtlasRelationshipDefStoreV1.preCreate({}): created relationshipDef vertex {}," + " and one edge as {}, because end1 and end2 have the same type and name", relationshipDef, relationshipDefVertex, edge1);
        }
    } else {
        AtlasEdge edge2 = typeDefStore.getOrCreateEdge(relationshipDefVertex, end2TypeVertex, AtlasGraphUtilsV1.RELATIONSHIPTYPE_EDGE_LABEL);
        if (LOG.isDebugEnabled()) {
            LOG.debug("AtlasRelationshipDefStoreV1.preCreate({}): created relationshipDef vertex {}," + " edge1 as {}, edge2 as {} ", relationshipDef, relationshipDefVertex, edge1, edge2);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.preCreate({}): {}", relationshipDef, relationshipDefVertex);
    }
    return relationshipDefVertex;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef)

Example 80 with AtlasType

use of org.apache.atlas.type.AtlasType 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)

Aggregations

AtlasType (org.apache.atlas.type.AtlasType)95 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)51 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)33 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)23 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)17 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 AtlasStructType (org.apache.atlas.type.AtlasStructType)16 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)15 AtlasMapType (org.apache.atlas.type.AtlasMapType)13 ArrayList (java.util.ArrayList)11 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 HashMap (java.util.HashMap)8 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)8 Map (java.util.Map)7 List (java.util.List)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)4