removing init strategies which are replaces by MediaAutoInitializer
[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.occurrence.DerivedUnitBase;
34 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
35 import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
36
37 /**
38 * @author a.kohlbecker
39 * @date 28.06.2010
40 *
41 */
42 @Controller
43 @RequestMapping(value = {"/derivedUnitFacade/{uuid}"})
44 public class DerivedUnitFacadeController extends AbstractController{
45
46
47 private IOccurrenceService service;
48
49 @Autowired
50 public void setService(IOccurrenceService service) {
51 this.service = service;
52 }
53
54 @InitBinder
55 public void initBinder(WebDataBinder binder) {
56 binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
57 }
58
59 @RequestMapping(method = RequestMethod.GET)
60 public DerivedUnitFacade doGet(
61 @PathVariable("uuid") UUID occurrenceUuid,
62 HttpServletRequest request,
63 HttpServletResponse response) throws IOException {
64
65 logger.info("getGet() - " + request.getServletPath());
66 DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response, null);
67 return duf;
68 }
69
70 @RequestMapping(value = {"derivedUnitMedia"}, method = RequestMethod.GET)
71 public ModelAndView doGetDerivedUnitMedia(
72 @PathVariable("uuid") UUID occurrenceUuid,
73 HttpServletRequest request,
74 HttpServletResponse response) throws IOException {
75
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"}));
80 if(duf != null){
81 mv.addObject(duf.getDerivedUnitMedia());
82 }
83 return mv;
84 }
85
86 @RequestMapping(value = {"fieldObjectMedia"}, method = RequestMethod.GET)
87 public ModelAndView doGetFieldObjectMedia(
88 @PathVariable("uuid") UUID occurrenceUuid,
89 HttpServletRequest request,
90 HttpServletResponse response) throws IOException {
91
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());
97 return mv;
98 }
99
100 // TODO
101 //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
102 @RequestMapping(
103 value = {"collectingareas"},
104 method = RequestMethod.GET)
105 public Object doGetCollectingAreas(
106 @PathVariable("uuid") UUID occurrenceUuid,
107 HttpServletRequest request,
108 HttpServletResponse response) throws IOException {
109
110 logger.info("doGetCollectingAreas() - " + request.getServletPath());
111 DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid,
112 response,
113 Arrays.asList(new String []{"ecology"}));
114 return duf.getCollectingAreas();
115 }
116
117 @RequestMapping(method = RequestMethod.GET, value = "collection")
118 public Object doGetCollection(
119 @PathVariable("uuid") UUID uuid,
120 HttpServletRequest request,
121 HttpServletResponse response) throws IOException {
122
123 logger.info("doGetCollection() - " + request.getServletPath());
124 DerivedUnitFacade duf = newFacadeFrom(uuid,
125 response,
126 Arrays.asList(new String []{"collection"}));
127 return duf.getCollection();
128 }
129
130
131 //TODO:
132 // public Point getExactLocation() => valueProcessor?
133
134
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() {
152
153
154 /**
155 * @param occurrenceUuid
156 * @param response
157 * @param extendedInitStrategy
158 * @return the requesed <code>DerivedUnitFacade</code> instance or <code>null</code>
159 * @throws IOException
160 */
161 private DerivedUnitFacade newFacadeFrom(UUID occurrenceUuid, HttpServletResponse response, List<String> extendedInitStrategy)
162 throws IOException {
163 List<String> initStrategy = new ArrayList<String>(initializationStrategy);
164 if(extendedInitStrategy != null && extendedInitStrategy.size() > 0){
165 initStrategy.addAll(extendedInitStrategy);
166 }
167 SpecimenOrObservationBase<?> sob = service.load(occurrenceUuid, null);
168 if(sob instanceof DerivedUnitBase<?>){
169 try {
170 return service.getDerivedUnitFacade(((DerivedUnitBase)sob), initStrategy);
171 } catch (DerivedUnitFacadeNotSupportedException e) {
172 logger.error(e); //TODO ...
173 }
174 } else {
175 HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
176 }
177 return null;
178 }
179
180
181
182
183
184
185
186
187
188
189
190 }