3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.cdm
.remote
.controller
;
13 import java
.io
.IOException
;
14 import java
.util
.Arrays
;
15 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import javax
.servlet
.http
.HttpServletRequest
;
19 import javax
.servlet
.http
.HttpServletResponse
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
22 import org
.springframework
.stereotype
.Controller
;
23 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
24 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
25 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
26 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
27 import org
.springframework
.web
.servlet
.ModelAndView
;
29 import com
.wordnik
.swagger
.annotations
.Api
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DerivateDTO
;
33 import eu
.etaxonomy
.cdm
.api
.service
.dto
.FieldUnitDTO
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivationEvent
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
36 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
40 * TODO write controller documentation
42 * @author a.kohlbecker
46 @Api("portal_occurrence")
47 @RequestMapping(value
= {"/portal/occurrence/{uuid}"})
48 public class OccurrencePortalController
extends BaseController
<SpecimenOrObservationBase
, IOccurrenceService
>
51 private static final List
<String
> DEFAULT_INIT_STRATEGY
= Arrays
.asList(new String
[]{
56 "derivedFrom.originals.*",
57 "derivedFrom.originals.determinations.taxon",
58 "derivedFrom.gatheringEvent.exactLocation.$",
59 "specimenTypeDesignations.*",
60 "specimenTypeDesignations.citation.*",
61 "specimenTypeDesignations.homotypicalGroup.*",
63 "sequences.annotations",
73 public OccurrencePortalController() {
75 setInitializationStrategy(DEFAULT_INIT_STRATEGY
);
79 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
83 public void setService(IOccurrenceService service
) {
84 this.service
= service
;
87 @RequestMapping(value
= { "derivedFrom" }, method
= RequestMethod
.GET
)
88 public ModelAndView
doGetDerivedFrom(
89 @PathVariable("uuid") UUID uuid
,
90 HttpServletRequest request
,
91 HttpServletResponse response
) throws IOException
{
93 logger
.info("doGetDerivedFrom() " + request
.getRequestURI());
95 ModelAndView mv
= new ModelAndView();
97 List
<String
> initStrategy
= DEFAULT_INIT_STRATEGY
;
99 SpecimenOrObservationBase sob
= getCdmBaseInstance(uuid
, response
, initStrategy
);
100 if(sob
instanceof DerivedUnit
){
101 DerivationEvent derivationEvent
= ((DerivedUnit
)sob
).getDerivedFrom();
102 mv
.addObject(derivationEvent
);
107 @RequestMapping(value
= { "derivateHierarchy" }, method
= RequestMethod
.GET
)
108 public ModelAndView
doGetDerivateHierarchy(
109 @PathVariable("uuid") UUID uuid
,
110 @RequestParam(value
= "taxonUuid", required
= true) UUID taxonUuid
,
111 HttpServletRequest request
,
112 HttpServletResponse response
) throws IOException
{
114 logger
.info("doGetDerivateHierarchy() " + request
.getRequestURI());
116 ModelAndView mv
= new ModelAndView();
118 List
<String
> initStrategy
= DEFAULT_INIT_STRATEGY
;
120 SpecimenOrObservationBase sob
= service
.load(uuid
);
121 if(sob
instanceof FieldUnit
){
122 final FieldUnitDTO assembleDerivateHierarchyDTO
= service
.assembleFieldUnitDTO((FieldUnit
)sob
, taxonUuid
);
123 if(assembleDerivateHierarchyDTO
!=null){
124 mv
.addObject(assembleDerivateHierarchyDTO
);