Project

General

Profile

Revision 5c530881

ID5c5308813ea9af3faa9b36d649e63228ccfe5b21
Parent 60ef4839
Child 54e11d53

Added by Andreas Kohlbecker over 1 year ago

RestrictionConverter converts uuid strings to UUID objetcs which have beed passed as json value

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/converter/RestrictionConverter.java
9 9
package eu.etaxonomy.cdm.remote.converter;
10 10

  
11 11
import java.io.IOException;
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.UUID;
12 15

  
13 16
import org.springframework.core.convert.converter.Converter;
14 17

  
......
38 41
    public Restriction<?> convert(String source) {
39 42

  
40 43
            try {
41
                return objectMapper.readValue(source, Restriction.class);
44
                Restriction restriction = objectMapper.readValue(source, Restriction.class);
45
                // the below loop is detects UUID string representations and converts them to UUIDs
46
                // such conversion is needed for all user types, we are only handling UUIDs here quickly and dirty
47
                // TODO think about the best solution, handle the string to object conversion in
48
                // CdmEntityDaoBase.createRestriction(String propertyName, Object value, MatchMode matchMode) ?
49
                List<Object> convertedValues = new ArrayList<>(restriction.getValues().size());
50
                for(Object val : restriction.getValues()){
51
                    if(val.toString().matches("([a-f\\d]{8}(-[a-f\\d]{4}){3}-[a-f\\d]{12}?)")){
52
                        convertedValues.add(UUID.fromString(val.toString()));
53
                    } else {
54
                        convertedValues.add(val);
55
                    }
56
                }
57
                restriction.setValues(convertedValues);
58
                return restriction ;
42 59
            } catch (JsonParseException | JsonMappingException e) {
43 60
                throw new IllegalArgumentException(e);
44 61
            }catch (IOException e) {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)