use of org.molgenis.data.meta.AttributeType in project molgenis by molgenis.
the class RestService method toEntityValue.
/**
* Converts a HTTP request parameter to a entity value of which the type is defined by the attribute. For file
* attributes persists the file in the file store and persist a file meta data entity.
*
* @param attr attribute
* @param paramValue HTTP parameter value
* @return Object
*/
public Object toEntityValue(Attribute attr, Object paramValue, Object id) {
// Treat empty strings as null
if (paramValue != null && (paramValue instanceof String) && ((String) paramValue).isEmpty()) {
paramValue = null;
}
Object value;
AttributeType attrType = attr.getDataType();
switch(attrType) {
case BOOL:
value = convertBool(attr, paramValue);
break;
case EMAIL:
case ENUM:
case HTML:
case HYPERLINK:
case SCRIPT:
case STRING:
case TEXT:
value = convertString(attr, paramValue);
break;
case CATEGORICAL:
case XREF:
value = convertRef(attr, paramValue);
break;
case CATEGORICAL_MREF:
case MREF:
case ONE_TO_MANY:
value = convertMref(attr, paramValue);
break;
case DATE:
value = convertDate(attr, paramValue);
break;
case DATE_TIME:
value = convertDateTime(attr, paramValue);
break;
case DECIMAL:
value = convertDecimal(attr, paramValue);
break;
case FILE:
value = convertFile(attr, paramValue, id);
break;
case INT:
value = convertInt(attr, paramValue);
break;
case LONG:
value = convertLong(attr, paramValue);
break;
case COMPOUND:
throw new RuntimeException(format("Illegal attribute type [%s]", attrType.toString()));
default:
throw new UnexpectedEnumException(attrType);
}
return value;
}
Aggregations