Search in sources :

Example 1 with EnumType

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

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

the class StructInstance method setInt.

public void setInt(String attrName, int val) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.INT_TYPE && !(i.dataType() instanceof EnumType)) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic set method", attrName, getTypeName(), DataTypes.INT_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    nullFlags[nullPos] = false;
    ints[pos] = val;
    explicitSets[nullPos] = true;
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) EnumType(org.apache.atlas.typesystem.types.EnumType) AtlasException(org.apache.atlas.AtlasException)

Example 3 with EnumType

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

the class StructInstance method getInt.

public int getInt(String attrName) throws AtlasException {
    AttributeInfo i = fieldMapping.fields.get(attrName);
    if (i == null) {
        throw new AtlasException(String.format("Unknown field %s for Struct %s", attrName, getTypeName()));
    }
    if (i.dataType() != DataTypes.INT_TYPE && !(i.dataType() instanceof EnumType)) {
        throw new AtlasException(String.format("Field %s for Struct %s is not a %s, call generic get method", attrName, getTypeName(), DataTypes.INT_TYPE.getName()));
    }
    int pos = fieldMapping.fieldPos.get(attrName);
    int nullPos = fieldMapping.fieldNullPos.get(attrName);
    if (nullFlags[nullPos]) {
        return DataTypes.INT_TYPE.nullValue();
    }
    return ints[pos];
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) EnumType(org.apache.atlas.typesystem.types.EnumType) AtlasException(org.apache.atlas.AtlasException)

Aggregations

EnumType (org.apache.atlas.typesystem.types.EnumType)3 AtlasException (org.apache.atlas.AtlasException)2 AttributeInfo (org.apache.atlas.typesystem.types.AttributeInfo)2 AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)1 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)1 ClassType (org.apache.atlas.typesystem.types.ClassType)1 EnumValue (org.apache.atlas.typesystem.types.EnumValue)1 TypeSystem (org.apache.atlas.typesystem.types.TypeSystem)1 Test (org.testng.annotations.Test)1