3 * Copyright (C) 2009 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.
10 package eu
.etaxonomy
.cdm
.remote
.controller
;
12 import java
.io
.IOException
;
13 import java
.util
.ArrayList
;
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
.WebDataBinder
;
24 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
25 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
27 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
28 import org
.springframework
.web
.servlet
.ModelAndView
;
30 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
31 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
32 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
33 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
35 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
38 * @author a.kohlbecker
43 @RequestMapping(value
= {"/derivedUnitFacade/{uuid}"})
44 public class DerivedUnitFacadeController
extends AbstractController
{
47 private IOccurrenceService service
;
50 public void setService(IOccurrenceService service
) {
51 this.service
= service
;
55 public void initBinder(WebDataBinder binder
) {
56 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
59 @RequestMapping(method
= RequestMethod
.GET
)
60 public DerivedUnitFacade
doGet(
61 @PathVariable("uuid") UUID occurrenceUuid
,
62 HttpServletRequest request
,
63 HttpServletResponse response
) throws IOException
{
65 logger
.info("getGet() - " + request
.getServletPath());
66 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
, null);
70 @RequestMapping(value
= {"derivedUnitMedia"}, method
= RequestMethod
.GET
)
71 public ModelAndView
doGetDerivedUnitMedia(
72 @PathVariable("uuid") UUID occurrenceUuid
,
73 HttpServletRequest request
,
74 HttpServletResponse response
) throws IOException
{
76 logger
.info("doGetDerivedUnitMedia() - " + request
.getServletPath());
77 ModelAndView mv
= new ModelAndView();
78 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
,Arrays
.asList(new String
[]{
79 "derivedUnitMedia", "derivedUnitMedia.title"}));
81 mv
.addObject(duf
.getDerivedUnitMedia());
86 @RequestMapping(value
= {"fieldObjectMedia"}, method
= RequestMethod
.GET
)
87 public ModelAndView
doGetFieldObjectMedia(
88 @PathVariable("uuid") UUID occurrenceUuid
,
89 HttpServletRequest request
,
90 HttpServletResponse response
) throws IOException
{
92 logger
.info("doGetFieldObjectMedia() - " + request
.getServletPath());
93 ModelAndView mv
= new ModelAndView();
94 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
,Arrays
.asList(new String
[]{
95 "fieldObjectMedia", "fieldObjectMedia.title"}));
96 mv
.addObject(duf
.getFieldObjectMedia());
101 //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
103 value
= {"collectingareas"},
104 method
= RequestMethod
.GET
)
105 public Object
doGetCollectingAreas(
106 @PathVariable("uuid") UUID occurrenceUuid
,
107 HttpServletRequest request
,
108 HttpServletResponse response
) throws IOException
{
110 logger
.info("doGetCollectingAreas() - " + request
.getServletPath());
111 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
,
113 Arrays
.asList(new String
[]{"ecology"}));
114 return duf
.getCollectingAreas();
117 @RequestMapping(method
= RequestMethod
.GET
, value
= "collection")
118 public Object
doGetCollection(
119 @PathVariable("uuid") UUID uuid
,
120 HttpServletRequest request
,
121 HttpServletResponse response
) throws IOException
{
123 logger
.info("doGetCollection() - " + request
.getServletPath());
124 DerivedUnitFacade duf
= newFacadeFrom(uuid
,
126 Arrays
.asList(new String
[]{"collection"}));
127 return duf
.getCollection();
132 // public Point getExactLocation() => valueProcessor?
135 // public Collection getCollection() {
136 // public AgentBase getCollector() {
137 // public DerivedUnitBase getDerivedUnit() {
138 // public Map<Language, LanguageString> getDerivedUnitDefinitions(){
139 // public List<Media> getDerivedUnitMedia() {
140 // public Set<DeterminationEvent> getDeterminations() {
141 // public Set<Specimen> getDuplicates(){
142 // public Map<Language, LanguageString> getEcologyAll(){
143 // public Map<Language, LanguageString> getFieldObjectDefinition() {
144 // public List<Media> getFieldObjectMedia() {
145 // public FieldObservation getFieldObservation(){
146 // public GatheringEvent getGatheringEvent() {
147 // public String getGatheringEventDescription() {
148 // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!
149 // public PreservationMethod getPreservationMethod()
150 // public Set<IdentifiableSource> getSources(){
151 // public TaxonNameBase getStoredUnder() {
155 * @param occurrenceUuid
157 * @param extendedInitStrategy
158 * @return the requesed <code>DerivedUnitFacade</code> instance or <code>null</code>
159 * @throws IOException
161 private DerivedUnitFacade
newFacadeFrom(UUID occurrenceUuid
, HttpServletResponse response
, List
<String
> extendedInitStrategy
)
163 List
<String
> initStrategy
= new ArrayList
<String
>(initializationStrategy
);
164 if(extendedInitStrategy
!= null && extendedInitStrategy
.size() > 0){
165 initStrategy
.addAll(extendedInitStrategy
);
167 SpecimenOrObservationBase
<?
> sob
= service
.load(occurrenceUuid
, null);
168 if(sob
instanceof DerivedUnitBase
<?
>){
170 return service
.getDerivedUnitFacade(((DerivedUnitBase
)sob
), initStrategy
);
171 } catch (DerivedUnitFacadeNotSupportedException e
) {
172 logger
.error(e
); //TODO ...
175 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);