Project

General

Profile

Download (8.51 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.apache.log4j.Logger;
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.api.service.dto.FieldUnitDTO;
34
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
35
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
36
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
37
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
38
import io.swagger.annotations.Api;
39

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

    
50
    private static final Logger logger = Logger.getLogger(DerivedUnitFacadeController.class);
51

    
52

    
53
    private IOccurrenceService service;
54

    
55
    private final List<String> derivedUnitFacadeInitStrategy = Arrays.asList(new String []{
56
            "$",
57
            "titleCache",
58
            "collection"
59
    });
60

    
61
    public DerivedUnitFacadeController(){
62
        setInitializationStrategy(derivedUnitFacadeInitStrategy);
63
    }
64

    
65
    @Override
66
    @Autowired
67
    public void setService(IOccurrenceService service) {
68
        this.service = service;
69
    }
70

    
71
    @InitBinder
72
    public void initBinder(WebDataBinder binder) {
73
        binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
74
    }
75

    
76
    @RequestMapping(method = RequestMethod.GET)
77
    public DerivedUnitFacade doGet(
78
            @PathVariable("uuid") UUID occurrenceUuid,
79
            HttpServletRequest request,
80
            HttpServletResponse response) throws IOException {
81

    
82
        logger.info("doGet() - " + request.getRequestURI());
83
        DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response, null);
84
        return duf;
85
    }
86

    
87
    @RequestMapping(value = {"derivedUnitMedia"}, method = RequestMethod.GET)
88
    public ModelAndView doGetDerivedUnitMedia(
89
        @PathVariable("uuid") UUID occurrenceUuid,
90
        HttpServletRequest request,
91
        HttpServletResponse response) throws IOException {
92

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

    
103
    @RequestMapping(value = {"fieldObjectMediaDTO"}, method = RequestMethod.GET)
104
    public ModelAndView doGetFieldObjectMediaDTO(
105
        @PathVariable("uuid") UUID occurrenceUuid,
106
        HttpServletRequest request,
107
        HttpServletResponse response) throws IOException {
108

    
109
        logger.info("doGetFieldObjectMedia() - " + request.getRequestURI());
110
        ModelAndView mv = new ModelAndView();
111
//        DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response,Arrays.asList(new String []{
112
//                "fieldObjectMedia", "fieldObjectMedia.title"}));
113
        SpecimenOrObservationBase sob = service.load(occurrenceUuid, Arrays.asList(new String []{"descriptions", "descriptions.descriptionElements.$", "descriptions.descriptionElements.media", "kindOfUnit","gatheringEvent.*"}));
114
        FieldUnitDTO dto;
115
        if (sob instanceof FieldUnit){
116
            dto = new FieldUnitDTO((FieldUnit)sob);
117
            mv.addObject(dto.getListOfMedia());
118
        }
119

    
120
        return mv;
121
    }
122

    
123
    @RequestMapping(value = {"fieldObjectMedia"}, method = RequestMethod.GET)
124
    public ModelAndView doGetFieldObjectMedia(
125
        @PathVariable("uuid") UUID occurrenceUuid,
126
        HttpServletRequest request,
127
        HttpServletResponse response) throws IOException {
128

    
129
        logger.info("doGetFieldObjectMedia() - " + request.getRequestURI());
130
        ModelAndView mv = new ModelAndView();
131
        DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response,Arrays.asList(new String []{
132
                "fieldObjectMedia", "fieldObjectMedia.title"}));
133

    
134
        mv.addObject(duf.getFieldObjectMedia());
135

    
136
        return mv;
137
    }
138

    
139

    
140
// TODO
141
    //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
142
    @RequestMapping(
143
        value = {"collectingareas"},
144
        method = RequestMethod.GET)
145
    public Object doGetCollectingAreas(
146
            @PathVariable("uuid") UUID occurrenceUuid,
147
            HttpServletRequest request,
148
            HttpServletResponse response) throws IOException {
149

    
150
        logger.info("doGetCollectingAreas() - " + request.getRequestURI());
151
        DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid,
152
                response,
153
                Arrays.asList(new String []{"collectingAreas"}));
154
        return duf.getCollectingAreas();
155
    }
156

    
157
    @RequestMapping(method = RequestMethod.GET, value = "collection")
158
    public Object doGetCollection(
159
            @PathVariable("uuid") UUID uuid,
160
            HttpServletRequest request,
161
            HttpServletResponse response) throws IOException {
162

    
163
        logger.info("doGetCollection() - " + request.getRequestURI());
164
        DerivedUnitFacade duf = newFacadeFrom(uuid,
165
                response,
166
                Arrays.asList(new String []{"collection"}));
167
        return duf.getCollection();
168
    }
169

    
170

    
171
    //TODO:
172
    // public Point getExactLocation() => valueProcessor?
173

    
174

    
175
    // public Collection getCollection() {
176
    // public AgentBase getCollector() {
177
    // public DerivedUnit getDerivedUnit() {
178
    // public Map<Language, LanguageString> getDerivedUnitDefinitions(){
179
    // public List<Media> getDerivedUnitMedia() {
180
    // public Set<DeterminationEvent> getDeterminations() {
181
    // public Set<Specimen> getDuplicates(){
182
    // public Map<Language, LanguageString> getEcologyAll(){
183
    // public Map<Language, LanguageString> getFieldObjectDefinition() {
184
    // public List<Media> getFieldObjectMedia() {
185
    // public FieldUnit getFieldUnit(){
186
    // public GatheringEvent getGatheringEvent() {
187
    // public String getGatheringEventDescription() {
188
    // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!
189
    // public PreservationMethod getPreservationMethod()
190
    // public Set<IdentifiableSource> getSources(){
191
    // public TaxonName getStoredUnder() {
192

    
193

    
194
    /**
195
     * @param occurrenceUuid
196
     * @param response
197
     * @param extendedInitStrategy
198
     * @return the requested <code>DerivedUnitFacade</code> instance or <code>null</code>
199
     * @throws IOException
200
     */
201
    private DerivedUnitFacade newFacadeFrom(UUID occurrenceUuid, HttpServletResponse response, List<String> extendedInitStrategy)
202
    throws IOException {
203
        List<String> initStrategy = new ArrayList<String>(getInitializationStrategy());
204
        if(extendedInitStrategy != null && extendedInitStrategy.size() > 0){
205
            initStrategy.addAll(extendedInitStrategy);
206
        }
207
        SpecimenOrObservationBase<?> sob = service.load(occurrenceUuid, null);
208
        if(sob instanceof DerivedUnit){
209
            try {
210
                return service.getDerivedUnitFacade(((DerivedUnit)sob), initStrategy);
211
            } catch (DerivedUnitFacadeNotSupportedException e) {
212
                logger.error(e); //TODO ...
213
            }
214
        } else {
215

    
216
            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
217
        }
218
        return null;
219
    }
220

    
221

    
222

    
223

    
224

    
225

    
226

    
227

    
228

    
229

    
230

    
231
}
(16-16/75)