Search in sources :

Example 21 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasStructDefStoreV1 method addReferencesForAttribute.

private static void addReferencesForAttribute(AtlasVertex vertex, AtlasAttributeDef attributeDef, AtlasTypeDefGraphStoreV1 typeDefStore) throws AtlasBaseException {
    Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName());
    String typeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class);
    for (String referencedTypeName : referencedTypeNames) {
        if (!AtlasTypeUtil.isBuiltInType(referencedTypeName)) {
            AtlasVertex referencedTypeVertex = typeDefStore.findTypeVertexByName(referencedTypeName);
            if (referencedTypeVertex == null) {
                throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, referencedTypeName, typeName, attributeDef.getName());
            }
            String label = AtlasGraphUtilsV1.getEdgeLabel(typeName, attributeDef.getName());
            typeDefStore.getOrCreateEdge(vertex, referencedTypeVertex, label);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 22 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasStructDefStoreV1 method getByName.

@Override
public AtlasStructDef getByName(String name) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasStructDefStoreV1.getByName({})", name);
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, String.class);
    AtlasStructDef ret = toStructDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasStructDefStoreV1.getByName({}): {}", name, ret);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 23 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasStructDefStoreV1 method updateByName.

@Override
public AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasStructDefStoreV1.updateByName({}, {})", name, structDef);
    }
    AtlasStructDef existingDef = typeRegistry.getStructDefByName(name);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update struct-def ", name);
    validateType(structDef);
    AtlasType type = typeRegistry.getType(structDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    AtlasStructDefStoreV1.updateVertexPreUpdate(structDef, (AtlasStructType) type, vertex, typeDefStore);
    AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
    AtlasStructDef ret = toStructDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasStructDefStoreV1.updateByName({}, {}): {}", name, structDef, ret);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasType(org.apache.atlas.type.AtlasType)

Example 24 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasStructDefStoreV1 method create.

@Override
public AtlasStructDef create(AtlasStructDef structDef, AtlasVertex preCreateResult) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasStructDefStoreV1.create({}, {})", structDef, preCreateResult);
    }
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, structDef), "create struct-def ", structDef.getName());
    if (CollectionUtils.isEmpty(structDef.getAttributeDefs())) {
        throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Missing attributes for structdef");
    }
    AtlasVertex vertex = (preCreateResult == null) ? preCreate(structDef) : preCreateResult;
    AtlasStructDefStoreV1.updateVertexAddReferences(structDef, vertex, typeDefStore);
    AtlasStructDef ret = toStructDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasStructDefStoreV1.create({}, {}): {}", structDef, preCreateResult, ret);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest)

Example 25 with AtlasBaseException

use of org.apache.atlas.exception.AtlasBaseException in project atlas by apache.

the class AtlasStructDefStoreV1 method preCreate.

@Override
public AtlasVertex preCreate(AtlasStructDef structDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasStructDefStoreV1.preCreate({})", structDef);
    }
    validateType(structDef);
    AtlasType type = typeRegistry.getType(structDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name());
    }
    AtlasVertex ret = typeDefStore.findTypeVertexByName(structDef.getName());
    if (ret != null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, structDef.getName());
    }
    ret = typeDefStore.createTypeVertex(structDef);
    AtlasStructDefStoreV1.updateVertexPreCreate(structDef, (AtlasStructType) type, ret, typeDefStore);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasStructDefStoreV1.preCreate({}): {}", structDef, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

Aggregations

AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)437 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)129 Test (org.testng.annotations.Test)60 ArrayList (java.util.ArrayList)59 AtlasType (org.apache.atlas.type.AtlasType)51 AtlasException (org.apache.atlas.AtlasException)50 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)48 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)45 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)43 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)36 HashMap (java.util.HashMap)34 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)31 Produces (javax.ws.rs.Produces)29 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)29 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)29 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)26 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)26 Path (javax.ws.rs.Path)25 Map (java.util.Map)24