Search in sources :

Example 41 with AtlasClassificationDef

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

the class AtlasTypeDefGraphStore method updateGraphStore.

private AtlasTypesDef updateGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
    AtlasTypesDef ret = new AtlasTypesDef();
    AtlasEnumDefStore enumDefStore = getEnumDefStore(ttr);
    AtlasStructDefStore structDefStore = getStructDefStore(ttr);
    AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr);
    AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr);
    if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
        for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
            ret.getEnumDefs().add(enumDefStore.update(enumDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            ret.getStructDefs().add(structDefStore.update(structDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            ret.getClassificationDefs().add(classifiDefStore.update(classifiDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            ret.getEntityDefs().add(entityDefStore.update(entityDef));
        }
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 42 with AtlasClassificationDef

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

the class AtlasTypeDefGraphStore method createUpdateTypesDef.

@Override
@GraphTransaction
public AtlasTypesDef createUpdateTypesDef(AtlasTypesDef typesToCreate, AtlasTypesDef typesToUpdate) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasTypeDefGraphStore.createUpdateTypesDef({}, {})", typesToCreate, typesToUpdate);
    }
    AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
    if (!typesToUpdate.isEmpty()) {
        ttr.updateTypesWithNoRefResolve(typesToUpdate);
    }
    // Translate any NOT FOUND errors to BAD REQUEST
    tryTypeCreation(typesToCreate, ttr);
    AtlasTypesDef ret = addToGraphStore(typesToCreate, ttr);
    if (!typesToUpdate.isEmpty()) {
        AtlasTypesDef updatedTypes = updateGraphStore(typesToUpdate, ttr);
        if (CollectionUtils.isNotEmpty(updatedTypes.getEnumDefs())) {
            for (AtlasEnumDef enumDef : updatedTypes.getEnumDefs()) {
                ret.getEnumDefs().add(enumDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getStructDefs())) {
            for (AtlasStructDef structDef : updatedTypes.getStructDefs()) {
                ret.getStructDefs().add(structDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getClassificationDefs())) {
            for (AtlasClassificationDef classificationDef : updatedTypes.getClassificationDefs()) {
                ret.getClassificationDefs().add(classificationDef);
            }
        }
        if (CollectionUtils.isNotEmpty(updatedTypes.getEntityDefs())) {
            for (AtlasEntityDef entityDef : updatedTypes.getEntityDefs()) {
                ret.getEntityDefs().add(entityDef);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasTypeDefGraphStore.createUpdateTypesDef({}, {}): {}", typesToCreate, typesToUpdate, ret);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 43 with AtlasClassificationDef

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

the class AtlasClassificationDefStoreV1 method getByGuid.

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

Example 44 with AtlasClassificationDef

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

the class AtlasClassificationDefStoreV1 method updateByGuid.

@Override
public AtlasClassificationDef updateByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.updateByGuid({})", guid);
    }
    validateType(classificationDef);
    AtlasType type = typeRegistry.getTypeByGuid(guid);
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    updateVertexPreUpdate(classificationDef, (AtlasClassificationType) type, vertex);
    updateVertexAddReferences(classificationDef, vertex);
    AtlasClassificationDef ret = toClassificationDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.updateByGuid({}): {}", guid, 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 45 with AtlasClassificationDef

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

the class AtlasClassificationDefStoreV1 method toClassificationDef.

private AtlasClassificationDef toClassificationDef(AtlasVertex vertex) throws AtlasBaseException {
    AtlasClassificationDef ret = null;
    if (vertex != null && typeDefStore.isTypeVertex(vertex, TypeCategory.TRAIT)) {
        ret = new AtlasClassificationDef();
        AtlasStructDefStoreV1.toStructDef(vertex, ret, typeDefStore);
        ret.setSuperTypes(typeDefStore.getSuperTypeNames(vertex));
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef)

Aggregations

AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)45 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)24 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)22 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)21 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)18 Test (org.testng.annotations.Test)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 ArrayList (java.util.ArrayList)8 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)8 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)5 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 HashMap (java.util.HashMap)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)3 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2