Project

General

Profile

Download (6.06 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 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

    
11
package eu.etaxonomy.cdm.remote.controller;
12

    
13
import io.swagger.annotations.Api;
14

    
15
import java.io.IOException;
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.apache.log4j.Logger;
24
import org.springframework.beans.factory.annotation.Autowired;
25
import org.springframework.stereotype.Controller;
26
import org.springframework.web.bind.WebDataBinder;
27
import org.springframework.web.bind.annotation.InitBinder;
28
import org.springframework.web.bind.annotation.PathVariable;
29
import org.springframework.web.bind.annotation.RequestMapping;
30
import org.springframework.web.bind.annotation.RequestMethod;
31
import org.springframework.web.servlet.ModelAndView;
32

    
33
import eu.etaxonomy.cdm.api.service.IDescriptionService;
34
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
35
import eu.etaxonomy.cdm.api.service.ITermService;
36
import eu.etaxonomy.cdm.api.service.pager.Pager;
37
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
38
import eu.etaxonomy.cdm.model.common.Annotation;
39
import eu.etaxonomy.cdm.model.common.MarkerType;
40
import eu.etaxonomy.cdm.model.description.CategoricalData;
41
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
42
import eu.etaxonomy.cdm.model.description.StateData;
43
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
44
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
45
import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
46
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
47
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
48
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
49
import eu.etaxonomy.cdm.remote.editor.UuidList;
50

    
51
/**
52
 * TODO write controller documentation
53
 *
54
 * @author a.kohlbecker
55
 * @date 24.03.2009
56
 */
57

    
58
@Controller
59
@Api("descriptionElement")
60
@RequestMapping(value = {"/descriptionElement/{uuid}", "/descriptionElement/{uuid_list}"})
61
public class DescriptionElementController
62
{
63

    
64
    /**
65
     *
66
     */
67
    private static final List<String> STATE_INIT_STRATEGY = Arrays.asList( new String[]{
68
            "states.state.representations",
69
            "modifiers",
70
            "modifyingText"
71
            } );
72

    
73

    
74
    public static final Logger logger = Logger.getLogger(DescriptionElementController.class);
75

    
76

    
77
    @Autowired
78
    private IFeatureTreeService featureTreeService;
79

    
80
    @Autowired
81
    private ITermService termService;
82

    
83

    
84
    @Autowired
85
    private IEditGeoService geoService;
86

    
87
    private IDescriptionService service;
88

    
89
    @InitBinder
90
    public void initBinder(WebDataBinder binder) {
91
        binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
92
        binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
93
        binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
94
        binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<MarkerType>(termService));
95
    }
96

    
97
    /* (non-Javadoc)
98
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
99
     */
100
    @Autowired
101
    public void setService(IDescriptionService service) {
102
        this.service = service;
103
    }
104

    
105
    /**
106
     * @return
107
     */
108
    protected List<String> getInitializationStrategy() {
109
        return AbstractController.DEFAULT_INIT_STRATEGY;
110
    }
111

    
112

    
113
//    @RequestMapping(method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
114
//    public ModelAndView doGetDescriptionElement(
115
//            @PathVariable("uuid") UUID uuid,
116
//            HttpServletRequest request,
117
//            HttpServletResponse response) throws IOException {
118
//
119
//        ModelAndView mv = new ModelAndView();
120
//        logger.info("doGetDescriptionElement() - " + request.getRequestURI());
121
//        DescriptionElementBase element = service.loadDescriptionElement(uuid, getInitializationStrategy());
122
//        if(element == null) {
123
//            HttpStatusMessage.UUID_NOT_FOUND.send(response);
124
//        }
125
//        mv.addObject(element);
126
//        return mv;
127
//    }
128

    
129
    @RequestMapping(value = "annotations", method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
130
    public Pager<Annotation> doGetDescriptionElementAnnotations(
131
            @PathVariable("uuid") UUID uuid,
132
            HttpServletRequest request,
133
            HttpServletResponse response) throws IOException {
134
        logger.info("doGetDescriptionElementAnnotations() - " + request.getRequestURI());
135
        DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
136
        if(annotatableEntity == null){
137
            HttpStatusMessage.UUID_INVALID.send(response);
138
            // method will exit here
139
            return null;
140
        }
141

    
142
        Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
143
        return annotations;
144
    }
145

    
146
    @RequestMapping(value = "states", method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
147
    public ModelAndView doGetDescriptionElementStates(
148
            @PathVariable("uuid") UUID uuid,
149
            HttpServletRequest request,
150
            HttpServletResponse response) throws IOException {
151
        logger.info("doGetDescriptionElementStates() - " + request.getRequestURI());
152

    
153
        ModelAndView mv = new ModelAndView();
154

    
155
        DescriptionElementBase descriptionElement = service.loadDescriptionElement(uuid, STATE_INIT_STRATEGY);
156
        if(descriptionElement == null){
157
            HttpStatusMessage.UUID_INVALID.send(response);
158
            // method will exit here
159
            return null;
160
        }
161

    
162
        if(descriptionElement instanceof CategoricalData){
163

    
164
        }
165
        List<StateData> states = ((CategoricalData)descriptionElement).getStateData();
166
        mv.addObject(states);
167
        return mv;
168
    }
169

    
170

    
171
}
(16-16/63)