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
.EnumSet
;
14 import java
.util
.HashSet
;
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
.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
.PathVariable
;
27 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
28 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
29 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
35 import eu
.etaxonomy
.cdm
.api
.service
.util
.TaxonRelationshipEdge
;
36 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
.Direction
;
37 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
38 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
41 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
42 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
43 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
44 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
45 import eu
.etaxonomy
.cdm
.remote
.editor
.CdmTypePropertyEditor
;
46 import eu
.etaxonomy
.cdm
.remote
.editor
.MatchModePropertyEditor
;
47 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaPropertyEditor
;
48 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
49 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
52 * TODO write controller documentation
54 * @author a.kohlbecker
58 @RequestMapping(value
= {"/occurrence"})
59 public class OccurrenceListController
extends IdentifiableListController
<SpecimenOrObservationBase
, IOccurrenceService
> {
63 private ITaxonService taxonService
;
66 private ITermService termService
;
69 * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
73 public void setService(IOccurrenceService service
) {
74 this.service
= service
;
79 public void initBinder(WebDataBinder binder
) {
80 super.initBinder(binder
);
81 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
86 * @param relationshipUuids e.g. CongruentTo; "60974c98-64ab-4574-bb5c-c110f6db634d"
87 * @param relationshipInversUuids
88 * @param maxDepth null for unlimited
97 value
= {"byAssociatedTaxon"},
98 method
= RequestMethod
.GET
)
99 public Pager
<SpecimenOrObservationBase
> doListByAssociatedTaxon(
100 @RequestParam(value
= "taxonUuid", required
= true) UUID taxonUuid
,
101 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
102 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
103 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
104 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
105 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
106 HttpServletRequest request
,
107 HttpServletResponse response
) throws IOException
{
109 logger
.info("doListByAssociatedTaxon()" + request
.getServletPath() + "?" + request
.getQueryString());
111 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(relationshipUuids
, relationshipInversUuids
, termService
);
113 Taxon associatedTaxon
= (Taxon
) taxonService
.find(taxonUuid
);
114 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
115 pagerParams
.normalizeAndValidate(response
);
117 List
<OrderHint
> orderHints
= null;
119 return service
.pageByAssociatedTaxon(null, includeRelationships
, associatedTaxon
,
120 maxDepth
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(),
121 orderHints
, DEFAULT_INIT_STRATEGY
);