Project

General

Profile

Download (7.22 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.remote.controller;
10

    
11
import java.io.IOException;
12
import java.util.ArrayList;
13
import java.util.Arrays;
14
import java.util.List;
15
import java.util.UUID;
16

    
17
import javax.servlet.http.HttpServletRequest;
18
import javax.servlet.http.HttpServletResponse;
19

    
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.stereotype.Controller;
22
import org.springframework.web.bind.WebDataBinder;
23
import org.springframework.web.bind.annotation.InitBinder;
24
import org.springframework.web.bind.annotation.PathVariable;
25
import org.springframework.web.bind.annotation.RequestMapping;
26
import org.springframework.web.bind.annotation.RequestMethod;
27
import org.springframework.web.servlet.ModelAndView;
28

    
29
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
30
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
31
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
32
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
33
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
34
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
35
import io.swagger.annotations.Api;
36

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

    
47

    
48
    private IOccurrenceService service;
49

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

    
55
    public DerivedUnitFacadeController(){
56
        setInitializationStrategy(ocurrenceInitSrategy);
57
    }
58

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

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

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

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

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

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

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

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

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

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

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

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

    
141

    
142
    //TODO:
143
    // public Point getExactLocation() => valueProcessor?
144

    
145

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

    
164

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

    
191

    
192

    
193

    
194

    
195

    
196

    
197

    
198

    
199

    
200

    
201
}
(15-15/67)