use of org.apache.atlas.typesystem.types.EnumValue in project incubator-atlas by apache.
the class GraphBackedSearchIndexerTest method verifyUserDefinedTypeIndex.
@Test
public void verifyUserDefinedTypeIndex() throws AtlasException {
AtlasGraph graph = TestUtils.getGraph();
AtlasGraphManagement managementSystem = graph.getManagementSystem();
try {
TypeSystem typeSystem = TypeSystem.getInstance();
String enumName = "randomEnum" + RandomStringUtils.randomAlphanumeric(10);
EnumType managedType = typeSystem.defineEnumType(enumName, new EnumValue("randomEnumValue", 0));
HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = createClassTypeDef("Database", "Database type description", null, TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("managedType", managedType));
ClassType databaseType = typeSystem.defineClassType(databaseTypeDefinition);
graphBackedSearchIndexer.onAdd(Arrays.asList(databaseType));
verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY, false);
verifyVertexIndexContains(managementSystem, "Database.name" + Constants.ENTITY_TYPE_PROPERTY_KEY);
verifySystemCompositeIndex(managementSystem, "Database.name" + Constants.SUPER_TYPES_PROPERTY_KEY, false);
verifyVertexIndexContains(managementSystem, "Database.managedType");
} finally {
// search indexer uses its own titan management transaction
managementSystem.rollback();
}
}
use of org.apache.atlas.typesystem.types.EnumValue in project incubator-atlas by apache.
the class FullTextMapper method forAttribute.
private String forAttribute(IDataType type, Object value, boolean followReferences) throws AtlasException {
if (value == null) {
return null;
}
switch(type.getTypeCategory()) {
case PRIMITIVE:
return String.valueOf(value);
case ENUM:
return ((EnumValue) value).value;
case ARRAY:
StringBuilder fullText = new StringBuilder();
IDataType elemType = ((DataTypes.ArrayType) type).getElemType();
List list = (List) value;
for (Object element : list) {
String elemFullText = forAttribute(elemType, element, false);
if (StringUtils.isNotEmpty(elemFullText)) {
fullText = fullText.append(FULL_TEXT_DELIMITER).append(elemFullText);
}
}
return fullText.toString();
case MAP:
fullText = new StringBuilder();
IDataType keyType = ((DataTypes.MapType) type).getKeyType();
IDataType valueType = ((DataTypes.MapType) type).getValueType();
Map map = (Map) value;
for (Object entryObj : map.entrySet()) {
Map.Entry entry = (Map.Entry) entryObj;
String keyFullText = forAttribute(keyType, entry.getKey(), false);
if (StringUtils.isNotEmpty(keyFullText)) {
fullText = fullText.append(FULL_TEXT_DELIMITER).append(keyFullText);
}
String valueFullText = forAttribute(valueType, entry.getValue(), false);
if (StringUtils.isNotEmpty(valueFullText)) {
fullText = fullText.append(FULL_TEXT_DELIMITER).append(valueFullText);
}
}
return fullText.toString();
case CLASS:
if (followReferences) {
Id refId = ((ITypedReferenceableInstance) value).getId();
String refGuid = refId._getId();
AtlasVertex refVertex = typedInstanceToGraphMapper.lookupVertex(refId);
if (refVertex == null) {
refVertex = graphHelper.getVertexForGUID(refGuid);
}
return mapRecursive(refVertex, false);
}
break;
case STRUCT:
if (followReferences) {
return forInstance((ITypedInstance) value, true);
}
break;
default:
throw new IllegalStateException("Unhandled type category " + type.getTypeCategory());
}
return null;
}
use of org.apache.atlas.typesystem.types.EnumValue 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;
}
use of org.apache.atlas.typesystem.types.EnumValue in project incubator-atlas by apache.
the class DefaultTypeCacheTest method onetimeSetup.
@BeforeClass
public void onetimeSetup() throws Exception {
// init TypeSystem
TypeSystem ts = TypeSystem.getInstance().reset();
// Customer ClassType
customerType = ts.defineClassType(TypesUtil.createClassTypeDef(CLASSTYPE_CUSTOMER, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("id", DataTypes.LONG_TYPE)));
// Address StructType
addressType = ts.defineStructType(STRUCTTYPE_ADDRESS, true, TypesUtil.createRequiredAttrDef("first line", DataTypes.STRING_TYPE), TypesUtil.createOptionalAttrDef("second line", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("city", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("pincode", DataTypes.INT_TYPE));
// Privileged TraitType
privilegedTrait = ts.defineTraitType(TypesUtil.createTraitTypeDef(TRAITTYPE_PRIVILEGED, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("category", DataTypes.INT_TYPE)));
// Shipping EnumType
shippingEnum = ts.defineEnumType(TypesUtil.createEnumTypeDef(ENUMTYPE_SHIPPING, new EnumValue("Domestic", 1), new EnumValue("International", 2)));
}
use of org.apache.atlas.typesystem.types.EnumValue in project incubator-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;
}
Aggregations