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
.List
;
15 import java
.util
.UUID
;
17 import javax
.servlet
.http
.HttpServletRequest
;
18 import javax
.servlet
.http
.HttpServletResponse
;
20 import org
.apache
.lucene
.queryParser
.ParseException
;
21 import org
.hibernate
.search
.spatial
.impl
.Rectangle
;
22 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
23 import org
.springframework
.stereotype
.Controller
;
24 import org
.springframework
.web
.bind
.WebDataBinder
;
25 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
27 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
28 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
34 import eu
.etaxonomy
.cdm
.api
.service
.search
.SearchResult
;
35 import eu
.etaxonomy
.cdm
.api
.service
.util
.TaxonRelationshipEdge
;
36 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
39 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
40 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
41 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
42 import eu
.etaxonomy
.cdm
.remote
.editor
.RectanglePropertyEditor
;
43 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
44 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
47 * TODO write controller documentation
49 * @author a.kohlbecker
53 @RequestMapping(value
= {"/occurrence"})
54 public class OccurrenceListController
extends IdentifiableListController
<SpecimenOrObservationBase
, IOccurrenceService
> {
58 private ITaxonService taxonService
;
61 private ITermService termService
;
64 * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
68 public void setService(IOccurrenceService service
) {
69 this.service
= service
;
74 public void initBinder(WebDataBinder binder
) {
75 super.initBinder(binder
);
76 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
77 binder
.registerCustomEditor(Rectangle
.class, new RectanglePropertyEditor());
82 * @param relationshipUuids a comma separated list of uuids e.g. CongruentTo; "60974c98-64ab-4574-bb5c-c110f6db634d"
83 * @param relationshipInversUuids a comma separated list of uuids
84 * @param maxDepth null for unlimited
93 value
= {"byAssociatedTaxon"},
94 method
= RequestMethod
.GET
)
95 public Pager
<SpecimenOrObservationBase
> doListByAssociatedTaxon(
96 @RequestParam(value
= "taxonUuid", required
= true) UUID taxonUuid
,
97 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
98 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
99 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
100 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
101 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
102 HttpServletRequest request
,
103 HttpServletResponse response
) throws IOException
{
105 logger
.info("doListByAssociatedTaxon()" + request
.getRequestURI() + "?" + request
.getQueryString());
107 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(relationshipUuids
, relationshipInversUuids
, termService
);
109 Taxon associatedTaxon
= (Taxon
) taxonService
.find(taxonUuid
);
110 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
111 pagerParams
.normalizeAndValidate(response
);
113 List
<OrderHint
> orderHints
= null;
115 return service
.pageByAssociatedTaxon(null, includeRelationships
, associatedTaxon
,
116 maxDepth
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(),
117 orderHints
, getInitializationStrategy());
127 * minx(minlongitute),miny(minlatitute),maxx(maxlongitute),max(
128 * maxlatitute), e.g. 13.112,52.374,13.681,52.641 for the Berlin
131 * @param highlighting
137 * @throws IOException
138 * @throws ParseException
140 @RequestMapping(method
= RequestMethod
.GET
, value
={"findByFullText"})
141 public Pager
<SearchResult
<SpecimenOrObservationBase
>> dofindByFullText(
142 @RequestParam(value
= "clazz", required
= false) Class
<?
extends SpecimenOrObservationBase
<?
>> clazz
,
143 @RequestParam(value
= "query", required
= false) String queryString
,
144 @RequestParam(value
= "bbox", required
= false) Rectangle boundingBox
,
145 @RequestParam(value
= "languages", required
= false) List
<Language
> languages
,
146 @RequestParam(value
= "hl", required
= false) Boolean highlighting
,
147 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
148 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
149 HttpServletRequest request
,
150 HttpServletResponse response
152 throws IOException
, ParseException
{
154 logger
.info("findByFullText : " + request
.getRequestURI() + "?" + request
.getQueryString() );
156 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
157 pagerParams
.normalizeAndValidate(response
);
159 if(highlighting
== null){
160 highlighting
= false;
163 if(queryString
== null && boundingBox
== null) {
164 HttpStatusMessage
.create("Either query or bbox must be given", 400).send(response
);
168 Pager
<SearchResult
<SpecimenOrObservationBase
>> pager
= service
.findByFullText(clazz
, queryString
, boundingBox
, languages
,
169 highlighting
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), ((List
<OrderHint
>)null),
170 initializationStrategy
);