Search in sources :

Example 26 with AtlasEntityDef

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

the class TypeDefSorter method addToResult.

private static <T extends AtlasStructDef> void addToResult(T type, List<T> result, Set<T> processed, Map<String, T> typesByName) {
    if (processed.contains(type)) {
        return;
    }
    processed.add(type);
    Set<String> superTypeNames = new HashSet<>();
    if (type.getClass().equals(AtlasClassificationDef.class)) {
        try {
            AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
            superTypeNames.addAll(classificationDef.getSuperTypes());
        } catch (ClassCastException ex) {
            LOG.warn("Casting to ClassificationDef failed");
        }
    }
    if (type.getClass().equals(AtlasEntityDef.class)) {
        try {
            AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
            superTypeNames.addAll(entityDef.getSuperTypes());
        } catch (ClassCastException ex) {
            LOG.warn("Casting to AtlasEntityDef failed");
        }
    }
    for (String superTypeName : superTypeNames) {
        // Recursively add any supertypes first to the result.
        T superType = typesByName.get(superTypeName);
        if (superType != null) {
            addToResult(superType, result, processed, typesByName);
        }
    }
    result.add(type);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashSet(java.util.HashSet)

Example 27 with AtlasEntityDef

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

the class EntityV2JerseyResourceIT method testUTF8.

@Test
public void testUTF8() throws Exception {
    String classType = randomString();
    String attrName = random();
    String attrValue = random();
    AtlasEntityDef classTypeDef = AtlasTypeUtil.createClassTypeDef(classType, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef(attrName, "string"));
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    atlasTypesDef.getEntityDefs().add(classTypeDef);
    createType(atlasTypesDef);
    AtlasEntity instance = new AtlasEntity(classType);
    instance.setAttribute(attrName, attrValue);
    AtlasEntityHeader entity = createEntity(instance);
    assertNotNull(entity);
    assertNotNull(entity.getGuid());
    AtlasEntity entityByGuid = getEntityByGuid(entity.getGuid());
    assertEquals(entityByGuid.getAttribute(attrName), attrValue);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Example 28 with AtlasEntityDef

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

the class TypedefsJerseyResourceIT method createHiveTypesV2.

private AtlasTypesDef createHiveTypesV2() throws Exception {
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    AtlasEntityDef databaseTypeDefinition = createClassTypeDef("database", ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"));
    atlasTypesDef.getEntityDefs().add(databaseTypeDefinition);
    AtlasEntityDef tableTypeDefinition = createClassTypeDef("table", ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"), AtlasTypeUtil.createOptionalAttrDef("columnNames", DataTypes.arrayTypeName("string")), AtlasTypeUtil.createOptionalAttrDef("created", "date"), AtlasTypeUtil.createOptionalAttrDef("parameters", DataTypes.mapTypeName("string", "string")), AtlasTypeUtil.createRequiredAttrDef("type", "string"), new AtlasAttributeDef("database", "database", false, Cardinality.SINGLE, 1, 1, true, true, Collections.<AtlasConstraintDef>emptyList()));
    atlasTypesDef.getEntityDefs().add(tableTypeDefinition);
    AtlasClassificationDef fetlTypeDefinition = AtlasTypeUtil.createTraitTypeDef("fetl", ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("level", "int"));
    atlasTypesDef.getClassificationDefs().add(fetlTypeDefinition);
    return atlasTypesDef;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 29 with AtlasEntityDef

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

the class TypedefsJerseyResourceIT method testCreate.

@Test
public void testCreate() throws Exception {
    createType(typeDefinitions);
    for (AtlasEnumDef enumDef : typeDefinitions.getEnumDefs()) {
        AtlasEnumDef byName = atlasClientV2.getEnumDefByName(enumDef.getName());
        assertNotNull(byName);
    }
    for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) {
        AtlasStructDef byName = atlasClientV2.getStructDefByName(structDef.getName());
        assertNotNull(byName);
    }
    for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) {
        AtlasClassificationDef byName = atlasClientV2.getClassificationDefByName(classificationDef.getName());
        assertNotNull(byName);
    }
    for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
        AtlasEntityDef byName = atlasClientV2.getEntityDefByName(entityDef.getName());
        assertNotNull(byName);
    }
}
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) Test(org.testng.annotations.Test)

Example 30 with AtlasEntityDef

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

the class TypedefsJerseyResourceIT method testListTypesByFilter.

@Test
public void testListTypesByFilter() throws Exception {
    AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", "string");
    AtlasEntityDef classDefA = AtlasTypeUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr);
    AtlasEntityDef classDefA1 = AtlasTypeUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(classDefA.getName()), attr);
    AtlasEntityDef classDefB = AtlasTypeUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr);
    AtlasEntityDef classDefC = AtlasTypeUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(classDefB.getName(), classDefA.getName()), attr);
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    atlasTypesDef.getEntityDefs().add(classDefA);
    atlasTypesDef.getEntityDefs().add(classDefA1);
    atlasTypesDef.getEntityDefs().add(classDefB);
    atlasTypesDef.getEntityDefs().add(classDefC);
    AtlasTypesDef created = clientV2.createAtlasTypeDefs(atlasTypesDef);
    assertNotNull(created);
    assertEquals(created.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
    MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
    searchParams.add(SearchFilter.PARAM_TYPE, "CLASS");
    searchParams.add(SearchFilter.PARAM_SUPERTYPE, classDefA.getName());
    SearchFilter searchFilter = new SearchFilter(searchParams);
    AtlasTypesDef searchDefs = clientV2.getAllTypeDefs(searchFilter);
    assertNotNull(searchDefs);
    assertEquals(searchDefs.getEntityDefs().size(), 2);
    searchParams.add(SearchFilter.PARAM_NOT_SUPERTYPE, classDefB.getName());
    searchFilter = new SearchFilter(searchParams);
    searchDefs = clientV2.getAllTypeDefs(searchFilter);
    assertNotNull(searchDefs);
    assertEquals(searchDefs.getEntityDefs().size(), 1);
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) SearchFilter(org.apache.atlas.model.SearchFilter) 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