Project

General

Profile

Download (4.89 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.remote.dto.namecatalogue;
2
import java.util.ArrayList;
3
import java.util.HashSet;
4
import java.util.List;
5
import java.util.Set;
6

    
7

    
8
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
9
import eu.etaxonomy.cdm.remote.dto.common.RemoteResponse;
10

    
11
/**
12
 * The class representing the response from the CDM Remote Web Service API to a single name search query.
13
 * All information contained in this class originates from a call to {@link TaxonName taxon names}
14
 * <P>
15
 * 
16
 * @author c.mathew
17
 * @version 1.0
18
 * @since 17-Apr-2012 13:00:43
19
 */
20

    
21

    
22
public class NameSearch implements RemoteResponse {
23

    
24
    private NameSearch.NameSearchRequest request;
25
    private List<NameSearch.NameSearchResponse> response;
26

    
27

    
28
    public NameSearch() {		
29
        this.response = new ArrayList<NameSearch.NameSearchResponse>();
30
    }
31

    
32
    public void setRequest(String q) {
33
        request = new NameSearchRequest();
34
        request.setQuery(q);
35
    }
36

    
37
    public NameSearchRequest getRequest() {
38
        return this.request;
39
    }
40

    
41
    public void addToResponseList(String title, String name, float score, String nameUuid, Set<TaxonBase> taxonBases,Set<TaxonBase> accTaxonBases) {
42

    
43
        NameSearch.NameSearchResponse res = responseWithtitle(title);
44
        if (res == null) {
45
            res = new NameSearch.NameSearchResponse();
46
            res.setTitle(title);
47
            res.setName(name);
48
            res.setScore(score);
49
            response.add(res);
50
        }
51
        res.addToNameUuids(nameUuid);
52
        for (TaxonBase tb : taxonBases) {
53
            res.addToTaxonConceptUuids(tb.getUuid().toString());
54
        }
55
        for (TaxonBase acctb : accTaxonBases) {
56
            res.addToAcceptedTaxontUuids(acctb.getUuid().toString());
57
        }
58
    }
59
    
60
    public void addToResponseList(String title, 
61
    		String name, 
62
    		float score, 
63
    		String nameUuid, 
64
    		String[] taxonBaseUuids,
65
    		String[] accTaxonUuids) {
66

    
67
        NameSearch.NameSearchResponse res = responseWithtitle(title);
68
        if (res == null) {
69
            res = new NameSearch.NameSearchResponse();
70
            res.setTitle(title);
71
            res.setName(name);
72
            res.setScore(score);
73
            response.add(res);
74
        }
75
        res.addToNameUuids(nameUuid);
76
        for (String tbuuid : taxonBaseUuids) {
77
            res.addToTaxonConceptUuids(tbuuid);
78
        }
79
        for (String acctbuuid : accTaxonUuids) {
80
            res.addToAcceptedTaxontUuids(acctbuuid);
81
        }
82
    }
83

    
84
    public List<NameSearch.NameSearchResponse> getResponse() {
85
        return this.response;
86
    }
87

    
88
    private NameSearch.NameSearchResponse responseWithtitle(String title) {
89
        for(NameSearch.NameSearchResponse nsres : response) {
90
            if(nsres.getTitle().trim().equals(title.trim())) {
91
                return nsres;
92
            }
93
        }
94
        return null;
95
    }
96

    
97
    public class NameSearchRequest {
98
        private String query;
99
        public NameSearchRequest() {
100
            this.query = "";
101
        }
102

    
103
        public void setQuery(String q) {
104
            this.query = q;
105
        }
106

    
107
        public String getQuery() {
108
            return this.query;
109
        }
110
    }
111

    
112
    public class NameSearchResponse {
113
        private String title;
114
        private String name;
115
        private float score;
116
		private Set<String> nameUuids;
117
        private Set<String> taxonConceptUuids;
118
        private Set<String> acceptedTaxontUuids;
119

    
120
        public NameSearchResponse() {
121
            title = "";
122
            name = "";
123
            score = 0;
124
            nameUuids = new HashSet<String>();
125
            taxonConceptUuids = new HashSet<String>();
126
            acceptedTaxontUuids = new HashSet<String>();
127
        }
128

    
129
        public void setTitle(String title) {
130
            this.title = title;
131
        }
132

    
133
        public String getTitle() {
134
            return this.title;
135
        }
136

    
137
        public void setName(String name) {
138
            this.name = name;
139
        }
140

    
141
        public String getName() {
142
            return this.name;
143
        }
144

    
145
        public float getScore() {
146
			return score;
147
		}
148

    
149
		public void setScore(float score) {
150
			this.score = score;
151
		}
152
		
153
        public void addToNameUuids(String nameUuid) {
154
            nameUuids.add(nameUuid);
155
        }
156

    
157
        public Set<String> getNameUuids() {
158
            return this.nameUuids;
159
        }
160

    
161
        public void addToTaxonConceptUuids(String taxonUuid) {
162
            taxonConceptUuids.add(taxonUuid);
163
        }
164

    
165
        public Set<String> getTaxonConceptUuids() {
166
            return this.taxonConceptUuids;
167
        }
168
        
169
        public void addToAcceptedTaxontUuids(String taxonUuid) {
170
            acceptedTaxontUuids.add(taxonUuid);
171
        }
172

    
173
        public Set<String> getAcceptedTaxonUuids() {
174
            return this.acceptedTaxontUuids;
175
        }
176
    }
177

    
178
}
179

    
180

    
181

    
(3-3/4)