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