Search in sources :

Example 1 with EnumValue

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();
    }
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) EnumType(org.apache.atlas.typesystem.types.EnumType) EnumValue(org.apache.atlas.typesystem.types.EnumValue) ClassType(org.apache.atlas.typesystem.types.ClassType) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) Test(org.testng.annotations.Test)

Example 2 with EnumValue

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;
}
Also used : EnumValue(org.apache.atlas.typesystem.types.EnumValue) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) IDataType(org.apache.atlas.typesystem.types.IDataType) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) List(java.util.List) Id(org.apache.atlas.typesystem.persistence.Id) Map(java.util.Map)

Example 3 with EnumValue

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;
}
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 4 with EnumValue

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)));
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) EnumValue(org.apache.atlas.typesystem.types.EnumValue) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with EnumValue

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;
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) EnumValue(org.apache.atlas.typesystem.types.EnumValue) AtlasEnumType(org.apache.atlas.type.AtlasEnumType)

Aggregations

EnumValue (org.apache.atlas.typesystem.types.EnumValue)9 Map (java.util.Map)2 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)2 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 AtlasEnumType (org.apache.atlas.type.AtlasEnumType)2 ClassType (org.apache.atlas.typesystem.types.ClassType)2 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)2 Test (org.testng.annotations.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 AtlasException (org.apache.atlas.AtlasException)1 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)1 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)1 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)1 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)1 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)1 Referenceable (org.apache.atlas.typesystem.Referenceable)1