Search in sources :

Example 6 with HierarchicalTypeDefinition

use of org.apache.atlas.typesystem.types.HierarchicalTypeDefinition in project incubator-atlas by apache.

the class TypesJerseyResourceIT method createHiveTypes.

private List<HierarchicalTypeDefinition> createHiveTypes() throws Exception {
    ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>();
    HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil.createClassTypeDef("database", ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef(QUALIFIED_NAME, DataTypes.STRING_TYPE));
    typeDefinitions.add(databaseTypeDefinition);
    HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil.createClassTypeDef("table", ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef(NAME, DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef(DESCRIPTION, DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef(QUALIFIED_NAME, DataTypes.STRING_TYPE), createOptionalAttrDef("columnNames", DataTypes.arrayTypeName(DataTypes.STRING_TYPE)), createOptionalAttrDef("created", DataTypes.DATE_TYPE), createOptionalAttrDef("parameters", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.STRING_TYPE)), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE), new AttributeDefinition("database", "database", Multiplicity.REQUIRED, false, "database"));
    typeDefinitions.add(tableTypeDefinition);
    HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil.createTraitTypeDef("fetl", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE));
    typeDefinitions.add(fetlTypeDefinition);
    return typeDefinitions;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) TraitType(org.apache.atlas.typesystem.types.TraitType) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 7 with HierarchicalTypeDefinition

use of org.apache.atlas.typesystem.types.HierarchicalTypeDefinition in project incubator-atlas by apache.

the class TypesJerseyResourceIT method testGetDefinition.

@Test(dependsOnMethods = "testSubmit")
public void testGetDefinition() throws Exception {
    for (HierarchicalTypeDefinition typeDefinition : typeDefinitions) {
        System.out.println("typeName = " + typeDefinition.typeName);
        JSONObject response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API.LIST_TYPES, null, typeDefinition.typeName);
        Assert.assertNotNull(response);
        Assert.assertNotNull(response.get(AtlasClient.DEFINITION));
        Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
        String typesJson = response.getString(AtlasClient.DEFINITION);
        final TypesDef typesDef = TypesSerialization.fromJson(typesJson);
        List<HierarchicalTypeDefinition<ClassType>> hierarchicalTypeDefinitions = typesDef.classTypesAsJavaList();
        for (HierarchicalTypeDefinition<ClassType> classType : hierarchicalTypeDefinitions) {
            for (AttributeDefinition attrDef : classType.attributeDefinitions) {
                if (NAME.equals(attrDef.name)) {
                    assertEquals(attrDef.isIndexable, true);
                    assertEquals(attrDef.isUnique, true);
                }
            }
        }
    }
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) JSONObject(org.codehaus.jettison.json.JSONObject) TypesDef(org.apache.atlas.typesystem.TypesDef) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 8 with HierarchicalTypeDefinition

use of org.apache.atlas.typesystem.types.HierarchicalTypeDefinition in project incubator-atlas by apache.

the class GraphBackedDiscoveryServiceTest method createTypesWithMultiLevelInheritance.

/*
     * Type Hierarchy is:
     *   A(a)
     *   B(b) extends A
     *   C(c) extends B
     *   D(d) extends C
     */
private void createTypesWithMultiLevelInheritance() throws Exception {
    HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
    HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableSet.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE));
    HierarchicalTypeDefinition C = createClassTypeDef("C", ImmutableSet.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE));
    HierarchicalTypeDefinition D = createClassTypeDef("D", ImmutableSet.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE));
    TypeSystem.getInstance().defineClassTypes(A, B, C, D);
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)

Example 9 with HierarchicalTypeDefinition

use of org.apache.atlas.typesystem.types.HierarchicalTypeDefinition in project incubator-atlas by apache.

the class RestUtilsTest method convertV1toV2.

private List<AtlasEntityDef> convertV1toV2(List<HierarchicalTypeDefinition<ClassType>> types) throws AtlasBaseException {
    ImmutableList<HierarchicalTypeDefinition<ClassType>> classTypeList = ImmutableList.<HierarchicalTypeDefinition<ClassType>>builder().addAll(types).build();
    TypesDef toConvert = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), classTypeList);
    String json = TypesSerialization.toJson(toConvert);
    AtlasTypeRegistry emptyRegistry = new AtlasTypeRegistry();
    AtlasTypesDef converted = TypeConverterUtil.toAtlasTypesDef(json, emptyRegistry);
    List<AtlasEntityDef> convertedEntityDefs = converted.getEntityDefs();
    return convertedEntityDefs;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 10 with HierarchicalTypeDefinition

use of org.apache.atlas.typesystem.types.HierarchicalTypeDefinition in project incubator-atlas by apache.

the class RestUtilsTest method testV1toV2toV1Conversion.

private void testV1toV2toV1Conversion(List<HierarchicalTypeDefinition<ClassType>> typesToTest, boolean[] compositeExpected) throws AtlasBaseException {
    List<AtlasEntityDef> convertedEntityDefs = convertV1toV2(typesToTest);
    AtlasTypeRegistry registry = createRegistry(convertedEntityDefs);
    for (int i = 0; i < convertedEntityDefs.size(); i++) {
        AtlasEntityDef def = convertedEntityDefs.get(i);
        for (AtlasAttributeDef attrDef : def.getAttributeDefs()) {
            AtlasAttributeDef converted = convertToJsonAndBack(registry, def, attrDef, compositeExpected[i]);
            Assert.assertEquals(converted, attrDef);
        }
    }
    List<HierarchicalTypeDefinition<ClassType>> convertedBackTypeDefs = convertV2toV1(convertedEntityDefs);
    for (int i = 0; i < typesToTest.size(); i++) {
        HierarchicalTypeDefinition<ClassType> convertedBack = convertedBackTypeDefs.get(i);
        Assert.assertEquals(convertedBack, typesToTest.get(i));
        AttributeDefinition[] attributeDefinitions = convertedBack.attributeDefinitions;
        if (attributeDefinitions.length > 0) {
            Assert.assertEquals(attributeDefinitions[0].isComposite, compositeExpected[i]);
        }
    }
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Aggregations

HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)10 ClassType (org.apache.atlas.typesystem.types.ClassType)5 TypesDef (org.apache.atlas.typesystem.TypesDef)4 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)4 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)3 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)3 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)3 TraitType (org.apache.atlas.typesystem.types.TraitType)3 ArrayList (java.util.ArrayList)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Test (org.testng.annotations.Test)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 BaseRepositoryTest (org.apache.atlas.BaseRepositoryTest)1 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)1 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)1 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)1 EnumTypeDefinition (org.apache.atlas.typesystem.types.EnumTypeDefinition)1 EnumValue (org.apache.atlas.typesystem.types.EnumValue)1 StructTypeDefinition (org.apache.atlas.typesystem.types.StructTypeDefinition)1 JSONArray (org.codehaus.jettison.json.JSONArray)1