public static Object getTypedValue ( String valueStr , Attribute attr , EntityManager entityManager ) { if ( valueStr == null ) return null ; switch ( attr . getDataType ( ) ) { case BOOL : return Boolean . valueOf ( valueStr ) ; case CATEGORICAL : case FILE : case XREF : EntityType xrefEntity = attr . getRefEntity ( ) ; Object xrefIdValue = getTypedValue ( valueStr , xrefEntity . getIdAttribute ( ) , entityManager ) ; return entityManager . getReference ( xrefEntity , xrefIdValue ) ; case CATEGORICAL_MREF : case MREF : case ONE_TO_MANY : EntityType mrefEntity = attr . getRefEntity ( ) ; List < String > mrefIdStrValues = ListEscapeUtils . toList ( valueStr ) ; return mrefIdStrValues . stream ( ) . map ( mrefIdStrValue -> getTypedValue ( mrefIdStrValue , mrefEntity . getIdAttribute ( ) , entityManager ) ) . map ( mrefIdValue -> entityManager . getReference ( mrefEntity , mrefIdValue ) ) . collect ( toList ( ) ) ; case COMPOUND : throw new IllegalArgumentException ( "Compound attribute has no value" ) ; case DATE : try { return parseLocalDate ( valueStr ) ; } catch ( DateTimeParseException e ) { throw new MolgenisDataException ( format ( FAILED_TO_PARSE_ATTRIBUTE_AS_DATE_MESSAGE , attr . getName ( ) , valueStr ) , e ) ; } case DATE_TIME : try { return parseInstant ( valueStr ) ; } catch ( DateTimeParseException e ) { throw new MolgenisDataException ( format ( FAILED_TO_PARSE_ATTRIBUTE_AS_DATETIME_MESSAGE , attr . getName ( ) , valueStr ) , e ) ; } case DECIMAL : return Double . valueOf ( valueStr ) ; case EMAIL : case ENUM : case HTML : case HYPERLINK : case SCRIPT : case STRING : case TEXT : return valueStr ; case INT : return Integer . valueOf ( valueStr ) ; case LONG : return Long . valueOf ( valueStr ) ; default : throw new UnexpectedEnumException ( attr . getDataType ( ) ) ; } }
Convert a string value to a typed value based on the attribute data type .