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.Collection;
|
15
|
import java.util.List;
|
16
|
import java.util.UUID;
|
17
|
import java.util.stream.Collectors;
|
18
|
|
19
|
import javax.servlet.http.HttpServletRequest;
|
20
|
import javax.servlet.http.HttpServletResponse;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Controller;
|
25
|
import org.springframework.web.bind.WebDataBinder;
|
26
|
import org.springframework.web.bind.annotation.InitBinder;
|
27
|
import org.springframework.web.bind.annotation.PathVariable;
|
28
|
import org.springframework.web.bind.annotation.RequestMapping;
|
29
|
import org.springframework.web.bind.annotation.RequestMethod;
|
30
|
import org.springframework.web.servlet.ModelAndView;
|
31
|
|
32
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
33
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
|
34
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
35
|
import eu.etaxonomy.cdm.api.service.dto.MediaDTO;
|
36
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
39
|
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
|
40
|
import io.swagger.annotations.Api;
|
41
|
|
42
|
/**
|
43
|
* @author a.kohlbecker
|
44
|
* @since 28.06.2010
|
45
|
*
|
46
|
*/
|
47
|
@Controller
|
48
|
@Api("derivedUnitFacade")
|
49
|
@RequestMapping(value = {"/derivedUnitFacade/{uuid}"})
|
50
|
public class DerivedUnitFacadeController extends AbstractController<SpecimenOrObservationBase, IOccurrenceService>{
|
51
|
|
52
|
private static final Logger logger = Logger.getLogger(DerivedUnitFacadeController.class);
|
53
|
|
54
|
|
55
|
private IOccurrenceService service;
|
56
|
|
57
|
private final List<String> derivedUnitFacadeInitStrategy = Arrays.asList(new String []{
|
58
|
"$",
|
59
|
"titleCache",
|
60
|
"collection"
|
61
|
});
|
62
|
|
63
|
public DerivedUnitFacadeController(){
|
64
|
setInitializationStrategy(derivedUnitFacadeInitStrategy);
|
65
|
}
|
66
|
|
67
|
@Override
|
68
|
@Autowired
|
69
|
public void setService(IOccurrenceService service) {
|
70
|
this.service = service;
|
71
|
}
|
72
|
|
73
|
@InitBinder
|
74
|
public void initBinder(WebDataBinder binder) {
|
75
|
binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
|
76
|
}
|
77
|
|
78
|
@RequestMapping(method = RequestMethod.GET)
|
79
|
public DerivedUnitFacade doGet(
|
80
|
@PathVariable("uuid") UUID occurrenceUuid,
|
81
|
HttpServletRequest request,
|
82
|
HttpServletResponse response) throws IOException {
|
83
|
|
84
|
logger.info("doGet() - " + request.getRequestURI());
|
85
|
DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response, null);
|
86
|
return duf;
|
87
|
}
|
88
|
|
89
|
@RequestMapping(value = {"derivedUnitMedia"}, method = RequestMethod.GET)
|
90
|
public ModelAndView doGetDerivedUnitMedia(
|
91
|
@PathVariable("uuid") UUID occurrenceUuid,
|
92
|
HttpServletRequest request,
|
93
|
HttpServletResponse response) throws IOException {
|
94
|
|
95
|
logger.info("doGetDerivedUnitMedia() - " + request.getRequestURI());
|
96
|
ModelAndView mv = new ModelAndView();
|
97
|
DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response, Arrays.asList(new String []{
|
98
|
"derivedUnitMedia", "derivedUnitMedia.title"}));
|
99
|
if(duf != null){
|
100
|
mv.addObject(duf.getDerivedUnitMedia());
|
101
|
}
|
102
|
return mv;
|
103
|
}
|
104
|
|
105
|
@RequestMapping(value = {"fieldObjectMediaDTO"}, method = RequestMethod.GET)
|
106
|
public List<MediaDTO> doGetFieldObjectMediaDTO(
|
107
|
@PathVariable("uuid") UUID occurrenceUuid,
|
108
|
HttpServletRequest request,
|
109
|
HttpServletResponse response) throws IOException {
|
110
|
|
111
|
logger.info("doGetFieldObjectMediaDTO() - " + readPathParameter(request, null));
|
112
|
|
113
|
Collection<FieldUnit> fus = service.findFieldUnits(occurrenceUuid, null);
|
114
|
List<MediaDTO> mediaDTOs = fus.stream()
|
115
|
.map(fu -> service.getMediaDTOs(fu, null, null))
|
116
|
.flatMap(p -> p.getRecords().stream())
|
117
|
.collect(Collectors.toList());
|
118
|
return mediaDTOs;
|
119
|
}
|
120
|
|
121
|
@RequestMapping(value = {"fieldObjectMedia"}, method = RequestMethod.GET)
|
122
|
public ModelAndView doGetFieldObjectMedia(
|
123
|
@PathVariable("uuid") UUID occurrenceUuid,
|
124
|
HttpServletRequest request,
|
125
|
HttpServletResponse response) throws IOException {
|
126
|
|
127
|
logger.info("doGetFieldObjectMedia() - " + request.getRequestURI());
|
128
|
ModelAndView mv = new ModelAndView();
|
129
|
DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response,Arrays.asList(new String []{
|
130
|
"fieldObjectMedia", "fieldObjectMedia.title"}));
|
131
|
|
132
|
mv.addObject(duf.getFieldObjectMedia());
|
133
|
|
134
|
return mv;
|
135
|
}
|
136
|
|
137
|
|
138
|
// TODO
|
139
|
//@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")
|
140
|
@RequestMapping(
|
141
|
value = {"collectingareas"},
|
142
|
method = RequestMethod.GET)
|
143
|
public Object doGetCollectingAreas(
|
144
|
@PathVariable("uuid") UUID occurrenceUuid,
|
145
|
HttpServletRequest request,
|
146
|
HttpServletResponse response) throws IOException {
|
147
|
|
148
|
logger.info("doGetCollectingAreas() - " + request.getRequestURI());
|
149
|
DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid,
|
150
|
response,
|
151
|
Arrays.asList(new String []{"collectingAreas"}));
|
152
|
return duf.getCollectingAreas();
|
153
|
}
|
154
|
|
155
|
@RequestMapping(method = RequestMethod.GET, value = "collection")
|
156
|
public Object doGetCollection(
|
157
|
@PathVariable("uuid") UUID uuid,
|
158
|
HttpServletRequest request,
|
159
|
HttpServletResponse response) throws IOException {
|
160
|
|
161
|
logger.info("doGetCollection() - " + request.getRequestURI());
|
162
|
DerivedUnitFacade duf = newFacadeFrom(uuid,
|
163
|
response,
|
164
|
Arrays.asList(new String []{"collection"}));
|
165
|
return duf.getCollection();
|
166
|
}
|
167
|
|
168
|
|
169
|
//TODO:
|
170
|
// public Point getExactLocation() => valueProcessor?
|
171
|
|
172
|
|
173
|
// public Collection getCollection() {
|
174
|
// public AgentBase getCollector() {
|
175
|
// public DerivedUnit getDerivedUnit() {
|
176
|
// public Map<Language, LanguageString> getDerivedUnitDefinitions(){
|
177
|
// public List<Media> getDerivedUnitMedia() {
|
178
|
// public Set<DeterminationEvent> getDeterminations() {
|
179
|
// public Set<Specimen> getDuplicates(){
|
180
|
// public Map<Language, LanguageString> getEcologyAll(){
|
181
|
// public Map<Language, LanguageString> getFieldObjectDefinition() {
|
182
|
// public List<Media> getFieldObjectMedia() {
|
183
|
// public FieldUnit getFieldUnit(){
|
184
|
// public GatheringEvent getGatheringEvent() {
|
185
|
// public String getGatheringEventDescription() {
|
186
|
// public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!
|
187
|
// public PreservationMethod getPreservationMethod()
|
188
|
// public Set<IdentifiableSource> getSources(){
|
189
|
// public TaxonName getStoredUnder() {
|
190
|
|
191
|
|
192
|
/**
|
193
|
* @param occurrenceUuid
|
194
|
* @param response
|
195
|
* @param extendedInitStrategy
|
196
|
* @return the requested <code>DerivedUnitFacade</code> instance or <code>null</code>
|
197
|
* @throws IOException
|
198
|
*/
|
199
|
private DerivedUnitFacade newFacadeFrom(UUID occurrenceUuid, HttpServletResponse response, List<String> extendedInitStrategy)
|
200
|
throws IOException {
|
201
|
List<String> initStrategy = new ArrayList<String>(getInitializationStrategy());
|
202
|
if(extendedInitStrategy != null && extendedInitStrategy.size() > 0){
|
203
|
initStrategy.addAll(extendedInitStrategy);
|
204
|
}
|
205
|
SpecimenOrObservationBase<?> sob = service.load(occurrenceUuid, null);
|
206
|
if(sob instanceof DerivedUnit){
|
207
|
try {
|
208
|
return service.getDerivedUnitFacade(((DerivedUnit)sob), initStrategy);
|
209
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
210
|
logger.error(e); //TODO ...
|
211
|
}
|
212
|
} else {
|
213
|
|
214
|
HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
215
|
}
|
216
|
return null;
|
217
|
}
|
218
|
|
219
|
|
220
|
|
221
|
|
222
|
|
223
|
|
224
|
|
225
|
|
226
|
|
227
|
|
228
|
|
229
|
}
|