Search in sources :

Example 16 with AtlasEntityDef

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

the class AtlasEntityDefStoreV1 method toEntityDef.

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

Example 17 with AtlasEntityDef

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

Example 18 with AtlasEntityDef

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

the class RestUtilsTest method convertV2toV1.

private List<HierarchicalTypeDefinition<ClassType>> convertV2toV1(List<AtlasEntityDef> toConvert) throws AtlasBaseException {
    AtlasTypeRegistry reg = createRegistry(toConvert);
    List<HierarchicalTypeDefinition<ClassType>> result = new ArrayList<>(toConvert.size());
    for (int i = 0; i < toConvert.size(); i++) {
        AtlasEntityDef entityDef = toConvert.get(i);
        AtlasEntityType entity = reg.getEntityTypeByName(entityDef.getName());
        HierarchicalTypeDefinition<ClassType> converted = TypeConverterUtil.toTypesDef(entity, reg).classTypesAsJavaList().get(0);
        result.add(converted);
    }
    return result;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 19 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 20 with AtlasEntityDef

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

the class AtlasTypeDefGraphStoreTest method testCreateWithInvalidSuperTypes.

@Test(dependsOnMethods = "testGet")
public void testCreateWithInvalidSuperTypes() {
    AtlasTypesDef typesDef;
    // Test Classification with supertype
    AtlasClassificationDef classificationDef = TestUtilsV2.getClassificationWithInvalidSuperType();
    typesDef = new AtlasTypesDef();
    typesDef.getClassificationDefs().add(classificationDef);
    try {
        AtlasTypesDef created = typeDefStore.createTypesDef(typesDef);
        fail("Classification creation with invalid supertype should've failed");
    } catch (AtlasBaseException e) {
        typesDef = null;
    }
    // Test Entity with supertype
    AtlasEntityDef entityDef = TestUtilsV2.getEntityWithInvalidSuperType();
    typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(entityDef);
    try {
        AtlasTypesDef created = typeDefStore.createTypesDef(typesDef);
        fail("Entity creation with invalid supertype should've failed");
    } catch (AtlasBaseException e) {
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)67 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)30 Test (org.testng.annotations.Test)25 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)24 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)24 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)19 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)18 ArrayList (java.util.ArrayList)17 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)17 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)14 HashMap (java.util.HashMap)12 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)7 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)6 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)5 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)5 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)5 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)5