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 io
.swagger
.annotations
.Api
;
14 import java
.io
.IOException
;
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
.classic
.ParseException
;
23 import org
.hibernate
.search
.spatial
.impl
.Rectangle
;
24 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
25 import org
.springframework
.stereotype
.Controller
;
26 import org
.springframework
.web
.bind
.WebDataBinder
;
27 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
28 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
29 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
30 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
32 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
36 import eu
.etaxonomy
.cdm
.api
.service
.search
.SearchResult
;
37 import eu
.etaxonomy
.cdm
.api
.service
.util
.TaxonRelationshipEdge
;
38 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
39 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
41 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
42 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
43 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
44 import eu
.etaxonomy
.cdm
.remote
.editor
.RectanglePropertyEditor
;
45 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
46 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
49 * TODO write controller documentation
51 * @author a.kohlbecker
56 @RequestMapping(value
= {"/occurrence"})
57 public class OccurrenceListController
extends AbstractIdentifiableListController
<SpecimenOrObservationBase
, IOccurrenceService
> {
61 private ITaxonService taxonService
;
64 private ITermService termService
;
67 * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
71 public void setService(IOccurrenceService service
) {
72 this.service
= service
;
77 public void initBinder(WebDataBinder binder
) {
78 super.initBinder(binder
);
79 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
80 binder
.registerCustomEditor(Rectangle
.class, new RectanglePropertyEditor());
85 * @param relationshipUuids a comma separated list of uuids e.g. CongruentTo; "60974c98-64ab-4574-bb5c-c110f6db634d"
86 * @param relationshipInversUuids a comma separated list of uuids
87 * @param maxDepth null for unlimited
96 value
= {"byAssociatedTaxon"},
97 method
= RequestMethod
.GET
)
98 public Pager
<SpecimenOrObservationBase
> doListByAssociatedTaxon(
99 @RequestParam(value
= "taxonUuid", required
= true) UUID taxonUuid
,
100 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
101 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
102 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
103 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
104 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
105 HttpServletRequest request
,
106 HttpServletResponse response
) throws IOException
{
108 logger
.info("doListByAssociatedTaxon()" + request
.getRequestURI() + "?" + request
.getQueryString());
110 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(relationshipUuids
, relationshipInversUuids
, termService
);
112 Taxon associatedTaxon
= (Taxon
) taxonService
.find(taxonUuid
);
113 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
114 pagerParams
.normalizeAndValidate(response
);
116 List
<OrderHint
> orderHints
= null;
118 return service
.pageByAssociatedTaxon(null, includeRelationships
, associatedTaxon
,
119 maxDepth
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(),
120 orderHints
, getInitializationStrategy());
130 * minx(minlongitute),miny(minlatitute),maxx(maxlongitute),max(
131 * maxlatitute), e.g. 13.112,52.374,13.681,52.641 for the Berlin
134 * @param highlighting
140 * @throws IOException
141 * @throws ParseException
143 @RequestMapping(method
= RequestMethod
.GET
, value
={"findByFullText"})
144 public Pager
<SearchResult
<SpecimenOrObservationBase
>> dofindByFullText(
145 @RequestParam(value
= "clazz", required
= false) Class
<?
extends SpecimenOrObservationBase
<?
>> clazz
,
146 @RequestParam(value
= "query", required
= false) String queryString
,
147 @RequestParam(value
= "bbox", required
= false) Rectangle boundingBox
,
148 @RequestParam(value
= "languages", required
= false) List
<Language
> languages
,
149 @RequestParam(value
= "hl", required
= false) Boolean highlighting
,
150 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
151 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
152 HttpServletRequest request
,
153 HttpServletResponse response
155 throws IOException
, ParseException
{
157 logger
.info("findByFullText : " + request
.getRequestURI() + "?" + request
.getQueryString() );
159 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
160 pagerParams
.normalizeAndValidate(response
);
162 if(highlighting
== null){
163 highlighting
= false;
166 if(queryString
== null && boundingBox
== null) {
167 HttpStatusMessage
.create("Either query or bbox must be given", 400).send(response
);
171 Pager
<SearchResult
<SpecimenOrObservationBase
>> pager
= service
.findByFullText(clazz
, queryString
, boundingBox
, languages
,
172 highlighting
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), ((List
<OrderHint
>)null),
173 initializationStrategy
);