Project

General

Profile

Download (5.03 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.remote.dto.namecatalogue;
2
import java.util.AbstractMap;
3
import java.util.ArrayList;
4
import java.util.HashSet;
5
import java.util.Hashtable;
6
import java.util.Iterator;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.Map.Entry;
10
import java.util.Set;
11

    
12

    
13
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
14
import eu.etaxonomy.cdm.remote.dto.common.RemoteResponse;
15

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

    
26

    
27
public class NameSearch implements RemoteResponse {
28

    
29
    private NameSearch.NameSearchRequest request;
30
    private List<NameSearch.NameSearchResponse> response;
31

    
32

    
33
    public NameSearch() {		
34
        this.response = new ArrayList<NameSearch.NameSearchResponse>();
35
    }
36

    
37
    public void setRequest(String q) {
38
        request = new NameSearchRequest();
39
        request.setQuery(q);
40
    }
41

    
42
    public NameSearchRequest getRequest() {
43
        return this.request;
44
    }
45

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

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

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

    
89
    public List<NameSearch.NameSearchResponse> getResponse() {
90
        return this.response;
91
    }
92

    
93
    private NameSearch.NameSearchResponse responseWithtitle(String title) {
94
        for(NameSearch.NameSearchResponse nsres : response) {
95
            if(nsres.getTitle().trim().equals(title.trim())) {
96
                return nsres;
97
            }
98
        }
99
        return null;
100
    }
101

    
102
    public class NameSearchRequest {
103
        private String query;
104
        public NameSearchRequest() {
105
            this.query = "";
106
        }
107

    
108
        public void setQuery(String q) {
109
            this.query = q;
110
        }
111

    
112
        public String getQuery() {
113
            return this.query;
114
        }
115
    }
116

    
117
    public class NameSearchResponse {
118
        private String title;
119
        private String name;
120
        private float score;
121
		private Set<String> nameUuids;
122
        private Set<String> taxonConceptUuids;
123
        private Set<String> acceptedTaxontUuids;
124

    
125
        public NameSearchResponse() {
126
            title = "";
127
            name = "";
128
            score = 0;
129
            nameUuids = new HashSet<String>();
130
            taxonConceptUuids = new HashSet<String>();
131
            acceptedTaxontUuids = new HashSet<String>();
132
        }
133

    
134
        public void setTitle(String title) {
135
            this.title = title;
136
        }
137

    
138
        public String getTitle() {
139
            return this.title;
140
        }
141

    
142
        public void setName(String name) {
143
            this.name = name;
144
        }
145

    
146
        public String getName() {
147
            return this.name;
148
        }
149

    
150
        public float getScore() {
151
			return score;
152
		}
153

    
154
		public void setScore(float score) {
155
			this.score = score;
156
		}
157
		
158
        public void addToNameUuids(String nameUuid) {
159
            nameUuids.add(nameUuid);
160
        }
161

    
162
        public Set<String> getNameUuids() {
163
            return this.nameUuids;
164
        }
165

    
166
        public void addToTaxonConceptUuids(String taxonUuid) {
167
            taxonConceptUuids.add(taxonUuid);
168
        }
169

    
170
        public Set<String> getTaxonConceptUuids() {
171
            return this.taxonConceptUuids;
172
        }
173
        
174
        public void addToAcceptedTaxontUuids(String taxonUuid) {
175
            acceptedTaxontUuids.add(taxonUuid);
176
        }
177

    
178
        public Set<String> getAcceptedTaxonUuids() {
179
            return this.acceptedTaxontUuids;
180
        }
181
    }
182

    
183
}
184

    
185

    
186

    
(3-3/4)