Search in sources :

Example 1 with AtlasEnumType

use of org.apache.atlas.type.AtlasEnumType in project atlas by apache.

the class SearchProcessor method toInMemoryPredicate.

private Predicate toInMemoryPredicate(AtlasStructType type, String attrName, SearchParameters.Operator op, String attrVal) {
    Predicate ret = null;
    AtlasAttribute attribute = type.getAttribute(attrName);
    VertexAttributePredicateGenerator predicate = OPERATOR_PREDICATE_MAP.get(op);
    if (attribute != null && predicate != null) {
        final AtlasType attrType = attribute.getAttributeType();
        final Class attrClass;
        final Object attrValue;
        // Some operators support null comparison, thus the parsing has to be conditional
        switch(attrType.getTypeName()) {
            case AtlasBaseTypeDef.ATLAS_TYPE_STRING:
                attrClass = String.class;
                attrValue = attrVal;
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_SHORT:
                attrClass = Short.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : Short.parseShort(attrVal);
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_INT:
                attrClass = Integer.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : Integer.parseInt(attrVal);
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_BIGINTEGER:
                attrClass = BigInteger.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : new BigInteger(attrVal);
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN:
                attrClass = Boolean.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : Boolean.parseBoolean(attrVal);
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_BYTE:
                attrClass = Byte.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : Byte.parseByte(attrVal);
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_LONG:
            case AtlasBaseTypeDef.ATLAS_TYPE_DATE:
                attrClass = Long.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : Long.parseLong(attrVal);
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_FLOAT:
                attrClass = Float.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : Float.parseFloat(attrVal);
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_DOUBLE:
                attrClass = Double.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : Double.parseDouble(attrVal);
                break;
            case AtlasBaseTypeDef.ATLAS_TYPE_BIGDECIMAL:
                attrClass = BigDecimal.class;
                attrValue = StringUtils.isEmpty(attrVal) ? null : new BigDecimal(attrVal);
                break;
            default:
                if (attrType instanceof AtlasEnumType) {
                    attrClass = String.class;
                } else if (attrType instanceof AtlasArrayType) {
                    attrClass = List.class;
                } else {
                    attrClass = Object.class;
                }
                attrValue = attrVal;
                break;
        }
        ret = predicate.generatePredicate(attribute.getQualifiedName(), attrValue, attrClass);
    }
    return ret;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasType(org.apache.atlas.type.AtlasType) BigInteger(java.math.BigInteger) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) BigDecimal(java.math.BigDecimal) Predicate(org.apache.commons.collections.Predicate)

Example 2 with AtlasEnumType

use of org.apache.atlas.type.AtlasEnumType in project atlas by apache.

the class ExportService method addType.

private void addType(AtlasType type, ExportContext context) {
    if (type.getTypeCategory() == TypeCategory.PRIMITIVE) {
        return;
    }
    if (type instanceof AtlasArrayType) {
        AtlasArrayType arrayType = (AtlasArrayType) type;
        addType(arrayType.getElementType(), context);
    } else if (type instanceof AtlasMapType) {
        AtlasMapType mapType = (AtlasMapType) type;
        addType(mapType.getKeyType(), context);
        addType(mapType.getValueType(), context);
    } else if (type instanceof AtlasEntityType) {
        addEntityType((AtlasEntityType) type, context);
    } else if (type instanceof AtlasClassificationType) {
        addClassificationType((AtlasClassificationType) type, context);
    } else if (type instanceof AtlasStructType) {
        addStructType((AtlasStructType) type, context);
    } else if (type instanceof AtlasEnumType) {
        addEnumType((AtlasEnumType) type, context);
    }
}
Also used : AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasMapType(org.apache.atlas.type.AtlasMapType)

Example 3 with AtlasEnumType

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

Example 4 with AtlasEnumType

use of org.apache.atlas.type.AtlasEnumType 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;
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) EnumValue(org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue) AtlasEnumType(org.apache.atlas.type.AtlasEnumType) Map(java.util.Map)

Example 5 with AtlasEnumType

use of org.apache.atlas.type.AtlasEnumType in project incubator-atlas by apache.

the class ExportService method addType.

private void addType(AtlasType type, ExportContext context) {
    if (type.getTypeCategory() == TypeCategory.PRIMITIVE) {
        return;
    }
    if (type instanceof AtlasArrayType) {
        AtlasArrayType arrayType = (AtlasArrayType) type;
        addType(arrayType.getElementType(), context);
    } else if (type instanceof AtlasMapType) {
        AtlasMapType mapType = (AtlasMapType) type;
        addType(mapType.getKeyType(), context);
        addType(mapType.getValueType(), context);
    } else if (type instanceof AtlasEntityType) {
        addEntityType((AtlasEntityType) type, context);
    } else if (type instanceof AtlasClassificationType) {
        addClassificationType((AtlasClassificationType) type, context);
    } else if (type instanceof AtlasStructType) {
        addStructType((AtlasStructType) type, context);
    } else if (type instanceof AtlasEnumType) {
        addEnumType((AtlasEnumType) type, context);
    }
}
Also used : AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasMapType(org.apache.atlas.type.AtlasMapType)

Aggregations

AtlasEnumType (org.apache.atlas.type.AtlasEnumType)7 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)4 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)3 Map (java.util.Map)2 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)2 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)2 AtlasMapType (org.apache.atlas.type.AtlasMapType)2 AtlasStructType (org.apache.atlas.type.AtlasStructType)2 EnumValue (org.apache.atlas.typesystem.types.EnumValue)2 EnumValue (org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue)2 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)1 AtlasType (org.apache.atlas.type.AtlasType)1 Predicate (org.apache.commons.collections.Predicate)1