Search in sources :

Example 1 with AtlasEnumDef

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

the class AtlasTypeDefGraphStore method addToGraphStore.

private AtlasTypesDef addToGraphStore(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);
    List<Object> preCreateStructDefs = new ArrayList<>();
    List<Object> preCreateClassifiDefs = new ArrayList<>();
    List<Object> preCreateEntityDefs = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
        for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
            AtlasEnumDef createdDef = enumDefStore.create(enumDef);
            ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
            ret.getEnumDefs().add(createdDef);
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            preCreateStructDefs.add(structDefStore.preCreate(structDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            preCreateClassifiDefs.add(classifiDefStore.preCreate(classifiDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            preCreateEntityDefs.add(entityDefStore.preCreate(entityDef));
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) {
        int i = 0;
        for (AtlasStructDef structDef : typesDef.getStructDefs()) {
            AtlasStructDef createdDef = structDefStore.create(structDef, preCreateStructDefs.get(i));
            ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
            ret.getStructDefs().add(createdDef);
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
        int i = 0;
        for (AtlasClassificationDef classifiDef : typesDef.getClassificationDefs()) {
            AtlasClassificationDef createdDef = classifiDefStore.create(classifiDef, preCreateClassifiDefs.get(i));
            ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
            ret.getClassificationDefs().add(createdDef);
            i++;
        }
    }
    if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
        int i = 0;
        for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
            AtlasEntityDef createdDef = entityDefStore.create(entityDef, preCreateEntityDefs.get(i));
            ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
            ret.getEntityDefs().add(createdDef);
            i++;
        }
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) ArrayList(java.util.ArrayList) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 2 with AtlasEnumDef

use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.

the class AtlasEnumDefStoreV1 method updateByGuid.

@Override
public AtlasEnumDef updateByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEnumDefStoreV1.updateByGuid({})", guid);
    }
    AtlasEnumDef existingDef = typeRegistry.getEnumDefByGuid(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update enum-def ", (existingDef != null ? existingDef.getName() : guid));
    validateType(enumDef);
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.ENUM);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    typeDefStore.updateTypeVertex(enumDef, vertex);
    toVertex(enumDef, vertex);
    AtlasEnumDef ret = toEnumDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEnumDefStoreV1.updateByGuid({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 3 with AtlasEnumDef

use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.

the class AtlasEnumDefStoreV1 method create.

@Override
public AtlasEnumDef create(AtlasEnumDef enumDef, AtlasVertex preCreateResult) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEnumDefStoreV1.create({}, {})", enumDef, preCreateResult);
    }
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, enumDef), "create enum-def ", enumDef.getName());
    AtlasVertex vertex = (preCreateResult == null) ? preCreate(enumDef) : preCreateResult;
    AtlasEnumDef ret = toEnumDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEntityDefStoreV1.create({}, {}): {}", enumDef, preCreateResult, ret);
    }
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 4 with AtlasEnumDef

use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.

the class AtlasEnumDefStoreV1 method toEnumDef.

private static AtlasEnumDef toEnumDef(AtlasVertex vertex, AtlasEnumDef enumDef, AtlasTypeDefGraphStoreV1 typeDefStore) {
    AtlasEnumDef ret = enumDef != null ? enumDef : new AtlasEnumDef();
    typeDefStore.vertexToTypeDef(vertex, ret);
    List<AtlasEnumElementDef> elements = new ArrayList<>();
    List<String> elemValues = vertex.getProperty(AtlasGraphUtilsV1.getTypeDefPropertyKey(ret), List.class);
    for (String elemValue : elemValues) {
        String elemKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(ret, elemValue);
        String descKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(elemKey, "description");
        Integer ordinal = AtlasGraphUtilsV1.getProperty(vertex, elemKey, Integer.class);
        String desc = AtlasGraphUtilsV1.getProperty(vertex, descKey, String.class);
        elements.add(new AtlasEnumElementDef(elemValue, desc, ordinal));
    }
    ret.setElementDefs(elements);
    return ret;
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) ArrayList(java.util.ArrayList) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 5 with AtlasEnumDef

use of org.apache.atlas.model.typedef.AtlasEnumDef in project atlas by apache.

the class AtlasEnumDefStoreV1 method preDeleteByName.

@Override
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.ENUM);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    AtlasEnumDef existingDef = typeRegistry.getEnumDefByName(name);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete enum-def ", (existingDef != null ? existingDef.getName() : name));
    return vertex;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Aggregations

AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)61 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)33 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)29 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)27 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)24 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)14 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)13 ArrayList (java.util.ArrayList)12 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 Test (org.testng.annotations.Test)11 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)9 HashMap (java.util.HashMap)8 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)5 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 AtlasRelationshipDef (org.apache.atlas.model.typedef.AtlasRelationshipDef)2 AtlasRelationshipEndDef (org.apache.atlas.model.typedef.AtlasRelationshipEndDef)2 TypesDef (org.apache.atlas.typesystem.TypesDef)2 EnumTypeDefinition (org.apache.atlas.typesystem.types.EnumTypeDefinition)2 EnumTypeDefinition (org.apache.atlas.v1.model.typedef.EnumTypeDefinition)2