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
.media
.Media
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnitBase
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
36 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
39 * @author a.kohlbecker
44 @RequestMapping(value
= {"/derivedUnitFacade/{uuid}"})
45 public class DerivedUnitFacadeController
extends AbstractController
{
48 private IOccurrenceService service
;
51 public void setService(IOccurrenceService service
) {
52 this.service
= service
;
56 public void initBinder(WebDataBinder binder
) {
57 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
60 @RequestMapping(method
= RequestMethod
.GET
)
61 public DerivedUnitFacade
doGet(
62 @PathVariable("uuid") UUID uuid
,
63 HttpServletRequest request
,
64 HttpServletResponse response
) throws IOException
{
66 logger
.info("getGet() - " + request
.getServletPath());
67 DerivedUnitFacade duf
= newFacadeFrom(uuid
, response
, null);
71 @RequestMapping(value
= {"derivedUnitMedia"}, method
= RequestMethod
.GET
)
72 public ModelAndView
doGetDerivedUnitMedia(
73 @PathVariable("uuid") UUID uuid
,
74 HttpServletRequest request
,
75 HttpServletResponse response
) throws IOException
{
77 logger
.info("doGetDerivedUnitMedia() - " + request
.getServletPath());
78 ModelAndView mv
= new ModelAndView();
79 DerivedUnitFacade duf
= newFacadeFrom(uuid
, response
,Arrays
.asList(new String
[]{
80 "derivedUnitMedia.representations.parts", "derivedUnitMedia.title"}));
81 mv
.addObject(duf
.getDerivedUnitMedia());
85 @RequestMapping(value
= {"fieldObjectMedia"}, method
= RequestMethod
.GET
)
86 public ModelAndView
doGetFieldObjectMedia(
87 @PathVariable("uuid") UUID uuid
,
88 HttpServletRequest request
,
89 HttpServletResponse response
) throws IOException
{
91 logger
.info("doGetFieldObjectMedia() - " + request
.getServletPath());
92 ModelAndView mv
= new ModelAndView();
93 DerivedUnitFacade duf
= newFacadeFrom(uuid
, response
,Arrays
.asList(new String
[]{
94 "fieldObjectMedia.representations.parts", "fieldObjectMedia.title"}));
95 mv
.addObject(duf
.getFieldObjectMedia());
100 //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
102 value
= {"collectingareas"},
103 method
= RequestMethod
.GET
)
104 public Object
doGetCollectingAreas(
105 @PathVariable("uuid") UUID uuid
,
106 HttpServletRequest request
,
107 HttpServletResponse response
) throws IOException
{
109 logger
.info("doGetCollectingAreas() - " + request
.getServletPath());
110 DerivedUnitFacade duf
= newFacadeFrom(uuid
,
112 Arrays
.asList(new String
[]{"ecology"}));
113 return duf
.getCollectingAreas();
116 @RequestMapping(method
= RequestMethod
.GET
, value
= "collection")
117 public Object
doGetCollection(
118 @PathVariable("uuid") UUID uuid
,
119 HttpServletRequest request
,
120 HttpServletResponse response
) throws IOException
{
122 logger
.info("doGetCollection() - " + request
.getServletPath());
123 DerivedUnitFacade duf
= newFacadeFrom(uuid
,
125 Arrays
.asList(new String
[]{"collection"}));
126 return duf
.getCollection();
131 // public Point getExactLocation() => valueProcessor?
134 // public Collection getCollection() {
135 // public AgentBase getCollector() {
136 // public DerivedUnitBase getDerivedUnit() {
137 // public Map<Language, LanguageString> getDerivedUnitDefinitions(){
138 // public List<Media> getDerivedUnitMedia() {
139 // public Set<DeterminationEvent> getDeterminations() {
140 // public Set<Specimen> getDuplicates(){
141 // public Map<Language, LanguageString> getEcologyAll(){
142 // public Map<Language, LanguageString> getFieldObjectDefinition() {
143 // public List<Media> getFieldObjectMedia() {
144 // public FieldObservation getFieldObservation(){
145 // public GatheringEvent getGatheringEvent() {
146 // public String getGatheringEventDescription() {
147 // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!
148 // public PreservationMethod getPreservationMethod()
149 // public Set<IdentifiableSource> getSources(){
150 // public TaxonNameBase getStoredUnder() {
153 private DerivedUnitFacade
newFacadeFrom(UUID uuid
, HttpServletResponse response
, List
<String
> extendedInitStrategy
)
155 List
<String
> initStrategy
= new ArrayList
<String
>(initializationStrategy
);
156 if(extendedInitStrategy
!= null && extendedInitStrategy
.size() > 0){
157 initStrategy
.addAll(extendedInitStrategy
);
159 SpecimenOrObservationBase
<?
> sob
= service
.load(uuid
, null);
160 if(sob
instanceof DerivedUnitBase
<?
>){
162 return service
.getDerivedUnitFacade(((DerivedUnitBase
)sob
), initStrategy
);
163 } catch (DerivedUnitFacadeNotSupportedException e
) {
164 logger
.error(e
); //TODO ...
167 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);