1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.remote.controller;
|
11
|
|
12
|
import java.io.IOException;
|
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.service.IDescriptionService;
|
31
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
32
|
import eu.etaxonomy.cdm.api.service.ITermTreeService;
|
33
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
34
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
35
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
36
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
37
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
38
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
39
|
import eu.etaxonomy.cdm.model.description.StateData;
|
40
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
41
|
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
|
42
|
import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
|
43
|
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
|
44
|
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
45
|
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
|
46
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
47
|
import io.swagger.annotations.Api;
|
48
|
|
49
|
/**
|
50
|
* TODO write controller documentation
|
51
|
*
|
52
|
* @author a.kohlbecker
|
53
|
* @since 24.03.2009
|
54
|
*/
|
55
|
|
56
|
@Controller
|
57
|
@Api("descriptionElement")
|
58
|
@RequestMapping(value = {"/descriptionElement/{uuid}", "/descriptionElement/{uuid_list}"})
|
59
|
public class DescriptionElementController
|
60
|
{
|
61
|
|
62
|
/**
|
63
|
*
|
64
|
*/
|
65
|
private static final List<String> STATE_INIT_STRATEGY = Arrays.asList( new String[]{
|
66
|
"states.state.representations",
|
67
|
"modifiers",
|
68
|
"modifyingText"
|
69
|
} );
|
70
|
|
71
|
|
72
|
public static final Logger logger = Logger.getLogger(DescriptionElementController.class);
|
73
|
|
74
|
|
75
|
@Autowired
|
76
|
private ITermTreeService termTreeService;
|
77
|
|
78
|
@Autowired
|
79
|
private ITermService termService;
|
80
|
|
81
|
|
82
|
@Autowired
|
83
|
private IEditGeoService geoService;
|
84
|
|
85
|
private IDescriptionService service;
|
86
|
|
87
|
@InitBinder
|
88
|
public void initBinder(WebDataBinder binder) {
|
89
|
binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
|
90
|
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
91
|
binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
|
92
|
binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<MarkerType>(termService));
|
93
|
}
|
94
|
|
95
|
/* (non-Javadoc)
|
96
|
* @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
|
97
|
*/
|
98
|
@Autowired
|
99
|
public void setService(IDescriptionService service) {
|
100
|
this.service = service;
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* @return
|
105
|
*/
|
106
|
protected List<String> getInitializationStrategy() {
|
107
|
return AbstractController.DEFAULT_INIT_STRATEGY;
|
108
|
}
|
109
|
|
110
|
|
111
|
// @RequestMapping(method = RequestMethod.GET) // mapped as absolute path, see CdmAntPathMatcher
|
112
|
// public ModelAndView doGetDescriptionElement(
|
113
|
// @PathVariable("uuid") UUID uuid,
|
114
|
// HttpServletRequest request,
|
115
|
// HttpServletResponse response) throws IOException {
|
116
|
//
|
117
|
// ModelAndView mv = new ModelAndView();
|
118
|
// logger.info("doGetDescriptionElement() - " + request.getRequestURI());
|
119
|
// DescriptionElementBase element = service.loadDescriptionElement(uuid, getInitializationStrategy());
|
120
|
// if(element == null) {
|
121
|
// HttpStatusMessage.UUID_NOT_FOUND.send(response);
|
122
|
// }
|
123
|
// mv.addObject(element);
|
124
|
// return mv;
|
125
|
// }
|
126
|
|
127
|
@RequestMapping(value = "annotations", method = RequestMethod.GET)
|
128
|
public Pager<Annotation> doGetDescriptionElementAnnotations(
|
129
|
@PathVariable("uuid") UUID uuid,
|
130
|
HttpServletRequest request,
|
131
|
HttpServletResponse response) throws IOException {
|
132
|
logger.info("doGetDescriptionElementAnnotations() - " + request.getRequestURI());
|
133
|
DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
|
134
|
if(annotatableEntity == null){
|
135
|
HttpStatusMessage.UUID_INVALID.send(response);
|
136
|
// method will exit here
|
137
|
return null;
|
138
|
}
|
139
|
|
140
|
Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
|
141
|
return annotations;
|
142
|
}
|
143
|
|
144
|
@RequestMapping(value = "states", method = RequestMethod.GET)
|
145
|
public ModelAndView doGetDescriptionElementStates(
|
146
|
@PathVariable("uuid") UUID uuid,
|
147
|
HttpServletRequest request,
|
148
|
HttpServletResponse response) throws IOException {
|
149
|
logger.info("doGetDescriptionElementStates() - " + request.getRequestURI());
|
150
|
|
151
|
ModelAndView mv = new ModelAndView();
|
152
|
|
153
|
DescriptionElementBase descriptionElement = service.loadDescriptionElement(uuid, STATE_INIT_STRATEGY);
|
154
|
if(descriptionElement == null){
|
155
|
HttpStatusMessage.UUID_INVALID.send(response);
|
156
|
// method will exit here
|
157
|
return null;
|
158
|
}
|
159
|
|
160
|
if(descriptionElement instanceof CategoricalData){
|
161
|
|
162
|
}
|
163
|
List<StateData> states = ((CategoricalData)descriptionElement).getStateData();
|
164
|
mv.addObject(states);
|
165
|
return mv;
|
166
|
}
|
167
|
|
168
|
|
169
|
}
|