Search in sources :

Example 66 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class AtlasClassificationDefStoreV1 method create.

@Override
public AtlasClassificationDef create(AtlasClassificationDef classificationDef, Object preCreateResult) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.create({}, {})", classificationDef, preCreateResult);
    }
    AtlasVertex vertex;
    if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) {
        vertex = preCreate(classificationDef);
    } else {
        vertex = (AtlasVertex) preCreateResult;
    }
    updateVertexAddReferences(classificationDef, vertex);
    AtlasClassificationDef ret = toClassificationDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.create({}, {}): {}", classificationDef, preCreateResult, ret);
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 67 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class AtlasClassificationDefStoreV1 method updateByName.

@Override
public AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.updateByName({}, {})", name, classificationDef);
    }
    validateType(classificationDef);
    AtlasType type = typeRegistry.getType(classificationDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    updateVertexPreUpdate(classificationDef, (AtlasClassificationType) type, vertex);
    updateVertexAddReferences(classificationDef, vertex);
    AtlasClassificationDef ret = toClassificationDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.updateByName({}, {}): {}", name, classificationDef, ret);
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

Example 68 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class AtlasClassificationDefStoreV1 method deleteByGuid.

@Override
public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.deleteByGuid({})", guid);
    }
    AtlasVertex vertex;
    if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) {
        vertex = preDeleteByGuid(guid);
    } else {
        vertex = (AtlasVertex) preDeleteResult;
    }
    typeDefStore.deleteTypeVertex(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.deleteByGuid({})", guid);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 69 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class AtlasClassificationDefStoreV1 method preDeleteByGuid.

@Override
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.preDeleteByGuid({})", guid);
    }
    AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
    String typeName = AtlasGraphUtilsV1.getProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class);
    if (AtlasGraphUtilsV1.typeHasInstanceVertex(typeName)) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName);
    }
    if (ret == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    typeDefStore.deleteTypeVertexOutEdges(ret);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.preDeleteByGuid({}): ret=", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 70 with AtlasVertex

use of org.apache.atlas.repository.graphdb.AtlasVertex in project incubator-atlas by apache.

the class EntityGraphDiscoveryContext method getResolvedEntityVertex.

public AtlasVertex getResolvedEntityVertex(AtlasObjectId objId) {
    AtlasVertex vertex = resolvedIdsByUniqAttribs.get(objId);
    // check also for sub-types; ref={typeName=Asset; guid=abcd} should match {typeName=hive_table; guid=abcd}
    if (vertex == null) {
        final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objId.getTypeName());
        final Set<String> allSubTypes = entityType.getAllSubTypes();
        for (String subType : allSubTypes) {
            AtlasObjectId subTypeObjId = new AtlasObjectId(objId.getGuid(), subType, objId.getUniqueAttributes());
            vertex = resolvedIdsByUniqAttribs.get(subTypeObjId);
            if (vertex != null) {
                resolvedIdsByUniqAttribs.put(objId, vertex);
                break;
            }
        }
    }
    return vertex;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Aggregations

AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)164 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)53 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)26 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)21 ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)16 Id (org.apache.atlas.typesystem.persistence.Id)14 Map (java.util.Map)13 List (java.util.List)12 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)12 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)12 AtlasException (org.apache.atlas.AtlasException)11 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)11 RepositoryException (org.apache.atlas.repository.RepositoryException)11 AtlasGraphQuery (org.apache.atlas.repository.graphdb.AtlasGraphQuery)11 AtlasType (org.apache.atlas.type.AtlasType)11 HashSet (java.util.HashSet)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8