Project

General

Profile

Download (5.05 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.dto.namecatalogue;
10

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

    
16
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
17
import eu.etaxonomy.cdm.remote.dto.common.RemoteResponse;
18

    
19
/**
20
 * The class representing the response from the CDM Remote Web Service API to a single name search query.
21
 * All information contained in this class originates from a call to {@link TaxonName taxon names}
22
 * <P>
23
 *
24
 * @author c.mathew
25
 * @since 17-Apr-2012 13:00:43
26
 */
27
public class NameSearch implements RemoteResponse {
28

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

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

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

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

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

    
47
        NameSearch.NameSearchResponse res = responseWithtitle(title);
48
        if (res == null) {
49
            res = new NameSearch.NameSearchResponse();
50
            res.setTitle(title);
51
            res.setName(name);
52
            res.setScore(score);
53
            response.add(res);
54
        }
55
        res.addToNameUuids(nameUuid);
56
        for (TaxonBase tb : taxonBases) {
57
            res.addToTaxonConceptUuids(tb.getUuid().toString());
58
        }
59
        for (TaxonBase acctb : accTaxonBases) {
60
            res.addToAcceptedTaxontUuids(acctb.getUuid().toString());
61
        }
62
    }
63

    
64
    public void addToResponseList(String title,
65
    		String name,
66
    		float score,
67
    		String nameUuid,
68
    		String[] taxonBaseUuids,
69
    		String[] accTaxonUuids) {
70

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

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

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

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

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

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

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

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

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

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

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

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

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

    
153
		public void setScore(float score) {
154
			this.score = score;
155
		}
156

    
157
        public void addToNameUuids(String nameUuid) {
158
            nameUuids.add(nameUuid);
159
        }
160

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

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

    
169
        public Set<String> getTaxonConceptUuids() {
170
            return this.taxonConceptUuids;
171
        }
172

    
173
        public void addToAcceptedTaxontUuids(String taxonUuid) {
174
            acceptedTaxontUuids.add(taxonUuid);
175
        }
176

    
177
        public Set<String> getAcceptedTaxonUuids() {
178
            return this.acceptedTaxontUuids;
179
        }
180
    }
181
}
(3-3/4)