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