Project

General

Profile

Download (4.02 KB) Statistics
| Branch: | Tag: | Revision:
1
package org.bgbm.biovel.drf.client;
2

    
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.Comparator;
6
import java.util.EnumSet;
7
import java.util.List;
8

    
9
import org.bgbm.biovel.drf.checklist.DRFChecklistException;
10
import org.bgbm.biovel.drf.checklist.SearchMode;
11

    
12
import com.wordnik.swagger.annotations.ApiModelProperty;
13

    
14
public class ServiceProviderInfo {
15

    
16
    private String id;
17
    private String label;
18
    private String documentationUrl;
19
    private String copyrightUrl;
20
    private String version;
21
    private List<ServiceProviderInfo> subChecklists = new ArrayList<ServiceProviderInfo>();
22
    protected EnumSet<SearchMode> searchModes;
23

    
24
    /**
25
     * [SearchMode.scientificNameExact]
26
     */
27
    public static final EnumSet<SearchMode> DEFAULT_SEARCH_MODE = EnumSet.of(SearchMode.scientificNameExact);
28

    
29
    public ServiceProviderInfo() {
30
    }
31

    
32
    /**
33
     * Constructor without <code>searchModes</code> parameter, the searchModes
34
     * will be set to the default: <code>[SearchMode.scientificNameExact]</code>
35
     * @param id
36
     * @param label
37
     * @param documentationUrl
38
     */
39
    public ServiceProviderInfo(String id, String label, String documentationUrl) {
40
        this(id,label,documentationUrl,"", DEFAULT_SEARCH_MODE);
41
    }
42

    
43
    /**
44
     *
45
     * @param id
46
     * @param label
47
     * @param documentationUrl
48
     * @param copyrightUrl
49
     * @param searchModes TODO
50
     */
51
    public ServiceProviderInfo(String id, String label, String documentationUrl, String copyrightUrl, EnumSet<SearchMode> searchModes) {
52
        this(id,label,DEFAULT_SEARCH_MODE,documentationUrl, copyrightUrl, "");
53
    }
54

    
55
    /**
56
     *
57
     * @param id
58
     * @param label
59
     * @param searchModes
60
     * @param documentationUrl
61
     * @param copyrightUrl
62
     * @param version
63
     */
64
    public ServiceProviderInfo(String id, String label, EnumSet<SearchMode> searchModes, String documentationUrl, String copyrightUrl, String version) {
65
        this.id = id;
66
        this.label = label;
67
        this.searchModes = searchModes;
68
        this.documentationUrl = documentationUrl;
69
        this.copyrightUrl = copyrightUrl;
70
        this.version = version;
71
    }
72

    
73
    public String getId() {
74
        return id;
75
    }
76

    
77
    public String getLabel() {
78
        return label;
79
    }
80

    
81
    public String getDocumentationUrl() {
82
        return documentationUrl;
83
    }
84

    
85
    public String getCopyrightUrl() {
86
        return copyrightUrl;
87
    }
88

    
89

    
90
    public String getVersion() {
91
        return version;
92
    }
93

    
94
    public void addSubChecklist(ServiceProviderInfo ci) {
95
        subChecklists.add(ci);
96
    }
97

    
98
    public List<ServiceProviderInfo> getSubChecklists() {
99
        if(subChecklists != null && subChecklists.size() > 0) {
100
            Collections.sort(subChecklists,new ServiceProviderInfoComparator());
101
        }
102
        return subChecklists;
103
    }
104

    
105
    public static ServiceProviderInfo create(String[] ciArray) throws DRFChecklistException {
106
        if(ciArray.length != 4) {
107
            throw new DRFChecklistException("Not correct number of elements to create Checklist Info");
108
        }
109
        return new ServiceProviderInfo(ciArray[0],ciArray[1],ciArray[2],ciArray[3], ServiceProviderInfo.DEFAULT_SEARCH_MODE);
110
    }
111

    
112
    public class ServiceProviderInfoComparator implements Comparator<ServiceProviderInfo> {
113
          @Override
114
          public int compare(ServiceProviderInfo spia, ServiceProviderInfo spib) {
115
              return spia.getLabel().compareTo(spib.getLabel());
116
          }
117

    
118
    }
119

    
120
    @Override
121
    public String toString(){
122
        return getId();
123
    }
124

    
125
    /**
126
     * @return the matchModes
127
     */
128
    @ApiModelProperty("Set of the different SearchModes supported by the service provider and client implementation."
129
            + "Possible search modes are: scientificNameExact, scientificNameLike, vernacularName")
130
    public EnumSet<SearchMode> getSearchModes() {
131
        return searchModes;
132
    }
133

    
134
    /**
135
     * @param matchModes the matchModes to set
136
     */
137
    public void setSearchModes(EnumSet<SearchMode> matchModes) {
138
        this.searchModes = matchModes;
139
    }
140

    
141
}
(2-2/2)