first implementation of DerivedUnitFacadeController
[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.Map;
17 import java.util.Set;
18 import java.util.UUID;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Controller;
25 import org.springframework.web.bind.WebDataBinder;
26 import org.springframework.web.bind.annotation.InitBinder;
27 import org.springframework.web.bind.annotation.PathVariable;
28 import org.springframework.web.bind.annotation.RequestMapping;
29 import org.springframework.web.bind.annotation.RequestMethod;
30
31 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
32 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
33 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
34 import eu.etaxonomy.cdm.model.agent.AgentBase;
35 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
36 import eu.etaxonomy.cdm.model.common.Language;
37 import eu.etaxonomy.cdm.model.common.LanguageString;
38 import eu.etaxonomy.cdm.model.location.NamedArea;
39 import eu.etaxonomy.cdm.model.location.Point;
40 import eu.etaxonomy.cdm.model.media.Media;
41 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
42 import eu.etaxonomy.cdm.model.occurrence.Collection;
43 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
44 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
45 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
46 import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
47 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
48 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
49 import eu.etaxonomy.cdm.model.occurrence.Specimen;
50 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
51 import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
52
53 /**
54 * @author a.kohlbecker
55 * @date 28.06.2010
56 *
57 */
58 @Controller
59 @RequestMapping(value = {"/derivedunitfacade/{uuid}"})
60 public class DerivedUnitFacadeController extends AbstractController{
61
62
63 private IOccurrenceService service;
64
65 @Autowired
66 public void setService(IOccurrenceService service) {
67 this.service = service;
68 }
69
70 @InitBinder
71 public void initBinder(WebDataBinder binder) {
72 binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
73 }
74
75 @RequestMapping(method = RequestMethod.GET)
76 public DerivedUnitFacade doGet(
77 @PathVariable("uuid") UUID uuid,
78 HttpServletRequest request,
79 HttpServletResponse response) throws IOException {
80
81 logger.info("getGet() - " + request.getServletPath());
82 DerivedUnitFacade duf = newFacadeFrom(uuid, response, null);
83 return duf;
84 }
85
86 // TODO
87 @RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
88 public Object doGetCollectingAreas(
89 @PathVariable("uuid") UUID uuid,
90 HttpServletRequest request,
91 HttpServletResponse response) throws IOException {
92
93 logger.info("doGetCollectingAreas() - " + request.getServletPath());
94 DerivedUnitFacade duf = newFacadeFrom(uuid,
95 response,
96 Arrays.asList(new String []{"ecology"}));
97 return duf.getCollectingAreas();
98 }
99
100 @RequestMapping(method = RequestMethod.GET, value = "{uuid}/collection")
101 public Object doGetCollection(
102 @PathVariable("uuid") UUID uuid,
103 HttpServletRequest request,
104 HttpServletResponse response) throws IOException {
105
106 logger.info("doGetCollection() - " + request.getServletPath());
107 DerivedUnitFacade duf = newFacadeFrom(uuid,
108 response,
109 Arrays.asList(new String []{"collection"}));
110 return duf.getCollection();
111 }
112
113
114 //TODO:
115 // public Point getExactLocation() => valueProcessor?
116
117
118 // public Collection getCollection() {
119 // public AgentBase getCollector() {
120 // public DerivedUnitBase getDerivedUnit() {
121 // public Map<Language, LanguageString> getDerivedUnitDefinitions(){
122 // public List<Media> getDerivedUnitMedia() {
123 // public Set<DeterminationEvent> getDeterminations() {
124 // public Set<Specimen> getDuplicates(){
125 // public Map<Language, LanguageString> getEcologyAll(){
126 // public Map<Language, LanguageString> getFieldObjectDefinition() {
127 // public List<Media> getFieldObjectMedia() {
128 // public FieldObservation getFieldObservation(){
129 // public GatheringEvent getGatheringEvent() {
130 // public String getGatheringEventDescription() {
131 // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!
132 // public PreservationMethod getPreservationMethod()
133 // public Set<IdentifiableSource> getSources(){
134 // public TaxonNameBase getStoredUnder() {
135
136
137 private DerivedUnitFacade newFacadeFrom(UUID uuid, HttpServletResponse response, List<String> extendedInitStrategy)
138 throws IOException {
139 List<String> initStrategy = new ArrayList<String>(DEFAULT_INIT_STRATEGY);
140 if(extendedInitStrategy != null && extendedInitStrategy.size() > 0){
141 initStrategy.addAll(extendedInitStrategy);
142 }
143 SpecimenOrObservationBase<?> sob = service.load(uuid, null);
144 if(sob instanceof DerivedUnitBase<?>){
145 try {
146 return service.getDerivedUnitFacade(((DerivedUnitBase)sob), initStrategy);
147 } catch (DerivedUnitFacadeNotSupportedException e) {
148 logger.error(e); //TODO ...
149 }
150 } else {
151 HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
152 }
153 return null;
154 }
155
156
157
158
159
160
161
162
163
164
165
166 }