Project

General

Profile

Download (2.39 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2013 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.cdm.remote.editor;
10

    
11
import java.util.HashSet;
12
import java.util.List;
13
import java.util.Set;
14
import java.util.UUID;
15

    
16
import org.apache.commons.lang.StringUtils;
17

    
18
import eu.etaxonomy.cdm.api.service.ITermService;
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20

    
21
/**
22
 * This PropertyEditor translates concatenated lists string identifiers into
23
 * {@link DefinedTermBase} instances. The instances can be identified either by
24
 * UUID or by ID The separator for concatenations is the colon: ','
25
 *
26
 * @author a.kohlbecker
27
 * @date Jun 25, 2013
28
 *
29
 * @deprecated see {@link TermBasePropertyEditor}
30
 */
31
@Deprecated
32
public class TermBaseListPropertyEditor<T extends DefinedTermBase<?>> extends TermBasePropertyEditor<T> {
33

    
34
    public TermBaseListPropertyEditor(ITermService termService){
35
        super(termService);
36
    }
37

    
38
    @Override
39
    public void setAsText(String text) {
40

    
41
        List<DefinedTermBase> termList = null;
42

    
43
        String[] tokens = StringUtils.split(text, ',');
44
        if(tokens != null && tokens.length > 0){
45

    
46

    
47
            try{
48
                UUID.fromString(tokens[0]);
49
                // no exception! treat all tokens as UUID
50
                Set<UUID> uuids = new HashSet<UUID>(tokens.length);
51
                for(String token : tokens){
52
                    uuids.add(UUID.fromString(token));
53
                }
54
                termList = termService.find(uuids);
55
            } catch (IllegalArgumentException e1){
56
                try {
57
                    Integer.parseInt(tokens[0]);
58
                    // no exception! treat all tokens as ID
59

    
60
                } catch (IllegalArgumentException e2){
61
                    Set<Integer> ids = new HashSet<Integer>(tokens.length);
62
                    for(String token : tokens){
63
                        ids.add(Integer.parseInt(token));
64
                    }
65
                    termList = termService.findById(ids);
66
                }
67
            }
68

    
69
            if(termList == null){
70
                throw new java.lang.IllegalArgumentException("No TermBase instances found for the supplied list of identifiers " + text);
71
            }
72

    
73
            setValue(termList);
74
        }
75
    }
76

    
77
}
(14-14/18)