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
;
15 import java
.util
.UUID
;
17 import javax
.servlet
.http
.HttpServletRequest
;
18 import javax
.servlet
.http
.HttpServletResponse
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
22 import org
.springframework
.stereotype
.Controller
;
23 import org
.springframework
.web
.bind
.WebDataBinder
;
24 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
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
.IDescriptionService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
33 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
34 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
35 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
37 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
38 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
39 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
40 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
45 * This controller is mostly a 1:1 copy of the DescriptionListController
46 * and this provides identical end points which only differ in the depth of the
47 * object graphs returned.
48 * An exception is the doAccumulateDistributions() method, which is not repeated
51 * @author a.kohlbecker
56 @RequestMapping(value
= {"/portal/description"})
57 public class DescriptionListPortalController
extends IdentifiableListController
<DescriptionBase
, IDescriptionService
> {
59 public static final Logger logger
= Logger
.getLogger(DescriptionListPortalController
.class);
62 private ITaxonService taxonService
;
64 protected static final List
<String
> DESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
68 "elements.sources.citation.authorTeam",
69 "elements.sources.nameUsedInSource.originalNameString",
70 "elements.multilanguageText",
73 "name.rank.representations",
74 "name.status.type.representations",
78 protected static final List
<String
> DESCRIPTION_ELEMENT_INIT_STRATEGY
= Arrays
.asList(new String
[]{
81 "sources.citation.authorTeam",
82 "sources.nameUsedInSource.originalNameString",
88 public DescriptionListPortalController() {
90 setInitializationStrategy(DESCRIPTION_INIT_STRATEGY
);
95 private ITermService termService
;
98 * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
102 public void setService(IDescriptionService service
) {
103 this.service
= service
;
108 public void initBinder(WebDataBinder binder
) {
109 super.initBinder(binder
);
110 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<Feature
>(termService
));
122 * @throws IOException
124 @RequestMapping(value
= "/portal/descriptionElement/find", method
= RequestMethod
.GET
)
125 public Pager
<DescriptionElementBase
> doFindDescriptionElements(
126 @RequestParam(value
= "query", required
= true) String queryString
,
127 @RequestParam(value
= "type", required
= false) Class
<?
extends DescriptionElementBase
> type
,
128 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
129 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
130 @RequestParam(value
= "matchMode", required
= false) MatchMode matchMode
,
131 HttpServletRequest request
,
132 HttpServletResponse response
136 logger
.info("doFindDescriptionElements : " + request
.getRequestURI() + "?" + request
.getQueryString() );
138 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
139 pagerParams
.normalizeAndValidate(response
);
141 Pager
<DescriptionElementBase
> pager
= service
.searchElements(type
, queryString
, pageSize
, pageNumber
, null, getInitializationStrategy());
147 * Requires the query parameter "descriptionType" to be present
150 * @param descriptionType
157 * @throws IOException
159 @RequestMapping(value
= "/portal/descriptionElement/byFeature", method
= {RequestMethod
.GET
, RequestMethod
.POST
})
160 public Pager
<DescriptionElementBase
> doPageDescriptionElementsByFeature(
161 @RequestParam(value
= "features", required
= false) DefinedTermBaseList
<Feature
> features
,
162 @RequestParam(value
= "descriptionType", required
= true) Class
<?
extends DescriptionBase
> descriptionType
,
163 @RequestParam(value
= "type", required
= false) Class
<?
extends DescriptionElementBase
> type
,
164 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
165 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
, HttpServletRequest request
,
166 HttpServletResponse response
) throws IOException
{
168 logger
.info("doPageDescriptionElementsByFeature : " + requestPathAndQuery(request
));
170 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
171 pagerParams
.normalizeAndValidate(response
);
173 Pager
<DescriptionElementBase
> pager
= service
.pageDescriptionElements(null, descriptionType
, features
.asSet(),
174 type
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), getInitializationStrategy());
180 * Requires the query parameter "taxon" to be present
190 * @throws IOException
192 @RequestMapping(value
= "/portal/descriptionElement/byTaxon", method
= {RequestMethod
.GET
, RequestMethod
.POST
})
193 public <T
extends DescriptionElementBase
> Pager
<T
> getDescriptionElementsForTaxon(
194 @RequestParam(value
= "taxon", required
= true) UUID taxon_uuid
,
195 @RequestParam(value
= "features", required
= false) DefinedTermBaseList
<Feature
> features
,
196 @RequestParam(value
= "type", required
= false) Class
<T
> type
,
197 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
198 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
, HttpServletRequest request
,
199 HttpServletResponse response
) throws IOException
{
201 logger
.info("getDescriptionElementsForTaxon : " + requestPathAndQuery(request
));
203 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
204 pagerParams
.normalizeAndValidate(response
);
207 if( taxon_uuid
!= null){
209 taxon
= (Taxon
) taxonService
.load(taxon_uuid
);
210 } catch (Exception e
) {
211 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
214 //TODO it seems as if the InitializationStrategy is not appropriate here !!!
215 // see #3728 (DescriptionListPortalController.getDescriptionElementsForTaxon() seems to be using inapproptiate init strategy)
216 if (logger
.isDebugEnabled()){logger
.debug("get pager ...");}
217 Pager
<T
> pager
= service
.pageDescriptionElementsForTaxon(
219 (features
!= null ? features
.asSet() : null),
221 pagerParams
.getPageSize(),
222 pagerParams
.getPageIndex(),
223 DESCRIPTION_ELEMENT_INIT_STRATEGY
225 if (logger
.isDebugEnabled()){logger
.debug("get pager - DONE");}