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
.PagerParameters
;
44 import eu
.etaxonomy
.cdm
.remote
.editor
.CdmTypePropertyEditor
;
45 import eu
.etaxonomy
.cdm
.remote
.editor
.MatchModePropertyEditor
;
46 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaPropertyEditor
;
47 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
48 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
51 * TODO write controller documentation
53 * @author a.kohlbecker
57 @RequestMapping(value
= {"/occurrence"})
58 public class OccurrenceListController
extends IdentifiableListController
<SpecimenOrObservationBase
, IOccurrenceService
> {
62 private ITaxonService taxonService
;
65 private ITermService termService
;
68 * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)
72 public void setService(IOccurrenceService service
) {
73 this.service
= service
;
78 public void initBinder(WebDataBinder binder
) {
79 super.initBinder(binder
);
80 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
85 * @param relationshipUuids e.g. CongruentTo; "60974c98-64ab-4574-bb5c-c110f6db634d"
86 * @param relationshipInversUuids
87 * @param maxDepth null for unlimited
96 value
= {"byAssociatedTaxon"},
97 method
= RequestMethod
.GET
)
98 public List
<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 Set
<TaxonRelationshipEdge
> includeRelationships
= null;
109 if(relationshipUuids
!= null || relationshipInversUuids
!= null){
110 includeRelationships
= new HashSet
<TaxonRelationshipEdge
>();
111 if(relationshipUuids
!= null) {
112 for (UUID uuid
: relationshipUuids
) {
113 if(relationshipInversUuids
!= null && relationshipInversUuids
.contains(uuid
)){
114 includeRelationships
.add(new TaxonRelationshipEdge((TaxonRelationshipType
) termService
.find(uuid
), Direction
.relatedTo
, Direction
.relatedFrom
));
115 relationshipInversUuids
.remove(uuid
);
117 includeRelationships
.add(new TaxonRelationshipEdge((TaxonRelationshipType
) termService
.find(uuid
), Direction
.relatedTo
));
121 if(relationshipInversUuids
!= null) {
122 for (UUID uuid
: relationshipInversUuids
) {
123 includeRelationships
.add(new TaxonRelationshipEdge((TaxonRelationshipType
) termService
.find(uuid
), Direction
.relatedFrom
));
128 Taxon associatedTaxon
= (Taxon
) taxonService
.find(taxonUuid
);
129 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
130 pagerParams
.normalizeAndValidate(response
);
132 List
<OrderHint
> orderHints
= null;
134 return service
.listByAssociatedTaxon(null, includeRelationships
, associatedTaxon
,
135 maxDepth
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(),
136 orderHints
, DEFAULT_INIT_STRATEGY
);