Search in sources :

Example 1 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef 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 AtlasEntityDef

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

the class TypeAttributeDifferenceTest method bothSame_DifferenceIsEmptyList.

@Test
public void bothSame_DifferenceIsEmptyList() throws Exception {
    AtlasEntityDef existing = getAtlasEntityDefWithAttributes("name", "qualifiedName");
    AtlasEntityDef incoming = getAtlasEntityDefWithAttributes("name", "qualifiedName");
    List<AtlasStructDef.AtlasAttributeDef> expectedAttributes = getAtlasAttributeDefs();
    List<AtlasStructDef.AtlasAttributeDef> actualAttributes = invokeGetAttributesAbsentInExisting(existing, incoming);
    Assert.assertEquals(actualAttributes, expectedAttributes);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) Test(org.testng.annotations.Test)

Example 3 with AtlasEntityDef

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

the class TypeAttributeDifferenceTest method different_ReturnsDifference.

@Test
public void different_ReturnsDifference() throws Exception {
    AtlasEntityDef existing = getAtlasEntityDefWithAttributes("name");
    AtlasEntityDef incoming = getAtlasEntityDefWithAttributes("name", "qualifiedName");
    List<AtlasStructDef.AtlasAttributeDef> expectedAttributes = getAtlasAttributeDefs("qualifiedName");
    List<AtlasStructDef.AtlasAttributeDef> actualAttributes = invokeGetAttributesAbsentInExisting(existing, incoming);
    Assert.assertEquals(actualAttributes, expectedAttributes);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) Test(org.testng.annotations.Test)

Example 4 with AtlasEntityDef

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

the class AtlasEntityDefStoreV1 method create.

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

Example 5 with AtlasEntityDef

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

the class AtlasEntityDefStoreV1 method getByName.

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

Aggregations

AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)141 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)55 Test (org.testng.annotations.Test)51 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)40 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)37 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)35 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)31 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)31 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)30 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)21 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)14 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)13 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)13 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)13 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)9 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)8