3 * Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.remote
.controller
;
12 import java
.io
.IOException
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Arrays
;
15 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import javax
.servlet
.http
.HttpServletRequest
;
20 import javax
.servlet
.http
.HttpServletResponse
;
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
;
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
.IFindTaxaAndNamesConfigurator
;
33 import eu
.etaxonomy
.cdm
.api
.service
.config
.FindTaxaAndNamesConfiguratorImpl
;
34 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
35 import eu
.etaxonomy
.cdm
.api
.service
.search
.SearchResult
;
36 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
37 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
38 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
39 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
40 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
42 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
45 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
46 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
47 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
48 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
51 * TODO write controller documentation
53 * @author a.kohlbecker
57 @RequestMapping(value
= {"/taxon"})
58 public class TaxonListController
extends IdentifiableListController
<TaxonBase
, ITaxonService
> {
65 public TaxonListController(){
67 setInitializationStrategy(Arrays
.asList(new String
[]{"$","name.nomenclaturalReference"}));
71 * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
75 public void setService(ITaxonService service
) {
76 this.service
= service
;
80 private IClassificationService classificationService
;
83 private ITermService termService
;
87 * Find Taxa, Synonyms, Common Names by name, either globally or in a specific geographic area.
89 * URI: <b>/{datasource-name}/portal/taxon/find</b>
92 * the string to query for. Since the wildcard character '*'
93 * internally always is appended to the query string, a search
94 * always compares the query string with the beginning of a name.
95 * - <i>required parameter</i>
97 * the {@link UUID} of a {@link Classification} to which the
98 * search is to be restricted. - <i>optional parameter</i>
100 * restrict the search to a set of geographic {@link NamedArea}s.
101 * The parameter currently takes a list of TDWG area labels.
102 * - <i>optional parameter</i>
104 * the number of the page to be returned, the first page has the
105 * pageNumber = 1 - <i>optional parameter</i>
107 * the maximum number of entities returned per page (can be -1
108 * to return all entities in a single page) - <i>optional parameter</i>
110 * weather to search for instances of {@link Taxon} - <i>optional parameter</i>
112 * weather to search for instances of {@link Synonym} - <i>optional parameter</i>
113 * @param doTaxaByCommonNames
114 * for instances of {@link Taxon} by a common name used - <i>optional parameter</i>
116 * valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
117 * @return a Pager on a list of {@link IdentifiableEntity}s initialized by
118 * the following strategy {@link #SIMPLE_TAXON_INIT_STRATEGY}
119 * @throws IOException
121 @RequestMapping(method
= RequestMethod
.GET
, value
={"findTaxaAndNames"})
122 public Pager
<IdentifiableEntity
> doFindTaxaAndNames(
123 @RequestParam(value
= "query", required
= true) String query
,
124 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
125 @RequestParam(value
= "area", required
= false) Set
<NamedArea
> areas
,
126 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
127 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
128 @RequestParam(value
= "doTaxa", required
= false) Boolean doTaxa
,
129 @RequestParam(value
= "doSynonyms", required
= false) Boolean doSynonyms
,
130 @RequestParam(value
= "doMisappliedNames", required
= false) Boolean doMisappliedNames
,
131 @RequestParam(value
= "doTaxaByCommonNames", required
= false) Boolean doTaxaByCommonNames
,
132 @RequestParam(value
= "matchMode", required
= false) MatchMode matchMode
,
133 HttpServletRequest request
,
134 HttpServletResponse response
139 logger
.info("findTaxaAndNames : " + request
.getRequestURI() + "?" + request
.getQueryString() );
141 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
142 pagerParams
.normalizeAndValidate(response
);
144 IFindTaxaAndNamesConfigurator config
= new FindTaxaAndNamesConfiguratorImpl();
146 config
.setTaxonPropertyPath(initializationStrategy
);
148 config
.setPageNumber(pagerParams
.getPageIndex());
149 config
.setPageSize(pagerParams
.getPageSize());
150 config
.setTitleSearchString(query
);
151 config
.setDoTaxa(doTaxa
!= null ? doTaxa
: Boolean
.FALSE
);
152 config
.setDoSynonyms(doSynonyms
!= null ? doSynonyms
: Boolean
.FALSE
);
153 config
.setDoMisappliedNames(doMisappliedNames
!= null ? doMisappliedNames
: Boolean
.FALSE
);
154 config
.setDoTaxaByCommonNames(doTaxaByCommonNames
!= null ? doTaxaByCommonNames
: Boolean
.FALSE
);
155 config
.setMatchMode(matchMode
!= null ? matchMode
: MatchMode
.BEGINNING
);
156 // config.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY);
157 config
.setNamedAreas(areas
);
158 if(treeUuid
!= null){
159 Classification classification
= classificationService
.find(treeUuid
);
160 config
.setClassification(classification
);
163 return (Pager
<IdentifiableEntity
>) service
.findTaxaAndNames(config
);
170 * @param treeUuid TODO unimplemented in TaxonServiceImpl !!!!
177 * @throws IOException
178 * @throws ParseException
180 @RequestMapping(method
= RequestMethod
.GET
, value
={"findByDescriptionElementFullText"})
181 public Pager
<SearchResult
<TaxonBase
>> dofindByDescriptionElementFullText(
182 @RequestParam(value
= "clazz", required
= false) Class
<?
extends DescriptionElementBase
> clazz
,
183 @RequestParam(value
= "query", required
= true) String queryString
,
184 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
185 @RequestParam(value
= "features", required
= false) UuidList featureUuids
,
186 @RequestParam(value
= "languages", required
= false) List
<Language
> languages
,
187 @RequestParam(value
= "hl", required
= false) Boolean highlighting
,
188 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
189 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
190 HttpServletRequest request
,
191 HttpServletResponse response
193 throws IOException
, ParseException
{
195 logger
.info("findByDescriptionElementFullText : " + request
.getRequestURI() + "?" + request
.getQueryString() );
197 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
198 pagerParams
.normalizeAndValidate(response
);
200 if(highlighting
== null){
201 highlighting
= false;
204 Classification classification
= null;
205 if(treeUuid
!= null){
206 classification
= classificationService
.find(treeUuid
);
209 List
<Feature
> features
= null;
210 if(featureUuids
!= null){
211 features
= new ArrayList
<Feature
>(featureUuids
.size());
212 for(UUID uuid
: featureUuids
){
213 features
.add((Feature
) termService
.find(uuid
));
217 Pager
<SearchResult
<TaxonBase
>> pager
= service
.findByDescriptionElementFullText(
218 clazz
, queryString
, classification
, features
, languages
, highlighting
,
219 pagerParams
.getPageSize(), pagerParams
.getPageIndex(), ((List
<OrderHint
>)null),
220 initializationStrategy
);
224 @RequestMapping(method
= RequestMethod
.GET
, value
={"findByFullText"})
225 public Pager
<SearchResult
<TaxonBase
>> dofindByFullText(
226 @RequestParam(value
= "clazz", required
= false) Class
<?
extends TaxonBase
> clazz
,
227 @RequestParam(value
= "query", required
= true) String queryString
,
228 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
229 @RequestParam(value
= "languages", required
= false) List
<Language
> languages
,
230 @RequestParam(value
= "hl", required
= false) Boolean highlighting
,
231 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
232 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
233 HttpServletRequest request
,
234 HttpServletResponse response
236 throws IOException
, ParseException
{
238 logger
.info("findByFullText : " + request
.getRequestURI() + "?" + request
.getQueryString() );
240 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
241 pagerParams
.normalizeAndValidate(response
);
243 if(highlighting
== null){
244 highlighting
= false;
247 Classification classification
= null;
248 if(treeUuid
!= null){
249 classification
= classificationService
.find(treeUuid
);
252 Pager
<SearchResult
<TaxonBase
>> pager
= service
.findByFullText(clazz
, queryString
, classification
, languages
,
253 highlighting
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), ((List
<OrderHint
>)null),
254 initializationStrategy
);
258 @RequestMapping(method
= RequestMethod
.GET
, value
={"findByEverythingFullText"})
259 public Pager
<SearchResult
<TaxonBase
>> dofindByEverythingFullText(
260 @RequestParam(value
= "clazz", required
= false) Class
<?
extends TaxonBase
> clazz
,
261 @RequestParam(value
= "query", required
= true) String queryString
,
262 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
263 @RequestParam(value
= "languages", required
= false) List
<Language
> languages
,
264 @RequestParam(value
= "hl", required
= false) Boolean highlighting
,
265 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
266 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
267 HttpServletRequest request
,
268 HttpServletResponse response
270 throws IOException
, ParseException
{
272 logger
.info("findByEverythingFullText : " + request
.getRequestURI() + "?" + request
.getQueryString() );
274 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
275 pagerParams
.normalizeAndValidate(response
);
277 if(highlighting
== null){
278 highlighting
= false;
281 Classification classification
= null;
282 if(treeUuid
!= null){
283 classification
= classificationService
.find(treeUuid
);
286 Pager
<SearchResult
<TaxonBase
>> pager
= service
.findByEverythingFullText(
287 queryString
, classification
, languages
, highlighting
,
288 pagerParams
.getPageSize(), pagerParams
.getPageIndex(),
289 ((List
<OrderHint
>)null), initializationStrategy
);