Search in sources :

Example 1 with HierarchicalTypeDefinition

use of org.apache.atlas.typesystem.types.HierarchicalTypeDefinition 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 2 with HierarchicalTypeDefinition

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

the class TypeConverterUtil method enumToTypesDef.

private static TypesDef enumToTypesDef(AtlasEnumType enumType) {
    TypesDef ret = null;
    AtlasEnumDef enumDef = enumType.getEnumDef();
    String enumName = enumDef.getName();
    String enumDesc = enumDef.getDescription();
    String enumVersion = enumDef.getTypeVersion();
    EnumValue[] enumValues = getEnumValues(enumDef.getElementDefs());
    if (enumName != null && enumValues != null && enumValues.length > 0) {
        EnumTypeDefinition enumTypeDef = new EnumTypeDefinition(enumName, enumDesc, enumVersion, enumValues);
        ret = TypesUtil.getTypesDef(ImmutableList.of(enumTypeDef), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
    }
    return ret;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) EnumValue(org.apache.atlas.typesystem.types.EnumValue) EnumTypeDefinition(org.apache.atlas.typesystem.types.EnumTypeDefinition) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) StructTypeDefinition(org.apache.atlas.typesystem.types.StructTypeDefinition)

Example 3 with HierarchicalTypeDefinition

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

the class TypeConverterUtil method classificationToTypesDef.

private static TypesDef classificationToTypesDef(AtlasClassificationType classificationType, AtlasTypeRegistry registry) throws AtlasBaseException {
    String typeName = classificationType.getClassificationDef().getName();
    String typeDesc = classificationType.getClassificationDef().getDescription();
    String typeVersion = classificationType.getClassificationDef().getTypeVersion();
    ImmutableSet superTypes = ImmutableSet.copyOf(classificationType.getClassificationDef().getSuperTypes());
    AttributeDefinition[] attributes = getAttributes(classificationType, registry);
    HierarchicalTypeDefinition traitType = TypesUtil.createTraitTypeDef(typeName, typeDesc, typeVersion, superTypes, attributes);
    TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(traitType), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
    return ret;
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) ImmutableSet(com.google.common.collect.ImmutableSet) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TypesDef(org.apache.atlas.typesystem.TypesDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 4 with HierarchicalTypeDefinition

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

the class GraphBackedDiscoveryServiceTest method createTypesWithReservedKeywordAttributes.

private void createTypesWithReservedKeywordAttributes() throws Exception {
    HierarchicalTypeDefinition orderType = createClassTypeDef("OrderType", null, createRequiredAttrDef("order", DataTypes.INT_TYPE));
    HierarchicalTypeDefinition limitType = createClassTypeDef("LimitType", null, createOptionalAttrDef("limit", DataTypes.BOOLEAN_TYPE));
    TypeSystem.getInstance().defineClassTypes(orderType, limitType);
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)

Example 5 with HierarchicalTypeDefinition

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

the class GraphBackedDiscoveryServiceTest method testSearchForTypeWithNoInstances.

@Test
public void testSearchForTypeWithNoInstances() throws Exception {
    HierarchicalTypeDefinition EMPTY = createClassTypeDef("EmptyType", null, createRequiredAttrDef("a", DataTypes.INT_TYPE));
    TypeSystem.getInstance().defineClassTypes(EMPTY);
    String dslQuery = "EmptyType";
    String jsonResults = searchByDSL(dslQuery);
    assertNotNull(jsonResults);
    JSONObject results = new JSONObject(jsonResults);
    assertEquals(results.length(), 3);
    JSONArray rows = results.getJSONArray("rows");
    assertNotNull(rows);
    // query should not return any rows
    assertEquals(rows.length(), 0);
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) Test(org.testng.annotations.Test) BaseRepositoryTest(org.apache.atlas.BaseRepositoryTest)

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