DerivedUnitFacade Portal controller
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / DerivedUnitFacadeController.java
1 // $Id$
2 /**
3 * Copyright (C) 2009 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10 package eu.etaxonomy.cdm.remote.controller;
11
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;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
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;
29
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;
37
38 /**
39 * @author a.kohlbecker
40 * @date 28.06.2010
41 *
42 */
43 @Controller
44 @RequestMapping(value = {"/derivedUnitFacade/{uuid}"})
45 public class DerivedUnitFacadeController extends AbstractController{
46
47
48 private IOccurrenceService service;
49
50 @Autowired
51 public void setService(IOccurrenceService service) {
52 this.service = service;
53 }
54
55 @InitBinder
56 public void initBinder(WebDataBinder binder) {
57 binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
58 }
59
60 @RequestMapping(method = RequestMethod.GET)
61 public DerivedUnitFacade doGet(
62 @PathVariable("uuid") UUID uuid,
63 HttpServletRequest request,
64 HttpServletResponse response) throws IOException {
65
66 logger.info("getGet() - " + request.getServletPath());
67 DerivedUnitFacade duf = newFacadeFrom(uuid, response, null);
68 return duf;
69 }
70
71 @RequestMapping(value = {"derivedUnitMedia"}, method = RequestMethod.GET)
72 public ModelAndView doGetDerivedUnitMedia(
73 @PathVariable("uuid") UUID uuid,
74 HttpServletRequest request,
75 HttpServletResponse response) throws IOException {
76
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());
82 return mv;
83 }
84
85 @RequestMapping(value = {"fieldObjectMedia"}, method = RequestMethod.GET)
86 public ModelAndView doGetFieldObjectMedia(
87 @PathVariable("uuid") UUID uuid,
88 HttpServletRequest request,
89 HttpServletResponse response) throws IOException {
90
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());
96 return mv;
97 }
98
99 // TODO
100 //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
101 @RequestMapping(
102 value = {"collectingareas"},
103 method = RequestMethod.GET)
104 public Object doGetCollectingAreas(
105 @PathVariable("uuid") UUID uuid,
106 HttpServletRequest request,
107 HttpServletResponse response) throws IOException {
108
109 logger.info("doGetCollectingAreas() - " + request.getServletPath());
110 DerivedUnitFacade duf = newFacadeFrom(uuid,
111 response,
112 Arrays.asList(new String []{"ecology"}));
113 return duf.getCollectingAreas();
114 }
115
116 @RequestMapping(method = RequestMethod.GET, value = "collection")
117 public Object doGetCollection(
118 @PathVariable("uuid") UUID uuid,
119 HttpServletRequest request,
120 HttpServletResponse response) throws IOException {
121
122 logger.info("doGetCollection() - " + request.getServletPath());
123 DerivedUnitFacade duf = newFacadeFrom(uuid,
124 response,
125 Arrays.asList(new String []{"collection"}));
126 return duf.getCollection();
127 }
128
129
130 //TODO:
131 // public Point getExactLocation() => valueProcessor?
132
133
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() {
151
152
153 private DerivedUnitFacade newFacadeFrom(UUID uuid, HttpServletResponse response, List<String> extendedInitStrategy)
154 throws IOException {
155 List<String> initStrategy = new ArrayList<String>(initializationStrategy);
156 if(extendedInitStrategy != null && extendedInitStrategy.size() > 0){
157 initStrategy.addAll(extendedInitStrategy);
158 }
159 SpecimenOrObservationBase<?> sob = service.load(uuid, null);
160 if(sob instanceof DerivedUnitBase<?>){
161 try {
162 return service.getDerivedUnitFacade(((DerivedUnitBase)sob), initStrategy);
163 } catch (DerivedUnitFacadeNotSupportedException e) {
164 logger.error(e); //TODO ...
165 }
166 } else {
167 HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
168 }
169 return null;
170 }
171
172
173
174
175
176
177
178
179
180
181
182 }