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
.Arrays
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import javax
.servlet
.http
.HttpServletRequest
;
19 import javax
.servlet
.http
.HttpServletResponse
;
21 import org
.apache
.lucene
.queryParser
.ParseException
;
22 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
23 import org
.springframework
.stereotype
.Controller
;
24 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
25 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
26 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
28 import eu
.etaxonomy
.cdm
.api
.service
.IClassificationService
;
29 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.config
.ITaxonServiceConfigurator
;
31 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonServiceConfiguratorImpl
;
32 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
33 import eu
.etaxonomy
.cdm
.api
.service
.search
.SearchResult
;
34 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
35 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
36 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
37 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
42 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
43 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
44 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
47 * TODO write controller documentation
49 * @author a.kohlbecker
53 @RequestMapping(value
= {"/taxon"})
54 public class TaxonListController
extends IdentifiableListController
<TaxonBase
, ITaxonService
> {
61 public TaxonListController(){
63 setInitializationStrategy(Arrays
.asList(new String
[]{"$","name.nomenclaturalReference"}));
67 * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
71 public void setService(ITaxonService service
) {
72 this.service
= service
;
76 private IClassificationService classificationService
;
79 * Find Taxa, Synonyms, Common Names by name, either globally or in a specific geographic area.
81 * URI: <b>/{datasource-name}/portal/taxon/find</b>
84 * the string to query for. Since the wildcard character '*'
85 * internally always is appended to the query string, a search
86 * always compares the query string with the beginning of a name.
87 * - <i>required parameter</i>
89 * the {@link UUID} of a {@link Classification} to which the
90 * search is to be restricted. - <i>optional parameter</i>
92 * restrict the search to a set of geographic {@link NamedArea}s.
93 * The parameter currently takes a list of TDWG area labels.
94 * - <i>optional parameter</i>
96 * the number of the page to be returned, the first page has the
97 * pageNumber = 1 - <i>optional parameter</i>
99 * the maximum number of entities returned per page (can be -1
100 * to return all entities in a single page) - <i>optional parameter</i>
102 * weather to search for instances of {@link Taxon} - <i>optional parameter</i>
104 * weather to search for instances of {@link Synonym} - <i>optional parameter</i>
105 * @param doTaxaByCommonNames
106 * for instances of {@link Taxon} by a common name used - <i>optional parameter</i>
108 * valid values are "EXACT", "BEGINNING", "ANYWHERE", "END" (case sensitive !!!)
109 * @return a Pager on a list of {@link IdentifiableEntity}s initialized by
110 * the following strategy {@link #SIMPLE_TAXON_INIT_STRATEGY}
111 * @throws IOException
113 @RequestMapping(method
= RequestMethod
.GET
, value
={"findTaxaAndNames"})
114 public Pager
<IdentifiableEntity
> doFindTaxaAndNames(
115 @RequestParam(value
= "query", required
= true) String query
,
116 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
117 @RequestParam(value
= "area", required
= false) Set
<NamedArea
> areas
,
118 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
119 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
120 @RequestParam(value
= "doTaxa", required
= false) Boolean doTaxa
,
121 @RequestParam(value
= "doSynonyms", required
= false) Boolean doSynonyms
,
122 @RequestParam(value
= "doMisappliedNames", required
= false) Boolean doMisappliedNames
,
123 @RequestParam(value
= "doTaxaByCommonNames", required
= false) Boolean doTaxaByCommonNames
,
124 @RequestParam(value
= "matchMode", required
= false) MatchMode matchMode
,
125 HttpServletRequest request
,
126 HttpServletResponse response
131 logger
.info("findTaxaAndNames : " + request
.getRequestURI() + "?" + request
.getQueryString() );
133 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
134 pagerParams
.normalizeAndValidate(response
);
136 ITaxonServiceConfigurator config
= new TaxonServiceConfiguratorImpl();
138 config
.setTaxonPropertyPath(initializationStrategy
);
140 config
.setPageNumber(pagerParams
.getPageIndex());
141 config
.setPageSize(pagerParams
.getPageSize());
142 config
.setTitleSearchString(query
);
143 config
.setDoTaxa(doTaxa
!= null ? doTaxa
: Boolean
.FALSE
);
144 config
.setDoSynonyms(doSynonyms
!= null ? doSynonyms
: Boolean
.FALSE
);
145 config
.setDoMisappliedNames(doMisappliedNames
!= null ? doMisappliedNames
: Boolean
.FALSE
);
146 config
.setDoTaxaByCommonNames(doTaxaByCommonNames
!= null ? doTaxaByCommonNames
: Boolean
.FALSE
);
147 config
.setMatchMode(matchMode
!= null ? matchMode
: MatchMode
.BEGINNING
);
148 // config.setTaxonPropertyPath(SIMPLE_TAXON_INIT_STRATEGY);
149 config
.setNamedAreas(areas
);
150 if(treeUuid
!= null){
151 Classification classification
= classificationService
.find(treeUuid
);
152 config
.setClassification(classification
);
155 return (Pager
<IdentifiableEntity
>) service
.findTaxaAndNames(config
);
162 * @param treeUuid TODO unimplemented in TaxonServiceImpl !!!!
169 * @throws IOException
170 * @throws ParseException
172 @RequestMapping(method
= RequestMethod
.GET
, value
={"findByDescriptionElementFullText"})
173 public Pager
<SearchResult
<TaxonBase
>> dofindByDescriptionElementFullText(
174 @RequestParam(value
= "clazz", required
= false) Class clazz
,
175 @RequestParam(value
= "query", required
= true) String queryString
,
176 @RequestParam(value
= "tree", required
= false) UUID treeUuid
,
177 @RequestParam(value
= "languages", required
= false) List
<Language
> languages
,
178 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
179 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
180 HttpServletRequest request
,
181 HttpServletResponse response
183 throws IOException
, ParseException
{
185 logger
.info("findByDescriptionElementFullText : " + request
.getRequestURI() + "?" + request
.getQueryString() );
187 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
188 pagerParams
.normalizeAndValidate(response
);
190 Classification classification
= null;
191 if(treeUuid
!= null){
192 classification
= classificationService
.find(treeUuid
);
194 Pager
<SearchResult
<TaxonBase
>> pager
= service
.findByDescriptionElementFullText(clazz
, queryString
, classification
, languages
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), ((List
<OrderHint
>)null), initializationStrategy
);