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