use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue in project atlas by apache.
the class BaseResourceIT method createTypeDefinitionsV1.
protected void createTypeDefinitionsV1() throws Exception {
ClassTypeDefinition dbClsDef = TypesUtil.createClassTypeDef(DATABASE_TYPE, null, null, TypesUtil.createUniqueRequiredAttrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), TypesUtil.createRequiredAttrDef(DESCRIPTION, AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("locationUri", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_INT), new AttributeDefinition("tables", AtlasBaseTypeDef.getArrayTypeName(HIVE_TABLE_TYPE), Multiplicity.OPTIONAL, false, "db"));
ClassTypeDefinition columnClsDef = TypesUtil.createClassTypeDef(COLUMN_TYPE, null, null, attrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("dataType", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("comment", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
StructTypeDefinition structTypeDefinition = new StructTypeDefinition("serdeType", null, Arrays.asList(new AttributeDefinition[] { TypesUtil.createRequiredAttrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), TypesUtil.createRequiredAttrDef("serde", AtlasBaseTypeDef.ATLAS_TYPE_STRING) }));
EnumValue[] values = { new EnumValue("MANAGED", 1), new EnumValue("EXTERNAL", 2) };
EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", null, null, Arrays.asList(values));
ClassTypeDefinition tblClsDef = TypesUtil.createClassTypeDef(HIVE_TABLE_TYPE, null, Collections.singleton("DataSet"), attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), attrDef("lastAccessTime", AtlasBaseTypeDef.ATLAS_TYPE_DATE), attrDef("temporary", AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN), new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.OPTIONAL, true, "tables"), new AttributeDefinition("columns", AtlasBaseTypeDef.getArrayTypeName(COLUMN_TYPE), Multiplicity.OPTIONAL, true, null), new AttributeDefinition("tableType", "tableType", Multiplicity.OPTIONAL, false, null), new AttributeDefinition("serde1", "serdeType", Multiplicity.OPTIONAL, false, null), new AttributeDefinition("serde2", "serdeType", Multiplicity.OPTIONAL, false, null));
ClassTypeDefinition loadProcessClsDef = TypesUtil.createClassTypeDef(HIVE_PROCESS_TYPE, null, Collections.singleton("Process"), attrDef("userName", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("startTime", AtlasBaseTypeDef.ATLAS_TYPE_INT), attrDef("endTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), attrDef("queryText", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryPlan", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryId", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryGraph", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED));
TraitTypeDefinition classificationTrait = TypesUtil.createTraitTypeDef("classification", null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("tag", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(PII_TAG, null, Collections.<String>emptySet());
TraitTypeDefinition phiTrait = TypesUtil.createTraitTypeDef(PHI_TAG, null, Collections.<String>emptySet());
TraitTypeDefinition pciTrait = TypesUtil.createTraitTypeDef(PCI_TAG, null, Collections.<String>emptySet());
TraitTypeDefinition soxTrait = TypesUtil.createTraitTypeDef(SOX_TAG, null, Collections.<String>emptySet());
TraitTypeDefinition secTrait = TypesUtil.createTraitTypeDef(SEC_TAG, null, Collections.<String>emptySet());
TraitTypeDefinition financeTrait = TypesUtil.createTraitTypeDef(FINANCE_TAG, null, Collections.<String>emptySet());
TraitTypeDefinition factTrait = TypesUtil.createTraitTypeDef("Fact" + randomString(), null, Collections.<String>emptySet());
TraitTypeDefinition etlTrait = TypesUtil.createTraitTypeDef("ETL" + randomString(), null, Collections.<String>emptySet());
TraitTypeDefinition dimensionTrait = TypesUtil.createTraitTypeDef("Dimension" + randomString(), null, Collections.<String>emptySet());
TraitTypeDefinition metricTrait = TypesUtil.createTraitTypeDef("Metric" + randomString(), null, Collections.<String>emptySet());
createType(getTypesDef(Collections.singletonList(enumTypeDefinition), Collections.singletonList(structTypeDefinition), Arrays.asList(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait, factTrait, etlTrait, dimensionTrait, metricTrait), Arrays.asList(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)));
}
use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue in project atlas by apache.
the class TypeConverterUtil method enumToTypesDef.
private static TypesDef enumToTypesDef(AtlasEnumType enumType) {
AtlasEnumDef enumDef = enumType.getEnumDef();
String enumName = enumDef.getName();
String enumDesc = enumDef.getDescription();
String enumVersion = enumDef.getTypeVersion();
List<EnumValue> enumValues = getEnumValues(enumDef.getElementDefs());
EnumTypeDefinition enumTypeDef = new EnumTypeDefinition(enumName, enumDesc, enumVersion, enumValues);
TypesDef ret = new TypesDef(Arrays.asList(enumTypeDef), null, null, null);
return ret;
}
use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue in project atlas by apache.
the class AtlasEnumFormatConverter method fromV2ToV1.
@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
EnumValue ret = null;
if (v2Obj == null || !(type instanceof AtlasEnumType)) {
return ret;
}
AtlasEnumType enumType = (AtlasEnumType) type;
AtlasEnumElementDef elementDef = enumType.getEnumElementDef(v2Obj.toString());
if (elementDef != null) {
ret = new EnumValue(elementDef.getValue(), elementDef.getOrdinal());
}
return ret;
}
use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue in project atlas by apache.
the class AtlasEnumFormatConverter method fromV1ToV2.
@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
String ret = null;
if (v1Obj == null || !(type instanceof AtlasEnumType)) {
return ret;
}
Object v1Value = null;
if (v1Obj instanceof EnumValue) {
EnumValue enumValue = (EnumValue) v1Obj;
v1Value = enumValue.getValue();
if (v1Value == null) {
v1Value = enumValue.getOrdinal();
}
} else if (v1Obj instanceof Map) {
Map mapValue = (Map) v1Obj;
v1Value = mapValue.get("value");
if (v1Value == null) {
v1Value = mapValue.get("ordinal");
}
}
if (v1Value == null) {
// could be 'value' or 'ordinal'
v1Value = v1Obj;
}
AtlasEnumElementDef elementDef;
if (v1Value instanceof Number) {
elementDef = ((AtlasEnumType) type).getEnumElementDef((Number) v1Value);
} else {
elementDef = ((AtlasEnumType) type).getEnumElementDef(v1Value.toString());
}
if (elementDef != null) {
ret = elementDef.getValue();
}
return ret;
}
Aggregations