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.ArrayList;
|
17
|
import java.util.Arrays;
|
18
|
import java.util.List;
|
19
|
import java.util.Set;
|
20
|
import java.util.UUID;
|
21
|
|
22
|
import javax.persistence.EntityNotFoundException;
|
23
|
import javax.servlet.http.HttpServletRequest;
|
24
|
import javax.servlet.http.HttpServletResponse;
|
25
|
|
26
|
import org.apache.log4j.Logger;
|
27
|
import org.springframework.beans.factory.annotation.Autowired;
|
28
|
import org.springframework.stereotype.Controller;
|
29
|
import org.springframework.web.bind.annotation.PathVariable;
|
30
|
import org.springframework.web.bind.annotation.RequestMapping;
|
31
|
import org.springframework.web.bind.annotation.RequestMethod;
|
32
|
import org.springframework.web.bind.annotation.RequestParam;
|
33
|
import org.springframework.web.servlet.ModelAndView;
|
34
|
|
35
|
import eu.etaxonomy.cdm.api.service.INameService;
|
36
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
37
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
38
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
39
|
import eu.etaxonomy.cdm.api.service.config.IncludedTaxonConfiguration;
|
40
|
import eu.etaxonomy.cdm.api.service.dto.IncludedTaxaDTO;
|
41
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
42
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
43
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
44
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
45
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
46
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
47
|
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
|
48
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
49
|
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
|
50
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
51
|
|
52
|
/**
|
53
|
* TODO write controller documentation
|
54
|
*
|
55
|
* @author a.kohlbecker
|
56
|
* @date 20.07.2009
|
57
|
*
|
58
|
*/
|
59
|
@Controller
|
60
|
@Api("taxon")
|
61
|
@RequestMapping(value = {"/taxon/{uuid}"})
|
62
|
public class TaxonController extends BaseController<TaxonBase, ITaxonService>
|
63
|
{
|
64
|
public static final Logger logger = Logger.getLogger(TaxonController.class);
|
65
|
|
66
|
@Autowired
|
67
|
private IOccurrenceService occurrenceService;
|
68
|
@Autowired
|
69
|
private INameService nameService;
|
70
|
@Autowired
|
71
|
private ITaxonNodeService nodeService;
|
72
|
|
73
|
protected static final List<String> TAXONNODE_INIT_STRATEGY = Arrays.asList(new String []{
|
74
|
"taxonNodes"
|
75
|
});
|
76
|
|
77
|
public TaxonController(){
|
78
|
super();
|
79
|
setInitializationStrategy(Arrays.asList(new String[]{
|
80
|
"$",
|
81
|
"name.nomenclaturalReference"
|
82
|
}
|
83
|
));
|
84
|
}
|
85
|
|
86
|
|
87
|
@Override
|
88
|
@Autowired
|
89
|
public void setService(ITaxonService service) {
|
90
|
this.service = service;
|
91
|
}
|
92
|
|
93
|
|
94
|
/**
|
95
|
* Get the set of accepted {@link Taxon} entities for a given
|
96
|
* {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
|
97
|
* <p>
|
98
|
* URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
|
99
|
*
|
100
|
* @param request
|
101
|
* @param response
|
102
|
* @return a set on a list of {@link Taxon} entities which are initialized
|
103
|
* using the following initialization strategy:
|
104
|
* {@link #DEFAULT_INIT_STRATEGY}
|
105
|
* @throws IOException
|
106
|
*/
|
107
|
/**
|
108
|
* Get the set of accepted {@link Taxon} entities for a given
|
109
|
* {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
|
110
|
* <p>
|
111
|
* URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/accepted</b>
|
112
|
*
|
113
|
* @param request
|
114
|
* @param response
|
115
|
* @return a Set of {@link Taxon} entities which are initialized
|
116
|
* using the following initialization strategy:
|
117
|
* {@link #SYNONYMY_INIT_STRATEGY}
|
118
|
* @throws IOException
|
119
|
* @Deprecated use getAcceptedFor() instead
|
120
|
*/
|
121
|
@Deprecated
|
122
|
@RequestMapping(value = "accepted/{classification_uuid}", method = RequestMethod.GET)
|
123
|
public List<Taxon> getAcceptedForWithClassificationFilter(
|
124
|
@PathVariable("uuid") UUID uuid,
|
125
|
@PathVariable("classification_uuid") UUID classification_uuid,
|
126
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
127
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
128
|
HttpServletRequest request,
|
129
|
HttpServletResponse response)
|
130
|
throws IOException {
|
131
|
|
132
|
|
133
|
return getAcceptedFor(uuid, classification_uuid, pageNumber, pageSize, request, response);
|
134
|
}
|
135
|
|
136
|
@RequestMapping(value = "accepted", method = RequestMethod.GET)
|
137
|
public List<Taxon> getAcceptedFor(
|
138
|
@PathVariable("uuid") UUID uuid,
|
139
|
@RequestParam(value = "classificationFilter", required = false) UUID classification_uuid,
|
140
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
141
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
142
|
HttpServletRequest request,
|
143
|
HttpServletResponse response)
|
144
|
throws IOException {
|
145
|
if(request != null){
|
146
|
logger.info("getAccepted() " + requestPathAndQuery(request));
|
147
|
}
|
148
|
|
149
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
150
|
pagerParams.normalizeAndValidate(response);
|
151
|
|
152
|
List<Taxon> resultset = new ArrayList<Taxon>();
|
153
|
try {
|
154
|
resultset = service.listAcceptedTaxaFor(uuid, classification_uuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), null, getInitializationStrategy());
|
155
|
} catch (EntityNotFoundException e){
|
156
|
HttpStatusMessage.UUID_NOT_FOUND.send(response);
|
157
|
}
|
158
|
|
159
|
return resultset;
|
160
|
}
|
161
|
|
162
|
@RequestMapping(value = "classifications", method = RequestMethod.GET)
|
163
|
public List<Classification> doGetClassifications(
|
164
|
@PathVariable("uuid") UUID uuid,
|
165
|
HttpServletRequest request,
|
166
|
HttpServletResponse response) throws IOException {
|
167
|
logger.info("doGetClassifications(): " + request.getRequestURI());
|
168
|
TaxonBase<?> taxonBase = service.load(uuid);
|
169
|
|
170
|
if (taxonBase == null){
|
171
|
HttpStatusMessage.UUID_NOT_FOUND.send(response);
|
172
|
}
|
173
|
|
174
|
return service.listClassifications(taxonBase, null, null, getInitializationStrategy());
|
175
|
}
|
176
|
|
177
|
@RequestMapping(value = "taxonNodes", method = RequestMethod.GET)
|
178
|
public Set<TaxonNode> doGetTaxonNodes(
|
179
|
@PathVariable("uuid") UUID uuid,
|
180
|
HttpServletRequest request,
|
181
|
HttpServletResponse response) throws IOException {
|
182
|
|
183
|
TaxonBase<?> tb = service.load(uuid, TAXONNODE_INIT_STRATEGY);
|
184
|
if(tb instanceof Taxon){
|
185
|
return ((Taxon)tb).getTaxonNodes();
|
186
|
} else {
|
187
|
HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
188
|
return null;
|
189
|
}
|
190
|
}
|
191
|
|
192
|
/**
|
193
|
*
|
194
|
* See also {@link AgentController#doGetTaxonNodeAgentRelations(UUID, UUID, Integer, Integer, HttpServletRequest, HttpServletResponse)}
|
195
|
*
|
196
|
* @param uuid
|
197
|
* @param classificationUuid
|
198
|
* @param pageNumber
|
199
|
* @param pageSize
|
200
|
* @param request
|
201
|
* @param response
|
202
|
* @return
|
203
|
* @throws IOException
|
204
|
*
|
205
|
*/
|
206
|
@RequestMapping(value = "taxonNodeAgentRelations/{classification_uuid}", method = RequestMethod.GET)
|
207
|
public Pager<TaxonNodeAgentRelation> doGetTaxonNodeAgentRelations(
|
208
|
@PathVariable("uuid") UUID uuid,
|
209
|
@PathVariable("classification_uuid") UUID classificationUuid,
|
210
|
@RequestParam(value = "relType_uuid" , required = false) UUID relTypeUuid,
|
211
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
212
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
213
|
HttpServletRequest request,
|
214
|
HttpServletResponse response) throws IOException {
|
215
|
|
216
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
217
|
pagerParams.normalizeAndValidate(response);
|
218
|
|
219
|
Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(uuid, classificationUuid,
|
220
|
null, null, relTypeUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), null);
|
221
|
return pager;
|
222
|
}
|
223
|
|
224
|
|
225
|
@RequestMapping(value = "specimensOrObservations", method = RequestMethod.GET)
|
226
|
public ModelAndView doListSpecimensOrObservations(
|
227
|
@PathVariable("uuid") UUID uuid,
|
228
|
HttpServletRequest request,
|
229
|
HttpServletResponse response) throws IOException {
|
230
|
logger.info("doListSpecimensOrObservations() - " + request.getRequestURI());
|
231
|
|
232
|
ModelAndView mv = new ModelAndView();
|
233
|
|
234
|
TaxonBase<?> tb = service.load(uuid);
|
235
|
|
236
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
237
|
orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));
|
238
|
|
239
|
if(tb instanceof Taxon){
|
240
|
List<SpecimenOrObservationBase<?>> specimensOrObservations = occurrenceService.listByAssociatedTaxon(null, null, (Taxon)tb, null, null, null, orderHints, null);
|
241
|
mv.addObject(specimensOrObservations);
|
242
|
} else {
|
243
|
HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
244
|
return null;
|
245
|
}
|
246
|
|
247
|
return mv;
|
248
|
}
|
249
|
|
250
|
@RequestMapping(value = "associatedFieldUnits", method = RequestMethod.GET)
|
251
|
public Pager<SpecimenOrObservationBase> doGetFieldUnits(
|
252
|
@PathVariable("uuid") UUID uuid,
|
253
|
@RequestParam(value = "maxDepth", required = false) Integer maxDepth,
|
254
|
@RequestParam(value = "pageNumber", required = false) Integer pageNumber,
|
255
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
256
|
HttpServletRequest request,
|
257
|
HttpServletResponse response) throws IOException {
|
258
|
logger.info("doGetFieldUnits() - " + request.getRequestURI());
|
259
|
|
260
|
ModelAndView mv = new ModelAndView();
|
261
|
|
262
|
TaxonBase<?> tb = service.load(uuid);
|
263
|
|
264
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
265
|
orderHints.add(new OrderHint("titleCache", SortOrder.ASCENDING));
|
266
|
|
267
|
if(tb instanceof Taxon){
|
268
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
|
269
|
pagerParams.normalizeAndValidate(response);
|
270
|
|
271
|
return occurrenceService.pageFieldUnitsByAssociatedTaxon(null, (Taxon) tb, null, pagerParams.getPageSize(), pagerParams.getPageIndex(), orderHints, null);
|
272
|
}
|
273
|
return null;
|
274
|
}
|
275
|
|
276
|
@RequestMapping(value = "taggedName", method = RequestMethod.GET)
|
277
|
public ModelAndView doGetTaggedName(
|
278
|
@PathVariable("uuid") UUID uuid,
|
279
|
HttpServletRequest request) {
|
280
|
logger.info("doGetDescriptionElementsByType() - " + request.getRequestURI());
|
281
|
|
282
|
ModelAndView mv = new ModelAndView();
|
283
|
|
284
|
TaxonBase<?> tb = service.load(uuid, Arrays.asList(new String[] {"name"}));
|
285
|
mv.addObject(nameService.getTaggedName(tb.getName().getUuid()));
|
286
|
return mv;
|
287
|
}
|
288
|
|
289
|
/**
|
290
|
* This webservice endpoint returns all taxa which are congruent or included in the taxon represented by the given taxon uuid.
|
291
|
* The result also returns the path to these taxa represented by the uuids of the taxon relationships types and doubtful information.
|
292
|
* If classificationUuids is set only taxa of classifications are returned which are included in the given classifications.
|
293
|
* Also the path to these taxa may not include taxa from other classifications.
|
294
|
*
|
295
|
* @param taxonUUIDString
|
296
|
* @param classificationStringList
|
297
|
* @param includeDoubtful
|
298
|
* @param onlyCongruent
|
299
|
* @param response
|
300
|
* @param request
|
301
|
* @return
|
302
|
* @throws IOException
|
303
|
*/
|
304
|
|
305
|
@RequestMapping(value = { "includedTaxa" }, method = { RequestMethod.GET })
|
306
|
public ModelAndView doGetIncludedTaxa(
|
307
|
@PathVariable("uuid") UUID uuid,
|
308
|
@RequestParam(value="classificationFilter", required=false) final List<String> classificationStringList,
|
309
|
@RequestParam(value="includeDoubtful", required=false) final boolean includeDoubtful,
|
310
|
@RequestParam(value="onlyCongruent", required=false) final boolean onlyCongruent,
|
311
|
HttpServletResponse response,
|
312
|
HttpServletRequest request) throws IOException {
|
313
|
ModelAndView mv = new ModelAndView();
|
314
|
/**
|
315
|
* List<UUID> classificationFilter,
|
316
|
* boolean includeDoubtful,
|
317
|
* boolean onlyCongruent)
|
318
|
*/
|
319
|
List<UUID> classificationFilter = null;
|
320
|
if( classificationStringList != null ){
|
321
|
classificationFilter = new ArrayList<UUID>();
|
322
|
for(String classString :classificationStringList){
|
323
|
classificationFilter.add(UUID.fromString(classString));
|
324
|
}
|
325
|
}
|
326
|
final IncludedTaxonConfiguration configuration = new IncludedTaxonConfiguration(classificationFilter, includeDoubtful, onlyCongruent);
|
327
|
IncludedTaxaDTO listIncludedTaxa = service.listIncludedTaxa(uuid, configuration);
|
328
|
mv.addObject(listIncludedTaxa);
|
329
|
return mv;
|
330
|
}
|
331
|
|
332
|
}
|