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;
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations