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
.DerivedUnit
;
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
<SpecimenOrObservationBase
, IOccurrenceService
>{
47 private IOccurrenceService service
;
49 private final List
<String
> ocurrenceInitSrategy
= Arrays
.asList(new String
[]{
54 public DerivedUnitFacadeController(){
55 setInitializationStrategy(ocurrenceInitSrategy
);
60 public void setService(IOccurrenceService service
) {
61 this.service
= service
;
65 public void initBinder(WebDataBinder binder
) {
66 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
69 @RequestMapping(method
= RequestMethod
.GET
)
70 public DerivedUnitFacade
doGet(
71 @PathVariable("uuid") UUID occurrenceUuid
,
72 HttpServletRequest request
,
73 HttpServletResponse response
) throws IOException
{
75 logger
.info("getGet() - " + request
.getRequestURI());
76 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
, null);
80 @RequestMapping(value
= {"derivedUnitMedia"}, method
= RequestMethod
.GET
)
81 public ModelAndView
doGetDerivedUnitMedia(
82 @PathVariable("uuid") UUID occurrenceUuid
,
83 HttpServletRequest request
,
84 HttpServletResponse response
) throws IOException
{
86 logger
.info("doGetDerivedUnitMedia() - " + request
.getRequestURI());
87 ModelAndView mv
= new ModelAndView();
88 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
,Arrays
.asList(new String
[]{
89 "derivedUnitMedia", "derivedUnitMedia.title"}));
91 mv
.addObject(duf
.getDerivedUnitMedia());
96 @RequestMapping(value
= {"fieldObjectMedia"}, method
= RequestMethod
.GET
)
97 public ModelAndView
doGetFieldObjectMedia(
98 @PathVariable("uuid") UUID occurrenceUuid
,
99 HttpServletRequest request
,
100 HttpServletResponse response
) throws IOException
{
102 logger
.info("doGetFieldObjectMedia() - " + request
.getRequestURI());
103 ModelAndView mv
= new ModelAndView();
104 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
, response
,Arrays
.asList(new String
[]{
105 "fieldObjectMedia", "fieldObjectMedia.title"}));
106 mv
.addObject(duf
.getFieldObjectMedia());
111 //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
113 value
= {"collectingareas"},
114 method
= RequestMethod
.GET
)
115 public Object
doGetCollectingAreas(
116 @PathVariable("uuid") UUID occurrenceUuid
,
117 HttpServletRequest request
,
118 HttpServletResponse response
) throws IOException
{
120 logger
.info("doGetCollectingAreas() - " + request
.getRequestURI());
121 DerivedUnitFacade duf
= newFacadeFrom(occurrenceUuid
,
123 Arrays
.asList(new String
[]{"ecology"}));
124 return duf
.getCollectingAreas();
127 @RequestMapping(method
= RequestMethod
.GET
, value
= "collection")
128 public Object
doGetCollection(
129 @PathVariable("uuid") UUID uuid
,
130 HttpServletRequest request
,
131 HttpServletResponse response
) throws IOException
{
133 logger
.info("doGetCollection() - " + request
.getRequestURI());
134 DerivedUnitFacade duf
= newFacadeFrom(uuid
,
136 Arrays
.asList(new String
[]{"collection"}));
137 return duf
.getCollection();
142 // public Point getExactLocation() => valueProcessor?
145 // public Collection getCollection() {
146 // public AgentBase getCollector() {
147 // public DerivedUnit getDerivedUnit() {
148 // public Map<Language, LanguageString> getDerivedUnitDefinitions(){
149 // public List<Media> getDerivedUnitMedia() {
150 // public Set<DeterminationEvent> getDeterminations() {
151 // public Set<Specimen> getDuplicates(){
152 // public Map<Language, LanguageString> getEcologyAll(){
153 // public Map<Language, LanguageString> getFieldObjectDefinition() {
154 // public List<Media> getFieldObjectMedia() {
155 // public FieldUnit getFieldUnit(){
156 // public GatheringEvent getGatheringEvent() {
157 // public String getGatheringEventDescription() {
158 // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!
159 // public PreservationMethod getPreservationMethod()
160 // public Set<IdentifiableSource> getSources(){
161 // public TaxonNameBase getStoredUnder() {
165 * @param occurrenceUuid
167 * @param extendedInitStrategy
168 * @return the requesed <code>DerivedUnitFacade</code> instance or <code>null</code>
169 * @throws IOException
171 private DerivedUnitFacade
newFacadeFrom(UUID occurrenceUuid
, HttpServletResponse response
, List
<String
> extendedInitStrategy
)
173 List
<String
> initStrategy
= new ArrayList
<String
>(initializationStrategy
);
174 if(extendedInitStrategy
!= null && extendedInitStrategy
.size() > 0){
175 initStrategy
.addAll(extendedInitStrategy
);
177 SpecimenOrObservationBase
<?
> sob
= service
.load(occurrenceUuid
, null);
178 if(sob
instanceof DerivedUnit
){
180 return service
.getDerivedUnitFacade(((DerivedUnit
)sob
), initStrategy
);
181 } catch (DerivedUnitFacadeNotSupportedException e
) {
182 logger
.error(e
); //TODO ...
185 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);