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.ArrayList;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.List;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
import java.util.stream.Collectors;
|
20
|
|
21
|
import javax.persistence.EntityNotFoundException;
|
22
|
import javax.servlet.http.HttpServletRequest;
|
23
|
import javax.servlet.http.HttpServletResponse;
|
24
|
|
25
|
import org.apache.log4j.Logger;
|
26
|
import org.springframework.beans.factory.annotation.Autowired;
|
27
|
import org.springframework.stereotype.Controller;
|
28
|
import org.springframework.web.bind.WebDataBinder;
|
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.IDescriptionService;
|
36
|
import eu.etaxonomy.cdm.api.service.INameService;
|
37
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
38
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
39
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
40
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
41
|
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
|
42
|
import eu.etaxonomy.cdm.api.service.config.IncludedTaxonConfiguration;
|
43
|
import eu.etaxonomy.cdm.api.service.dto.FieldUnitDTO;
|
44
|
import eu.etaxonomy.cdm.api.service.dto.IncludedTaxaDTO;
|
45
|
import eu.etaxonomy.cdm.api.service.dto.SpecimenOrObservationBaseDTO;
|
46
|
import eu.etaxonomy.cdm.api.service.dto.TaxonRelationshipsDTO;
|
47
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
48
|
import eu.etaxonomy.cdm.exception.UnpublishedException;
|
49
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
50
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
51
|
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
|
52
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
53
|
import eu.etaxonomy.cdm.model.description.DescriptionType;
|
54
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
55
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
56
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
57
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
58
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
59
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
60
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
61
|
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
|
62
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
63
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
64
|
import eu.etaxonomy.cdm.persistence.dao.initializer.EntityInitStrategy;
|
65
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
66
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
67
|
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
|
68
|
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
|
69
|
import eu.etaxonomy.cdm.remote.dto.common.StringResultDTO;
|
70
|
import eu.etaxonomy.cdm.remote.editor.TermBasePropertyEditor;
|
71
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
72
|
import io.swagger.annotations.Api;
|
73
|
|
74
|
/**
|
75
|
* TODO write controller documentation
|
76
|
*
|
77
|
* @author a.kohlbecker
|
78
|
* @since 20.07.2009
|
79
|
*
|
80
|
*/
|
81
|
@Controller
|
82
|
@Api("taxon")
|
83
|
@RequestMapping(value = {"/taxon/{uuid}"})
|
84
|
public class TaxonController extends AbstractIdentifiableController<TaxonBase, ITaxonService>{
|
85
|
|
86
|
public static final Logger logger = Logger.getLogger(TaxonController.class);
|
87
|
|
88
|
@Autowired
|
89
|
private IOccurrenceService occurrenceService;
|
90
|
|
91
|
@Autowired
|
92
|
private INameService nameService;
|
93
|
|
94
|
@Autowired
|
95
|
private ITaxonNodeService nodeService;
|
96
|
|
97
|
@Autowired
|
98
|
private IDescriptionService descriptionService;
|
99
|
|
100
|
@Autowired
|
101
|
private ITermService termService;
|
102
|
|
103
|
protected static final EntityInitStrategy TAXONNODE_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
104
|
"taxonNodes.classification",
|
105
|
"taxonNodes.parent",
|
106
|
"taxonNodes.taxon.name",
|
107
|
"taxonNodes.taxon.secSource.citation",
|
108
|
"taxonNodes.statusNote",
|
109
|
"acceptedTaxon.taxonNodes.classification"
|
110
|
}));
|
111
|
|
112
|
public TaxonController(){
|
113
|
super();
|
114
|
setInitializationStrategy(Arrays.asList(new String[]{
|
115
|
"$",
|
116
|
"name.nomenclaturalSource.citation"
|
117
|
}
|
118
|
));
|
119
|
}
|
120
|
|
121
|
@Override
|
122
|
@Autowired
|
123
|
public void setService(ITaxonService service) {
|
124
|
this.service = service;
|
125
|
}
|
126
|
|
127
|
@Override
|
128
|
public void initBinder(WebDataBinder binder) {
|
129
|
super.initBinder(binder);
|
130
|
binder.registerCustomEditor(MarkerType.class, new TermBasePropertyEditor<>(termService));
|
131
|
}
|
132
|
|
133
|
protected List<String> getTaxonDescriptionInitStrategy() {
|
134
|
return getInitializationStrategy(); // return Arrays.asList("$", "")
|
135
|
}
|
136
|
|
137
|
protected List<String> getTaxonDescriptionElementInitStrategy() {
|
138
|
return getInitializationStrategy();
|
139
|
}
|
140
|
|
141
|
@RequestMapping(params="subtree", method = RequestMethod.GET)
|
142
|
public TaxonBase<?> doGet(@PathVariable("uuid") UUID uuid,
|
143
|
@RequestParam(value = "subtree", required = true) UUID subtreeUuid, //if subtree does not exist the base class method is used, therefore required
|
144
|
HttpServletRequest request,
|
145
|
HttpServletResponse response) throws IOException {
|
146
|
if(request != null) {
|
147
|
logger.info("doGet() " + requestPathAndQuery(request));
|
148
|
}
|
149
|
//TODO do we want to allow Synonyms at all? Maybe needs initialization
|
150
|
EntityInitStrategy initStrategy = new EntityInitStrategy(getInitializationStrategy());
|
151
|
initStrategy.extend(null, getTaxonNodeInitStrategy(), false);
|
152
|
TaxonBase<?> taxonBase = getCdmBaseInstance(uuid, response, initStrategy.getPropertyPaths());
|
153
|
//TODO we should move subtree check down to service or persistence
|
154
|
TaxonNode subtree = getSubtreeOrError(subtreeUuid, nodeService, response);
|
155
|
taxonBase = checkExistsSubtreeAndAccess(taxonBase, subtree, NO_UNPUBLISHED, response);
|
156
|
return taxonBase;
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* Checks if a {@link TaxonBase taxonBase} is public and belongs to a {@link TaxonNode subtree}
|
161
|
* as accepted taxon or synonym.
|
162
|
* If not the according {@link HttpStatusMessage http messages} are send to response.
|
163
|
* <BR>
|
164
|
* Not (yet) checked is the relation to a subtree via a concept relationship.
|
165
|
* @param taxonBase
|
166
|
* @param includeUnpublished
|
167
|
* @param response
|
168
|
* @return
|
169
|
* @throws IOException
|
170
|
*/
|
171
|
protected <S extends TaxonBase<?>> S checkExistsSubtreeAndAccess(S taxonBase,
|
172
|
TaxonNode subtree, boolean includeUnpublished,
|
173
|
HttpServletResponse response) throws IOException {
|
174
|
taxonBase = checkExistsAndAccess(taxonBase, NO_UNPUBLISHED, response);
|
175
|
if (subtree == null){
|
176
|
return taxonBase;
|
177
|
}else if(taxonBase != null){
|
178
|
//TODO synonyms maybe can not be initialized
|
179
|
Taxon taxon = taxonBase.isInstanceOf(Synonym.class)?
|
180
|
CdmBase.deproxy(taxonBase, Synonym.class).getAcceptedTaxon():
|
181
|
CdmBase.deproxy(taxonBase, Taxon.class);
|
182
|
//check if taxon has any node that is a descendant of subtree
|
183
|
for (TaxonNode taxonNode :taxon.getTaxonNodes()){
|
184
|
if (subtree.isAncestor(taxonNode)){
|
185
|
return taxonBase;
|
186
|
}
|
187
|
}
|
188
|
HttpStatusMessage.ACCESS_DENIED.send(response);
|
189
|
}
|
190
|
return null;
|
191
|
}
|
192
|
|
193
|
|
194
|
/**
|
195
|
* Get the accepted {@link Taxon} for a given
|
196
|
* {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
|
197
|
* <p>
|
198
|
* URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
|
199
|
*
|
200
|
* @param request
|
201
|
* @param response
|
202
|
* @return a set on a list of {@link Taxon} entities which are initialized
|
203
|
* using the following initialization strategy:
|
204
|
* {@link #DEFAULT_INIT_STRATEGY}
|
205
|
* @throws IOException
|
206
|
*/
|
207
|
@RequestMapping(value = "accepted", method = RequestMethod.GET)
|
208
|
public Taxon doGetAcceptedFor(
|
209
|
@PathVariable("uuid") UUID uuid,
|
210
|
@RequestParam(value = "classificationFilter", required = false) UUID classification_uuid,
|
211
|
HttpServletRequest request,
|
212
|
HttpServletResponse response)
|
213
|
throws IOException {
|
214
|
if(request != null){
|
215
|
logger.info("doGetAcceptedFor() " + requestPathAndQuery(request));
|
216
|
}
|
217
|
|
218
|
try {
|
219
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
220
|
Taxon result = service.findAcceptedTaxonFor(uuid, classification_uuid, includeUnpublished, getInitializationStrategy());
|
221
|
result = checkExistsAndAccess(result, includeUnpublished, response);
|
222
|
|
223
|
return result;
|
224
|
} catch (EntityNotFoundException e){
|
225
|
HttpStatusMessage.UUID_NOT_FOUND.send(response, e.getMessage());
|
226
|
} catch (UnpublishedException e) {
|
227
|
HttpStatusMessage.ACCESS_DENIED.send(response, e.getMessage());
|
228
|
}
|
229
|
return null;
|
230
|
|
231
|
}
|
232
|
|
233
|
@RequestMapping(value = "classifications", method = RequestMethod.GET)
|
234
|
public List<Classification> doGetClassifications(
|
235
|
@PathVariable("uuid") UUID uuid,
|
236
|
HttpServletRequest request,
|
237
|
HttpServletResponse response) throws IOException {
|
238
|
|
239
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
240
|
|
241
|
logger.info("doGetClassifications(): " + request.getRequestURI());
|
242
|
TaxonBase<?> taxonBase = service.load(uuid);
|
243
|
taxonBase = checkExistsAndAccess(taxonBase, includeUnpublished, response);
|
244
|
|
245
|
return service.listClassifications(taxonBase, null, null, getInitializationStrategy());
|
246
|
}
|
247
|
|
248
|
@RequestMapping(value = "taxonNodes", method = RequestMethod.GET)
|
249
|
public Set<TaxonNodeDto> doGetTaxonNodes(
|
250
|
@PathVariable("uuid") UUID taxonUuid,
|
251
|
@RequestParam(value = "subtree", required = false) UUID subtreeUuid,
|
252
|
HttpServletRequest request,
|
253
|
HttpServletResponse response) throws IOException {
|
254
|
|
255
|
logger.info("doGetTaxonNodes" + requestPathAndQuery(request));
|
256
|
TaxonBase<?> taxonBase;
|
257
|
if (subtreeUuid != null){
|
258
|
taxonBase = doGet(taxonUuid, subtreeUuid, request, response);
|
259
|
}else{
|
260
|
taxonBase = service.load(taxonUuid, NO_UNPUBLISHED, getTaxonNodeInitStrategy().getPropertyPaths());
|
261
|
}
|
262
|
if(taxonBase instanceof Taxon){
|
263
|
return ((Taxon)taxonBase).getTaxonNodes().stream().map(e -> new TaxonNodeDto(e)).collect(Collectors.toSet());
|
264
|
} else {
|
265
|
HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
266
|
return null;
|
267
|
}
|
268
|
}
|
269
|
|
270
|
protected EntityInitStrategy getTaxonNodeInitStrategy() {
|
271
|
return TAXONNODE_INIT_STRATEGY;
|
272
|
}
|
273
|
|
274
|
/**
|
275
|
* See also {@link AgentController#doGetTaxonNodeAgentRelations(UUID, UUID, Integer, Integer, HttpServletRequest, HttpServletResponse)}
|
276
|
*/
|
277
|
@RequestMapping(value = "taxonNodeAgentRelations/{classification_uuid}", method = RequestMethod.GET)
|
278
|
public Pager<TaxonNodeAgentRelation> doGetTaxonNodeAgentRelations(
|
279
|
@PathVariable("uuid") UUID uuid,
|
280
|
@PathVariable("classification_uuid") UUID classificationUuid,
|
281
|
@RequestParam(value = "relType_uuid" , required = false) UUID relTypeUuid,
|
282
|
@RequestParam(value = "pageIndex", required = false) Integer pageIndex,
|
283
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
284
|
HttpServletRequest request,
|
285
|
HttpServletResponse response) throws IOException {
|
286
|
|
287
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageIndex);
|
288
|
pagerParams.normalizeAndValidate(response);
|
289
|
|
290
|
Pager<TaxonNodeAgentRelation> pager = nodeService.pageTaxonNodeAgentRelations(uuid, classificationUuid,
|
291
|
null, null, relTypeUuid, pagerParams.getPageSize(), pagerParams.getPageIndex(), null);
|
292
|
return pager;
|
293
|
}
|
294
|
|
295
|
|
296
|
@RequestMapping(value = "specimensOrObservationsCount", method = RequestMethod.GET)
|
297
|
public StringResultDTO doCountSpecimensOrObservations(
|
298
|
@PathVariable("uuid") UUID uuid,
|
299
|
HttpServletRequest request,
|
300
|
HttpServletResponse response) {
|
301
|
logger.info("doListSpecimensOrObservations() - " + request.getRequestURI());
|
302
|
|
303
|
List<OrderHint> orderHints = new ArrayList<>();
|
304
|
orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));
|
305
|
FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
|
306
|
config.setAssociatedTaxonUuid(uuid);
|
307
|
long countSpecimen = occurrenceService.countOccurrences(config);
|
308
|
return new StringResultDTO(String.valueOf(countSpecimen));
|
309
|
}
|
310
|
|
311
|
/**
|
312
|
* @deprecated replaced by rootUnitDTOs
|
313
|
*/
|
314
|
@Deprecated
|
315
|
@RequestMapping(value = "fieldUnitDTOs", method = RequestMethod.GET)
|
316
|
public List<SpecimenOrObservationBaseDTO> doListFieldUnitDTOs(
|
317
|
@PathVariable("uuid") UUID uuid,
|
318
|
HttpServletRequest request,
|
319
|
HttpServletResponse response) {
|
320
|
logger.info("doListFieldUnitDTOs() - " + request.getRequestURI());
|
321
|
|
322
|
List<SpecimenOrObservationBaseDTO> rootUnitDtos = occurrenceService.listRootUnitDTOsByAssociatedTaxon(null, uuid, OccurrenceController.DERIVED_UNIT_INIT_STRATEGY);
|
323
|
return rootUnitDtos.stream().filter(dto -> dto instanceof FieldUnitDTO).collect(Collectors.toList());
|
324
|
}
|
325
|
|
326
|
@RequestMapping(value = "rootUnitDTOs", method = RequestMethod.GET)
|
327
|
public List<SpecimenOrObservationBaseDTO> doListRooUnitDTOs(
|
328
|
@PathVariable("uuid") UUID uuid,
|
329
|
HttpServletRequest request,
|
330
|
HttpServletResponse response) {
|
331
|
logger.info("rootUnitDTOs() - " + request.getRequestURI());
|
332
|
|
333
|
List<SpecimenOrObservationBaseDTO> rootUnitDtos = occurrenceService.listRootUnitDTOsByAssociatedTaxon(null, uuid, OccurrenceController.DERIVED_UNIT_INIT_STRATEGY);
|
334
|
// List<SpecimenOrObservationBase<?>> specimensOrObservations = occurrenceService.listByAssociatedTaxon(null, null, (Taxon)tb, null, null, null, orderHints, null);
|
335
|
return rootUnitDtos;
|
336
|
}
|
337
|
|
338
|
@RequestMapping(value = "specimensOrObservations", method = RequestMethod.GET)
|
339
|
public List<SpecimenOrObservationBase<?>> doListSpecimensOrObservations(
|
340
|
@PathVariable("uuid") UUID uuid,
|
341
|
HttpServletRequest request,
|
342
|
HttpServletResponse response) throws IOException {
|
343
|
logger.info("doListSpecimensOrObservations() - " + request.getRequestURI());
|
344
|
|
345
|
TaxonBase<?> tb = service.load(uuid);
|
346
|
List<OrderHint> orderHints = new ArrayList<>();
|
347
|
orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));
|
348
|
if(tb instanceof Taxon){
|
349
|
List<SpecimenOrObservationBase<?>> specimensOrObservations = occurrenceService.listByAssociatedTaxon(null, null, (Taxon)tb, null, null, null, orderHints, null);
|
350
|
return specimensOrObservations;
|
351
|
} else {
|
352
|
HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
353
|
return null;
|
354
|
}
|
355
|
}
|
356
|
|
357
|
@RequestMapping(value = "associatedRootUnits", method = RequestMethod.GET)
|
358
|
public Pager<SpecimenOrObservationBase> doGetAssociatedRootUnits(
|
359
|
@PathVariable("uuid") UUID uuid,
|
360
|
@RequestParam(value = "maxDepth", required = false) Integer maxDepth,
|
361
|
@RequestParam(value = "pageIndex", required = false) Integer pageIndex,
|
362
|
@RequestParam(value = "pageSize", required = false) Integer pageSize,
|
363
|
HttpServletRequest request,
|
364
|
HttpServletResponse response) throws IOException {
|
365
|
logger.info("doGetAssociatedRootUnits() - " + request.getRequestURI());
|
366
|
|
367
|
TaxonBase<?> taxonBase = service.load(uuid);
|
368
|
taxonBase = checkExistsAndAccess(taxonBase, NO_UNPUBLISHED, response);
|
369
|
|
370
|
List<OrderHint> orderHints = new ArrayList<>();
|
371
|
orderHints.add(new OrderHint("titleCache", SortOrder.ASCENDING));
|
372
|
|
373
|
if(taxonBase instanceof Taxon){
|
374
|
PagerParameters pagerParams = new PagerParameters(pageSize, pageIndex);
|
375
|
pagerParams.normalizeAndValidate(response);
|
376
|
|
377
|
return occurrenceService.pageRootUnitsByAssociatedTaxon(null, null, (Taxon) taxonBase, maxDepth, pagerParams.getPageSize(), pagerParams.getPageIndex(), orderHints, null);
|
378
|
}else{
|
379
|
// FIXME proper HTTP code response
|
380
|
return null;
|
381
|
}
|
382
|
}
|
383
|
|
384
|
@RequestMapping(value = "taggedName", method = RequestMethod.GET)
|
385
|
public ModelAndView doGetTaggedName(
|
386
|
@PathVariable("uuid") UUID uuid,
|
387
|
HttpServletRequest request) {
|
388
|
logger.info("doGetDescriptionElementsByType() - " + request.getRequestURI());
|
389
|
|
390
|
ModelAndView mv = new ModelAndView();
|
391
|
|
392
|
TaxonBase<?> tb = service.load(uuid, NO_UNPUBLISHED, Arrays.asList(new String[] {"name"}));
|
393
|
mv.addObject(nameService.getTaggedName(tb.getName().getUuid()));
|
394
|
return mv;
|
395
|
}
|
396
|
|
397
|
/**
|
398
|
* This webservice endpoint returns all taxa which are congruent or included in the taxon represented by the given taxon uuid.
|
399
|
* The result also returns the path to these taxa represented by the uuids of the taxon relationships types and doubtful information.
|
400
|
* If classificationUuids is set only taxa of classifications are returned which are included in the given classifications.
|
401
|
* Also the path to these taxa may not include taxa from other classifications.
|
402
|
*/
|
403
|
@RequestMapping(value = { "includedTaxa" }, method = { RequestMethod.GET })
|
404
|
public IncludedTaxaDTO doGetIncludedTaxa(
|
405
|
@PathVariable("uuid") UUID uuid,
|
406
|
@RequestParam(value="classificationFilter", required=false) final List<String> classificationStringList,
|
407
|
@RequestParam(value="includeDoubtful", required=false) final boolean includeDoubtful,
|
408
|
@RequestParam(value="onlyCongruent", required=false) final boolean onlyCongruent,
|
409
|
HttpServletResponse response,
|
410
|
HttpServletRequest request) {
|
411
|
|
412
|
|
413
|
if(request != null){
|
414
|
logger.info("doGetIncludedTaxa()" + requestPathAndQuery(request));
|
415
|
}
|
416
|
|
417
|
List<UUID> classificationFilter = null;
|
418
|
if( classificationStringList != null ){
|
419
|
classificationFilter = new ArrayList<>();
|
420
|
for(String classString :classificationStringList){
|
421
|
classificationFilter.add(UUID.fromString(classString));
|
422
|
}
|
423
|
}
|
424
|
IncludedTaxonConfiguration configuration =
|
425
|
new IncludedTaxonConfiguration(classificationFilter, includeDoubtful, onlyCongruent);
|
426
|
IncludedTaxaDTO listIncludedTaxa = service.listIncludedTaxa(uuid, configuration);
|
427
|
return listIncludedTaxa;
|
428
|
}
|
429
|
|
430
|
// TODO ================================================================================ //
|
431
|
// move all description and descriptionElement related methods into the according
|
432
|
// Description Controllers
|
433
|
|
434
|
/**
|
435
|
* Get the list of {@link TaxonDescription}s of the
|
436
|
* {@link Taxon} instance identified by the <code>{taxon-uuid}</code>.
|
437
|
* <p>
|
438
|
* URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/descriptions</b>
|
439
|
*
|
440
|
* @param request
|
441
|
* @param response
|
442
|
* @return a List of {@link TaxonDescription} entities which are initialized
|
443
|
* using the following initialization strategy:
|
444
|
* {@link #TAXONDESCRIPTION_INIT_STRATEGY}
|
445
|
* @throws IOException
|
446
|
*/
|
447
|
@RequestMapping(
|
448
|
value = {"descriptions"},
|
449
|
method = RequestMethod.GET)
|
450
|
public Pager<TaxonDescription> doGetDescriptions(
|
451
|
@PathVariable("uuid") UUID uuid,
|
452
|
@RequestParam(value = "markerTypes", required = false) List<MarkerType> markerTypes,
|
453
|
@RequestParam(value = "descriptionTypes", required = false) List<DescriptionType> descriptionTypes,
|
454
|
HttpServletRequest request,
|
455
|
HttpServletResponse response)throws IOException {
|
456
|
|
457
|
if(request != null){
|
458
|
logger.info("doGetDescriptions()" + requestPathAndQuery(request));
|
459
|
}
|
460
|
|
461
|
Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
|
462
|
taxon = checkExistsAndAccess(taxon, NO_UNPUBLISHED, response);
|
463
|
|
464
|
Set<MarkerType> markerTypesSet = new HashSet<>();
|
465
|
if (markerTypes != null) {
|
466
|
markerTypesSet.addAll(markerTypes);
|
467
|
}
|
468
|
Set<DescriptionType> descriptionTypesSet = new HashSet<>();
|
469
|
if (descriptionTypes != null) {
|
470
|
descriptionTypesSet.addAll(descriptionTypes);
|
471
|
}
|
472
|
|
473
|
List<String> taxonDescriptionInitStrategy = getTaxonDescriptionInitStrategy();
|
474
|
Pager<TaxonDescription> p = descriptionService.pageTaxonDescriptions(taxon, null, null, markerTypesSet, descriptionTypesSet, null, null, taxonDescriptionInitStrategy);
|
475
|
|
476
|
return p;
|
477
|
}
|
478
|
|
479
|
@RequestMapping(value = "descriptions/elementsByType/{classSimpleName}", method = RequestMethod.GET)
|
480
|
public ModelAndView doGetDescriptionElementsByType(
|
481
|
@PathVariable("uuid") UUID uuid,
|
482
|
@PathVariable("classSimpleName") String classSimpleName,
|
483
|
@RequestParam(value = "markerTypes", required = false) List<MarkerType> markerTypes,
|
484
|
@RequestParam(value = "descriptionTypes", required = false) List<DescriptionType> descriptionTypes,
|
485
|
@RequestParam(value = "count", required = false, defaultValue = "false") Boolean doCount,
|
486
|
HttpServletRequest request,
|
487
|
HttpServletResponse response) throws IOException {
|
488
|
logger.info("doGetDescriptionElementsByType() - " + requestPathAndQuery(request));
|
489
|
|
490
|
|
491
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
492
|
|
493
|
ModelAndView mv = new ModelAndView();
|
494
|
|
495
|
List<DescriptionElementBase> allElements = new ArrayList<>();
|
496
|
List<DescriptionElementBase> elements;
|
497
|
int count = 0;
|
498
|
|
499
|
List<String> initStrategy = doCount ? null : getTaxonDescriptionElementInitStrategy();
|
500
|
|
501
|
Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
|
502
|
|
503
|
taxon = checkExistsAndAccess(taxon, includeUnpublished, response);
|
504
|
|
505
|
|
506
|
Set<MarkerType> markerTypesSet = new HashSet<>();
|
507
|
if (markerTypes != null) {
|
508
|
markerTypesSet.addAll(markerTypes);
|
509
|
}
|
510
|
Set<DescriptionType> descriptionTypesSet = new HashSet<>();
|
511
|
if (descriptionTypes != null) {
|
512
|
descriptionTypesSet.addAll(descriptionTypes);
|
513
|
}
|
514
|
|
515
|
List<TaxonDescription> taxonDescriptions = descriptionService.listTaxonDescriptions(
|
516
|
taxon, null, null, markerTypesSet, descriptionTypesSet, null, null, null);
|
517
|
try {
|
518
|
Class type;
|
519
|
type = Class.forName("eu.etaxonomy.cdm.model.description."
|
520
|
+ classSimpleName);
|
521
|
if (taxonDescriptions != null) {
|
522
|
for (TaxonDescription description : taxonDescriptions) {
|
523
|
elements = descriptionService.listDescriptionElements(description, null, type, null, 0, initStrategy);
|
524
|
allElements.addAll(elements);
|
525
|
count += elements.size();
|
526
|
}
|
527
|
|
528
|
}
|
529
|
} catch (ClassNotFoundException e) {
|
530
|
HttpStatusMessage.create(e.getLocalizedMessage(), 400).send(response);
|
531
|
}
|
532
|
if(doCount){
|
533
|
mv.addObject(count);
|
534
|
} else {
|
535
|
mv.addObject(allElements);
|
536
|
}
|
537
|
return mv;
|
538
|
}
|
539
|
|
540
|
@RequestMapping(value = "taxonRelationshipsDTO", method = RequestMethod.GET)
|
541
|
public TaxonRelationshipsDTO doGetTaxonRelationshipsDTO(
|
542
|
@PathVariable("uuid") UUID taxonUuid,
|
543
|
@RequestParam(value = "directTypes", required = false) UuidList directTypeUuids,
|
544
|
@RequestParam(value = "inversTypes", required = false) UuidList inversTypeUuids,
|
545
|
@RequestParam(value = "direction", required = false) Direction direction,
|
546
|
@RequestParam(value="groupMisapplications", required=false, defaultValue="false") final boolean groupMisapplications,
|
547
|
HttpServletRequest request,
|
548
|
HttpServletResponse response) throws IOException {
|
549
|
|
550
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
551
|
|
552
|
logger.info("doGetTaxonRelationshipDTOs(): " + request.getRequestURI());
|
553
|
TaxonBase<?> taxonBase = service.load(taxonUuid);
|
554
|
checkExistsAccessType(taxonBase, includeUnpublished, Taxon.class, response);
|
555
|
|
556
|
Set<TaxonRelationshipType> directTypes = getTermsByUuidSet(TaxonRelationshipType.class, directTypeUuids);
|
557
|
Set<TaxonRelationshipType> inversTypes = getTermsByUuidSet(TaxonRelationshipType.class, inversTypeUuids);
|
558
|
|
559
|
// Set<TaxonRelationshipType> inversTypes = null;
|
560
|
// if (directTypeUuids != null && !directTypeUuids.isEmpty()){
|
561
|
// types = new HashSet<>();
|
562
|
// List<TaxonRelationshipType> typeList = termService.find(TaxonRelationshipType.class, new HashSet<>(directTypeUuids));
|
563
|
// types.addAll(typeList);
|
564
|
// //TODO should we handle missing uuids as error response
|
565
|
//// HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
566
|
// }
|
567
|
|
568
|
|
569
|
|
570
|
// boolean deduplicateMisapplications = true;
|
571
|
Integer pageSize = null;
|
572
|
Integer pageNumber = null;
|
573
|
return service.listTaxonRelationships(taxonUuid, directTypes, inversTypes, direction, groupMisapplications,
|
574
|
includeUnpublished, pageSize, pageNumber);
|
575
|
}
|
576
|
|
577
|
/**
|
578
|
* @param directTypeUuids
|
579
|
* @return
|
580
|
*/
|
581
|
protected <T extends DefinedTermBase<T>> Set<T> getTermsByUuidSet(Class<T> clazz, UuidList directTypeUuids) {
|
582
|
Set<T> directTypes = null;
|
583
|
|
584
|
if (directTypeUuids != null && !directTypeUuids.isEmpty()){
|
585
|
directTypes = new HashSet<>();
|
586
|
List<T> typeList = termService.find(clazz, new HashSet<>(directTypeUuids));
|
587
|
directTypes.addAll(typeList);
|
588
|
//TODO should we handle missing uuids as error response
|
589
|
// HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
|
590
|
}
|
591
|
return directTypes;
|
592
|
}
|
593
|
|
594
|
// TODO ================================================================================ //
|
595
|
|
596
|
}
|