Search in sources :

Example 46 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 47 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 48 with AtlasEntityDef

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

the class EntityDiscoveryServiceTest method init.

@BeforeClass
public void init() throws AtlasBaseException {
    typeTest = new AtlasEntityDef(TEST_TYPE);
    typeTest1 = new AtlasEntityDef(TEST_TYPE1);
    typeTest2 = new AtlasEntityDef(TEST_TYPE2);
    typeTest3 = new AtlasEntityDef(TEST_TYPE3);
    typeWithSubTypes = new AtlasEntityDef(TEST_TYPE_WITH_SUB_TYPES);
    typeTest1.addSuperType(TEST_TYPE_WITH_SUB_TYPES);
    typeTest2.addSuperType(TEST_TYPE_WITH_SUB_TYPES);
    typeTest3.addSuperType(TEST_TYPE_WITH_SUB_TYPES);
    AtlasTypeRegistry.AtlasTransientTypeRegistry ttr = typeRegistry.lockTypeRegistryForUpdate();
    ttr.addType(typeTest);
    ttr.addType(typeWithSubTypes);
    ttr.addType(typeTest1);
    ttr.addType(typeTest2);
    ttr.addType(typeTest3);
    typeRegistry.releaseTypeRegistryForUpdate(ttr, true);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) BeforeClass(org.testng.annotations.BeforeClass)

Example 49 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)

Example 50 with AtlasEntityDef

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

the class AtlasTypeDefGraphStoreTest method testUpdateWithMandatoryFields.

@Test(enabled = false, dependsOnMethods = { "testCreateDept" })
public void testUpdateWithMandatoryFields() {
    AtlasTypesDef atlasTypesDef = TestUtilsV2.defineInvalidUpdatedDeptEmployeeTypes();
    List<AtlasEnumDef> enumDefsToUpdate = atlasTypesDef.getEnumDefs();
    List<AtlasClassificationDef> classificationDefsToUpdate = atlasTypesDef.getClassificationDefs();
    List<AtlasStructDef> structDefsToUpdate = atlasTypesDef.getStructDefs();
    List<AtlasEntityDef> entityDefsToUpdate = atlasTypesDef.getEntityDefs();
    AtlasTypesDef onlyEnums = new AtlasTypesDef(enumDefsToUpdate, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
    AtlasTypesDef onlyStructs = new AtlasTypesDef(Collections.EMPTY_LIST, structDefsToUpdate, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
    AtlasTypesDef onlyClassification = new AtlasTypesDef(Collections.EMPTY_LIST, Collections.EMPTY_LIST, classificationDefsToUpdate, Collections.EMPTY_LIST);
    AtlasTypesDef onlyEntities = new AtlasTypesDef(Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, entityDefsToUpdate);
    try {
        AtlasTypesDef updated = typeDefStore.updateTypesDef(onlyEnums);
        assertNotNull(updated);
    } catch (AtlasBaseException ignored) {
    }
    try {
        AtlasTypesDef updated = typeDefStore.updateTypesDef(onlyClassification);
        assertNotNull(updated);
        assertEquals(updated.getClassificationDefs().size(), 0, "Updates should've failed");
    } catch (AtlasBaseException ignored) {
    }
    try {
        AtlasTypesDef updated = typeDefStore.updateTypesDef(onlyStructs);
        assertNotNull(updated);
        assertEquals(updated.getStructDefs().size(), 0, "Updates should've failed");
    } catch (AtlasBaseException ignored) {
    }
    try {
        AtlasTypesDef updated = typeDefStore.updateTypesDef(onlyEntities);
        assertNotNull(updated);
        assertEquals(updated.getEntityDefs().size(), 0, "Updates should've failed");
    } catch (AtlasBaseException ignored) {
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

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