1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT 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
|
7
|
* 1.1 See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.remote.controller;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import javax.servlet.http.HttpServletRequest;
|
20
|
import javax.servlet.http.HttpServletResponse;
|
21
|
|
22
|
import org.apache.lucene.queryParser.ParseException;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Controller;
|
25
|
import org.springframework.web.bind.annotation.RequestMapping;
|
26
|
import org.springframework.web.bind.annotation.RequestMethod;
|
27
|
import org.springframework.web.bind.annotation.RequestParam;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
30
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
31
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
32
|
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
|
33
|
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
|
34
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
35
|
import eu.etaxonomy.cdm.api.service.search.LuceneMultiSearchException;
|
36
|
import eu.etaxonomy.cdm.api.service.search.SearchResult;
|
37
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
38
|
import eu.etaxonomy.cdm.model.common.Language;
|
39
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
40
|
import eu.etaxonomy.cdm.model.description.Feature;
|
41
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
42
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
43
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
44
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
45
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
46
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
47
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
48
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
49
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
50
|
|
51
|
/**
|
52
|
* TODO write controller documentation
|
53
|
*
|
54
|
* @author a.kohlbecker
|
55
|
* @date 20.03.2009
|
56
|
*/
|
57
|
@Controller
|
58
|
@RequestMapping(value = {"/taxon"})
|
59
|
public class TaxonListController extends IdentifiableListController<TaxonBase, ITaxonService> {
|
60
|
|
61
|
|
62
|
|
63
|
/**
|
64
|
*
|
65
|
*/
|
66
|
public TaxonListController(){
|
67
|
super();
|
68
|
setInitializationStrategy(Arrays.asList(new String[]{"$","name.nomenclaturalReference"}));
|
69
|
}
|
70
|
|
71
|
/* (non-Javadoc)
|
72
|
* @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
|
73
|
*/
|
74
|
@Override
|
75
|
@Autowired
|
76
|
public void setService(ITaxonService service) {
|
77
|
this.service = service;
|
78
|
}
|
79
|
|
80
|
@Autowired
|
81
|
private IClassificationService classificationService;
|
82
|
|
83
|
@Autowired
|
84
|
private ITermService termService;
|
85
|
|
86
|
|
87
|
/**
|
88
|
* Find Taxa, Synonyms, Common Names by name, either globally or in a specific geographic area.
|
89
|
* <p>
|
90
|
* URI: <b>/{datasource-name}/portal/taxon/find</b>
|
91
|
*
|
92
|
* @param query
|
93
|
* the string to query for. Since the wildcard character '*'
|
94
|
* internally always is appended to the query string, a search
|
95
|
* always compares the query string with the beginning of a name.
|
96
|
* - <i>required parameter</i>
|
97
|
* @param treeUuid
|
98
|
* the {@link UUID} of a {@link Classification} to which the
|
99
|
* search is to be restricted. - <i>optional parameter</i>
|
100
|
* @param areas
|
101
|
* restrict the search to a set of geographic {@link NamedArea}s.
|
102
|
* The parameter currently takes a list of TDWG area labels.
|
103
|
* - <i>optional parameter</i>
|
104
|
* @param pageNumber
|
105
|
* the number of the page to be returned, the first page has the
|
106
|
* pageNumber = 1 - <i>optional parameter</i>
|
107
|
* @param pageSize
|
108
|
* the maximum number of entities returned per page (can be -1
|
109
|
* to return all entities in a single page) - <i>optional parameter</i>
|
110
|
* @param doTaxa
|
111
|
* weather to search for instances of {@link Taxon} - <i>optional parameter</i>
|
112
|
* @param doSynonyms
|
113
|
* weather to search for instances of {@link Synonym} - <i>optional parameter</i>
|
114
|
* @param doTaxaByCommonNames
|
115
|
* for instances of {@link Taxon} by a common name used - <i>optional parameter</i>
|
116
|
* @param matchMode
|
117
|
* valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
|
118
|
* @return a Pager on a list of {@link IdentifiableEntity}s initialized by
|
119
|
* the following strategy {@link #SIMPLE_TAXON_INIT_STRATEGY}
|
120
|
* @throws IOException
|
121
|
*/
|
122
|
@RequestMapping(method = RequestMethod.GET, value={"findTaxaAndNames"})
|
123
|
public Pager<IdentifiableEntity> doFindTaxaAndNames(
|
124
|
@RequestParam(value = "query", required = true) String query,
|
125
|
@RequestParam(value = "tree", required = false) UUID treeUuid,
|
126
|
@RequestParam(value = "area", required = false) Set<NamedArea> areas,
|
127
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
128
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
129
|
@RequestParam(value = "doTaxa", required = false) Boolean doTaxa,
|
130
|
@RequestParam(value = "doSynonyms", required = false) Boolean doSynonyms,
|
131
|
@RequestParam(value = "doMisappliedNames", required = false) Boolean doMisappliedNames,
|
132
|
@RequestParam(value = "doTaxaByCommonNames", required = false) Boolean doTaxaByCommonNames,
|
133
|
@RequestParam(value = "matchMode", required = false) MatchMode matchMode,
|
134
|
HttpServletRequest request,
|
135
|
HttpServletResponse response
|
136
|
)
|
137
|
throws IOException {
|
138
|
|
139
|
|
140
|
logger.info("findTaxaAndNames : " + request.getRequestURI() + "?" + request.getQueryString() );
|
141
|
|
142
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
143
|
pagerParams.normalizeAndValidate(response);
|
144
|
|
145
|
IFindTaxaAndNamesConfigurator config = new FindTaxaAndNamesConfiguratorImpl();
|
146
|
|
147
|
config.setTaxonPropertyPath(initializationStrategy);
|
148
|
|
149
|
config.setPageNumber(pagerParams.getPageIndex());
|
150
|
config.setPageSize(pagerParams.getPageSize());
|
151
|
config.setTitleSearchString(query);
|
152
|
config.setDoTaxa(doTaxa!= null ? doTaxa : Boolean.FALSE );
|
153
|
config.setDoSynonyms(doSynonyms != null ? doSynonyms : Boolean.FALSE );
|
154
|
config.setDoMisappliedNames(doMisappliedNames != null ? doMisappliedNames : Boolean.FALSE);
|
155
|
config.setDoTaxaByCommonNames(doTaxaByCommonNames != null ? doTaxaByCommonNames : Boolean.FALSE );
|
156
|
config.setMatchMode(matchMode != null ? matchMode : MatchMode.BEGINNING);
|
157
|
// config.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY);
|
158
|
config.setNamedAreas(areas);
|
159
|
if(treeUuid != null){
|
160
|
Classification classification = classificationService.find(treeUuid);
|
161
|
config.setClassification(classification);
|
162
|
}
|
163
|
|
164
|
return service.findTaxaAndNames(config);
|
165
|
|
166
|
}
|
167
|
|
168
|
/**
|
169
|
* @param clazz
|
170
|
* @param queryString
|
171
|
* @param treeUuid TODO unimplemented in TaxonServiceImpl !!!!
|
172
|
* @param languages
|
173
|
* @param pageNumber
|
174
|
* @param pageSize
|
175
|
* @param request
|
176
|
* @param response
|
177
|
* @return
|
178
|
* @throws IOException
|
179
|
* @throws ParseException
|
180
|
*/
|
181
|
@RequestMapping(method = RequestMethod.GET, value={"findByDescriptionElementFullText"})
|
182
|
public Pager<SearchResult<TaxonBase>> dofindByDescriptionElementFullText(
|
183
|
@RequestParam(value = "clazz", required = false) Class<? extends DescriptionElementBase> clazz,
|
184
|
@RequestParam(value = "query", required = true) String queryString,
|
185
|
@RequestParam(value = "tree", required = false) UUID treeUuid,
|
186
|
@RequestParam(value = "features", required = false) UuidList featureUuids,
|
187
|
@RequestParam(value = "languages", required = false) List<Language> languages,
|
188
|
@RequestParam(value = "hl", required = false) Boolean highlighting,
|
189
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
190
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
191
|
HttpServletRequest request,
|
192
|
HttpServletResponse response
|
193
|
)
|
194
|
throws IOException, ParseException {
|
195
|
|
196
|
logger.info("findByDescriptionElementFullText : " + request.getRequestURI() + "?" + request.getQueryString() );
|
197
|
|
198
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
199
|
pagerParams.normalizeAndValidate(response);
|
200
|
|
201
|
if(highlighting == null){
|
202
|
highlighting = false;
|
203
|
}
|
204
|
|
205
|
Classification classification = null;
|
206
|
if(treeUuid != null){
|
207
|
classification = classificationService.find(treeUuid);
|
208
|
}
|
209
|
|
210
|
List<Feature> features = null;
|
211
|
if(featureUuids != null){
|
212
|
features = new ArrayList<Feature>(featureUuids.size());
|
213
|
for(UUID uuid : featureUuids){
|
214
|
features.add((Feature) termService.find(uuid));
|
215
|
}
|
216
|
}
|
217
|
|
218
|
Pager<SearchResult<TaxonBase>> pager = service.findByDescriptionElementFullText(
|
219
|
clazz, queryString, classification, features, languages, highlighting,
|
220
|
pagerParams.getPageSize(), pagerParams.getPageIndex(), ((List<OrderHint>)null),
|
221
|
initializationStrategy);
|
222
|
return pager;
|
223
|
}
|
224
|
|
225
|
@RequestMapping(method = RequestMethod.GET, value={"findByFullText"})
|
226
|
public Pager<SearchResult<TaxonBase>> dofindByFullText(
|
227
|
@RequestParam(value = "clazz", required = false) Class<? extends TaxonBase> clazz,
|
228
|
@RequestParam(value = "query", required = true) String queryString,
|
229
|
@RequestParam(value = "tree", required = false) UUID treeUuid,
|
230
|
@RequestParam(value = "languages", required = false) List<Language> languages,
|
231
|
@RequestParam(value = "hl", required = false) Boolean highlighting,
|
232
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
233
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
234
|
HttpServletRequest request,
|
235
|
HttpServletResponse response
|
236
|
)
|
237
|
throws IOException, ParseException {
|
238
|
|
239
|
logger.info("findByFullText : " + request.getRequestURI() + "?" + request.getQueryString() );
|
240
|
|
241
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
242
|
pagerParams.normalizeAndValidate(response);
|
243
|
|
244
|
if(highlighting == null){
|
245
|
highlighting = false;
|
246
|
}
|
247
|
|
248
|
Classification classification = null;
|
249
|
if(treeUuid != null){
|
250
|
classification = classificationService.find(treeUuid);
|
251
|
}
|
252
|
|
253
|
Pager<SearchResult<TaxonBase>> pager = service.findByFullText(clazz, queryString, classification, languages,
|
254
|
highlighting, pagerParams.getPageSize(), pagerParams.getPageIndex(), ((List<OrderHint>)null),
|
255
|
initializationStrategy);
|
256
|
return pager;
|
257
|
}
|
258
|
|
259
|
@RequestMapping(method = RequestMethod.GET, value={"findByEverythingFullText"})
|
260
|
public Pager<SearchResult<TaxonBase>> dofindByEverythingFullText(
|
261
|
@RequestParam(value = "clazz", required = false) Class<? extends TaxonBase> clazz,
|
262
|
@RequestParam(value = "query", required = true) String queryString,
|
263
|
@RequestParam(value = "tree", required = false) UUID treeUuid,
|
264
|
@RequestParam(value = "languages", required = false) List<Language> languages,
|
265
|
@RequestParam(value = "hl", required = false) Boolean highlighting,
|
266
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
267
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
268
|
HttpServletRequest request,
|
269
|
HttpServletResponse response
|
270
|
)
|
271
|
throws IOException, ParseException, LuceneMultiSearchException {
|
272
|
|
273
|
logger.info("findByEverythingFullText : " + request.getRequestURI() + "?" + request.getQueryString() );
|
274
|
|
275
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
276
|
pagerParams.normalizeAndValidate(response);
|
277
|
|
278
|
if(highlighting == null){
|
279
|
highlighting = false;
|
280
|
}
|
281
|
|
282
|
Classification classification = null;
|
283
|
if(treeUuid != null){
|
284
|
classification = classificationService.find(treeUuid);
|
285
|
}
|
286
|
|
287
|
Pager<SearchResult<TaxonBase>> pager = service.findByEverythingFullText(
|
288
|
queryString, classification, languages, highlighting,
|
289
|
pagerParams.getPageSize(), pagerParams.getPageIndex(),
|
290
|
((List<OrderHint>)null), initializationStrategy);
|
291
|
return pager;
|
292
|
}
|
293
|
}
|