Search in sources :

Example 6 with TraitType

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

the class MemRepository method defineTypes.

public void defineTypes(List<HierarchicalType> types) throws RepositoryException {
    List<TraitType> tTypes = new ArrayList<>();
    List<ClassType> cTypes = new ArrayList<>();
    for (HierarchicalType h : types) {
        if (h.getTypeCategory() == DataTypes.TypeCategory.TRAIT) {
            tTypes.add((TraitType) h);
        } else {
            cTypes.add((ClassType) h);
        }
    }
    tTypes = HierarchicalTypeDependencySorter.sortTypes(tTypes);
    cTypes = HierarchicalTypeDependencySorter.sortTypes(cTypes);
    for (TraitType tT : tTypes) {
        defineTrait(tT);
    }
    for (ClassType cT : cTypes) {
        defineClass(cT);
    }
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) HierarchicalType(org.apache.atlas.typesystem.types.HierarchicalType)

Example 7 with TraitType

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

the class TypeConverterUtil method structToTypesDef.

private static TypesDef structToTypesDef(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException {
    String typeName = structType.getStructDef().getName();
    String typeDesc = structType.getStructDef().getDescription();
    String typeVersion = structType.getStructDef().getTypeVersion();
    AttributeDefinition[] attributes = getAttributes(structType, registry);
    StructTypeDefinition structTypeDef = TypesUtil.createStructTypeDef(typeName, typeDesc, typeVersion, attributes);
    TypesDef ret = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.of(structTypeDef), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
    return ret;
}
Also used : 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) StructTypeDefinition(org.apache.atlas.typesystem.types.StructTypeDefinition)

Example 8 with TraitType

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

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

the class TypeConverterUtil method toAtlasClassificationDefs.

private static List<AtlasClassificationDef> toAtlasClassificationDefs(List<HierarchicalTypeDefinition<TraitType>> traitTypeDefinitions) throws AtlasBaseException {
    List<AtlasClassificationDef> ret = new ArrayList<AtlasClassificationDef>();
    for (HierarchicalTypeDefinition<TraitType> traitType : traitTypeDefinitions) {
        AtlasClassificationDef classifDef = new AtlasClassificationDef();
        List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>();
        classifDef.setName(traitType.typeName);
        classifDef.setDescription(traitType.typeDescription);
        classifDef.setTypeVersion(traitType.typeVersion);
        classifDef.setSuperTypes(traitType.superTypes);
        AttributeDefinition[] attrDefinitions = traitType.attributeDefinitions;
        for (AttributeDefinition attrDefinition : attrDefinitions) {
            attrDefs.add(toAtlasAttributeDef(attrDefinition));
        }
        classifDef.setAttributeDefs(attrDefs);
        ret.add(classifDef);
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition)

Example 10 with TraitType

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

the class QuickStart method createTypeDefinitions.

TypesDef createTypeDefinitions() throws Exception {
    HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil.createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE, null, TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), attrDef("description", DataTypes.STRING_TYPE), attrDef("locationUri", DataTypes.STRING_TYPE), attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE));
    HierarchicalTypeDefinition<ClassType> storageDescClsDef = TypesUtil.createClassTypeDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE, null, attrDef("location", DataTypes.STRING_TYPE), attrDef("inputFormat", DataTypes.STRING_TYPE), attrDef("outputFormat", DataTypes.STRING_TYPE), attrDef("compressed", DataTypes.STRING_TYPE, Multiplicity.REQUIRED, false, null));
    HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil.createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, null, attrDef("name", DataTypes.STRING_TYPE), attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE));
    HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil.createClassTypeDef(TABLE_TYPE, TABLE_TYPE, ImmutableSet.of("DataSet"), new AttributeDefinition(DB_ATTRIBUTE, DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("sd", STORAGE_DESC_TYPE, Multiplicity.REQUIRED, true, null), attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE), attrDef("lastAccessTime", DataTypes.LONG_TYPE), attrDef("retention", DataTypes.LONG_TYPE), attrDef("viewOriginalText", DataTypes.STRING_TYPE), attrDef("viewExpandedText", DataTypes.STRING_TYPE), attrDef("tableType", DataTypes.STRING_TYPE), attrDef("temporary", DataTypes.BOOLEAN_TYPE), new AttributeDefinition(COLUMNS_ATTRIBUTE, DataTypes.arrayTypeName(COLUMN_TYPE), Multiplicity.COLLECTION, true, null));
    HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil.createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, ImmutableSet.of("Process"), attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE), attrDef("endTime", DataTypes.LONG_TYPE), attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED));
    HierarchicalTypeDefinition<ClassType> viewClsDef = TypesUtil.createClassTypeDef(VIEW_TYPE, VIEW_TYPE, ImmutableSet.of("DataSet"), new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("inputTables", DataTypes.arrayTypeName(TABLE_TYPE), Multiplicity.COLLECTION, false, null));
    HierarchicalTypeDefinition<TraitType> dimTraitDef = TypesUtil.createTraitTypeDef("Dimension_v1", "Dimension Trait", null);
    HierarchicalTypeDefinition<TraitType> factTraitDef = TypesUtil.createTraitTypeDef("Fact_v1", "Fact Trait", null);
    HierarchicalTypeDefinition<TraitType> piiTraitDef = TypesUtil.createTraitTypeDef("PII_v1", "PII Trait", null);
    HierarchicalTypeDefinition<TraitType> metricTraitDef = TypesUtil.createTraitTypeDef("Metric_v1", "Metric Trait", null);
    HierarchicalTypeDefinition<TraitType> etlTraitDef = TypesUtil.createTraitTypeDef("ETL_v1", "ETL Trait", null);
    HierarchicalTypeDefinition<TraitType> jdbcTraitDef = TypesUtil.createTraitTypeDef("JdbcAccess_v1", "JdbcAccess Trait", null);
    HierarchicalTypeDefinition<TraitType> logTraitDef = TypesUtil.createTraitTypeDef("Log Data_v1", "LogData Trait", null);
    return TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.of(dimTraitDef, factTraitDef, piiTraitDef, metricTraitDef, etlTraitDef, jdbcTraitDef, logTraitDef), ImmutableList.of(dbClsDef, storageDescClsDef, columnClsDef, tblClsDef, loadProcessClsDef, viewClsDef));
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Aggregations

TraitType (org.apache.atlas.typesystem.types.TraitType)40 Test (org.testng.annotations.Test)22 ClassType (org.apache.atlas.typesystem.types.ClassType)19 TypesDef (org.apache.atlas.typesystem.TypesDef)13 Referenceable (org.apache.atlas.typesystem.Referenceable)12 Struct (org.apache.atlas.typesystem.Struct)12 Id (org.apache.atlas.typesystem.persistence.Id)10 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)10 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)7 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)7 IStruct (org.apache.atlas.typesystem.IStruct)6 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)6 ArrayList (java.util.ArrayList)5 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)5 AtlasServiceException (org.apache.atlas.AtlasServiceException)4 HierarchicalTypeDefinition (org.apache.atlas.typesystem.types.HierarchicalTypeDefinition)3 BeforeTest (org.testng.annotations.BeforeTest)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 HashMap (java.util.HashMap)2