Project

General

Profile

Download (7.24 KB) Statistics
| Branch: | Tag: | Revision:
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 io.swagger.annotations.Api;
13

    
14
import java.io.IOException;
15
import java.util.ArrayList;
16
import java.util.Arrays;
17
import java.util.List;
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
import org.springframework.web.servlet.ModelAndView;
31

    
32
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
33
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
34
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
35
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
36
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
37
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
38

    
39
/**
40
 * @author a.kohlbecker
41
 * @date 28.06.2010
42
 *
43
 */
44
@Controller
45
@Api("derivedUnitFacade")
46
@RequestMapping(value = {"/derivedUnitFacade/{uuid}"})
47
public class DerivedUnitFacadeController extends AbstractController<SpecimenOrObservationBase, IOccurrenceService>{
48

    
49

    
50
    private IOccurrenceService service;
51

    
52
    private final List<String> ocurrenceInitSrategy = Arrays.asList(new String []{
53
            "$",
54
            "titleCache"
55
    });
56

    
57
    public DerivedUnitFacadeController(){
58
        setInitializationStrategy(ocurrenceInitSrategy);
59
    }
60

    
61
    @Override
62
    @Autowired
63
    public void setService(IOccurrenceService service) {
64
        this.service = service;
65
    }
66

    
67
    @InitBinder
68
    public void initBinder(WebDataBinder binder) {
69
        binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
70
    }
71

    
72
    @RequestMapping(method = RequestMethod.GET)
73
    public DerivedUnitFacade doGet(
74
            @PathVariable("uuid") UUID occurrenceUuid,
75
            HttpServletRequest request,
76
            HttpServletResponse response) throws IOException {
77

    
78
        logger.info("getGet() - " + request.getRequestURI());
79
        DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response, null);
80
        return duf;
81
    }
82

    
83
    @RequestMapping(value = {"derivedUnitMedia"}, method = RequestMethod.GET)
84
    public ModelAndView doGetDerivedUnitMedia(
85
        @PathVariable("uuid") UUID occurrenceUuid,
86
        HttpServletRequest request,
87
        HttpServletResponse response) throws IOException {
88

    
89
        logger.info("doGetDerivedUnitMedia() - " + request.getRequestURI());
90
        ModelAndView mv = new ModelAndView();
91
        DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response,Arrays.asList(new String []{
92
                "derivedUnitMedia", "derivedUnitMedia.title"}));
93
        if(duf != null){
94
            mv.addObject(duf.getDerivedUnitMedia());
95
        }
96
        return mv;
97
    }
98

    
99
    @RequestMapping(value = {"fieldObjectMedia"}, method = RequestMethod.GET)
100
    public ModelAndView doGetFieldObjectMedia(
101
        @PathVariable("uuid") UUID occurrenceUuid,
102
        HttpServletRequest request,
103
        HttpServletResponse response) throws IOException {
104

    
105
        logger.info("doGetFieldObjectMedia() - " + request.getRequestURI());
106
        ModelAndView mv = new ModelAndView();
107
        DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response,Arrays.asList(new String []{
108
                "fieldObjectMedia", "fieldObjectMedia.title"}));
109
        mv.addObject(duf.getFieldObjectMedia());
110
        return mv;
111
    }
112

    
113
// TODO
114
    //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
115
        @RequestMapping(
116
            value = {"collectingareas"},
117
            method = RequestMethod.GET)
118
    public Object doGetCollectingAreas(
119
            @PathVariable("uuid") UUID occurrenceUuid,
120
            HttpServletRequest request,
121
            HttpServletResponse response) throws IOException {
122

    
123
        logger.info("doGetCollectingAreas() - " + request.getRequestURI());
124
        DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid,
125
                response,
126
                Arrays.asList(new String []{"ecology"}));
127
        return duf.getCollectingAreas();
128
    }
129

    
130
    @RequestMapping(method = RequestMethod.GET, value = "collection")
131
    public Object doGetCollection(
132
            @PathVariable("uuid") UUID uuid,
133
            HttpServletRequest request,
134
            HttpServletResponse response) throws IOException {
135

    
136
        logger.info("doGetCollection() - " + request.getRequestURI());
137
        DerivedUnitFacade duf = newFacadeFrom(uuid,
138
                response,
139
                Arrays.asList(new String []{"collection"}));
140
        return duf.getCollection();
141
    }
142

    
143

    
144
    //TODO:
145
    // public Point getExactLocation() => valueProcessor?
146

    
147

    
148
    // public Collection getCollection() {
149
    // public AgentBase getCollector() {
150
    // public DerivedUnit getDerivedUnit() {
151
    // public Map<Language, LanguageString> getDerivedUnitDefinitions(){
152
    // public List<Media> getDerivedUnitMedia() {
153
    // public Set<DeterminationEvent> getDeterminations() {
154
    // public Set<Specimen> getDuplicates(){
155
    // public Map<Language, LanguageString> getEcologyAll(){
156
    // public Map<Language, LanguageString> getFieldObjectDefinition() {
157
    // public List<Media> getFieldObjectMedia() {
158
    // public FieldUnit getFieldUnit(){
159
    // public GatheringEvent getGatheringEvent() {
160
    // public String getGatheringEventDescription() {
161
    // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!
162
    // public PreservationMethod getPreservationMethod()
163
    // public Set<IdentifiableSource> getSources(){
164
    // public TaxonNameBase getStoredUnder() {
165

    
166

    
167
    /**
168
     * @param occurrenceUuid
169
     * @param response
170
     * @param extendedInitStrategy
171
     * @return the requesed <code>DerivedUnitFacade</code> instance or <code>null</code>
172
     * @throws IOException
173
     */
174
    private DerivedUnitFacade newFacadeFrom(UUID occurrenceUuid, HttpServletResponse response, List<String> extendedInitStrategy)
175
    throws IOException {
176
        List<String> initStrategy = new ArrayList<String>(initializationStrategy);
177
        if(extendedInitStrategy != null && extendedInitStrategy.size() > 0){
178
            initStrategy.addAll(extendedInitStrategy);
179
        }
180
        SpecimenOrObservationBase<?> sob = service.load(occurrenceUuid, null);
181
        if(sob instanceof DerivedUnit){
182
            try {
183
                return service.getDerivedUnitFacade(((DerivedUnit)sob), initStrategy);
184
            } catch (DerivedUnitFacadeNotSupportedException e) {
185
                logger.error(e); //TODO ...
186
            }
187
        } else {
188
            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
189
        }
190
        return null;
191
    }
192

    
193

    
194

    
195

    
196

    
197

    
198

    
199

    
200

    
201

    
202

    
203
}
(13-13/63)