2 * Copyright (C) 2009 EDIT European Distributed Institute of Taxonomy
3 * http://www.e-taxonomy.eu
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 See LICENSE.TXT at the top of this package for the full license terms.
8 package eu
.etaxonomy
.cdm
.remote
.controller
;
10 import java
.io
.IOException
;
11 import java
.util
.List
;
13 import java
.util
.UUID
;
15 import javax
.servlet
.http
.HttpServletRequest
;
16 import javax
.servlet
.http
.HttpServletResponse
;
18 import org
.apache
.logging
.log4j
.LogManager
;
19 import org
.apache
.logging
.log4j
.Logger
;
20 import org
.hibernate
.search
.spatial
.impl
.Rectangle
;
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
.IOccurrenceService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RectangleDTO
;
33 import eu
.etaxonomy
.cdm
.api
.service
.dto
.SpecimenOrObservationBaseDTO
;
34 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
35 import eu
.etaxonomy
.cdm
.api
.service
.search
.LuceneParseException
;
36 import eu
.etaxonomy
.cdm
.api
.service
.search
.SearchResult
;
37 import eu
.etaxonomy
.cdm
.api
.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
;
47 import io
.swagger
.annotations
.Api
;
50 * TODO write controller documentation
52 * @author a.kohlbecker
57 @RequestMapping(value
= {"/occurrence"})
58 public class OccurrenceListController
extends AbstractIdentifiableListController
<SpecimenOrObservationBase
, IOccurrenceService
> {
60 private static final Logger logger
= LogManager
.getLogger();
63 private ITaxonService taxonService
;
66 private ITermService termService
;
70 public void setService(IOccurrenceService service
) {
71 this.service
= service
;
76 public void initBinder(WebDataBinder binder
) {
77 super.initBinder(binder
);
78 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
79 binder
.registerCustomEditor(Rectangle
.class, new RectanglePropertyEditor());
84 * @param relationshipUuids a comma separated list of uuids e.g. CongruentTo; "60974c98-64ab-4574-bb5c-c110f6db634d"
85 * @param relationshipInversUuids a comma separated list of uuids
86 * @param maxDepth null for unlimited
89 value
= {"byAssociatedTaxon"},
90 method
= RequestMethod
.GET
)
91 public Pager
<SpecimenOrObservationBase
> doListByAssociatedTaxon(
92 @RequestParam(value
= "taxonUuid", required
= true) UUID taxonUuid
,
93 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
94 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
95 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
96 @RequestParam(value
= "pageIndex", required
= false) Integer pageIndex
,
97 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
98 HttpServletRequest request
,
99 HttpServletResponse response
) throws IOException
{
101 logger
.info("doListByAssociatedTaxon()" + requestPathAndQuery(request
));
102 boolean includeUnpublished
= NO_UNPUBLISHED
;
104 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(relationshipUuids
, relationshipInversUuids
, termService
);
106 Taxon associatedTaxon
= (Taxon
) taxonService
.find(taxonUuid
);
107 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageIndex
);
108 pagerParams
.normalizeAndValidate(response
);
110 List
<OrderHint
> orderHints
= null;
112 return service
.pageByAssociatedTaxon(null, includeRelationships
, associatedTaxon
,
113 includeUnpublished
, maxDepth
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(),
114 orderHints
, getInitializationStrategy());
117 @RequestMapping(value
= "rootUnitDTOsByAssociatedTaxon", method
= RequestMethod
.GET
)
118 public List
<SpecimenOrObservationBaseDTO
> doListlistRootUnitDTOsByAssociatedTaxon(
119 @RequestParam(value
= "uuid", required
= true) UUID uuid
,
120 HttpServletRequest request
,
121 HttpServletResponse response
) {
122 logger
.info("doListlistRootUnitDTOByAssociatedTaxon() - " + requestPathAndQuery(request
));
124 boolean includeUnpublished
= NO_UNPUBLISHED
;
125 List
<SpecimenOrObservationBaseDTO
> sobDTOs
= service
.listRootUnitDTOsByAssociatedTaxon(
126 null, uuid
, includeUnpublished
, OccurrenceController
.DERIVED_UNIT_INIT_STRATEGY
);
134 * minx(minlongitute),miny(minlatitute),maxx(maxlongitute),max(
135 * maxlatitute), e.g. 13.112,52.374,13.681,52.641 for the Berlin
138 @RequestMapping(method
= RequestMethod
.GET
, value
={"findByFullText"})
139 public Pager
<SearchResult
<SpecimenOrObservationBase
>> doFindByFullText(
140 @RequestParam(value
= "clazz", required
= false) Class
<?
extends SpecimenOrObservationBase
<?
>> clazz
,
141 @RequestParam(value
= "query", required
= false) String queryString
,
142 @RequestParam(value
= "bbox", required
= false) RectangleDTO boundingBox
,
143 @RequestParam(value
= "languages", required
= false) List
<Language
> languages
,
144 @RequestParam(value
= "hl", required
= false) Boolean highlighting
,
145 @RequestParam(value
= "pageIndex", required
= false) Integer pageIndex
,
146 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
147 HttpServletRequest request
,
148 HttpServletResponse response
150 throws IOException
, LuceneParseException
{
152 logger
.info("doFindByFullText() " + requestPathAndQuery(request
) );
154 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageIndex
);
155 pagerParams
.normalizeAndValidate(response
);
157 if(highlighting
== null){
158 highlighting
= false;
161 if(queryString
== null && boundingBox
== null) {
162 HttpStatusMessage
.create("Either query or bbox must be given", 400).send(response
);
166 Pager
<SearchResult
<SpecimenOrObservationBase
>> pager
= service
.findByFullText(clazz
, queryString
, boundingBox
, languages
,
167 highlighting
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), ((List
<OrderHint
>)null),
168 initializationStrategy
);
172 @RequestMapping(method
= RequestMethod
.GET
, value
= "byGeneticAccessionNumber" )
173 public SpecimenOrObservationBaseDTO
doGetByGeneticAccessionNumber(
174 @RequestParam(value
="accessionNumber", required
= true) String accessionNumber
,
175 HttpServletRequest request
,
176 HttpServletResponse response
) throws IOException
{
177 logger
.info("doGetByGeneticAccessionNumber() - " + requestPathAndQuery(request
));
179 SpecimenOrObservationBaseDTO sobDto
= service
.findByGeneticAccessionNumber(accessionNumber
, null);
180 if(sobDto
== null ) {
181 response
.setHeader("Failure", "No DNA available for accession number ");
182 HttpStatusMessage
.create("No DNA available for accession number " + accessionNumber
, 400).send(response
);