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.Hashtable;
|
16
|
import java.util.Iterator;
|
17
|
import java.util.List;
|
18
|
import java.util.Map;
|
19
|
import java.util.Set;
|
20
|
import java.util.UUID;
|
21
|
|
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.InitBinder;
|
30
|
import org.springframework.web.bind.annotation.PathVariable;
|
31
|
import org.springframework.web.bind.annotation.RequestMapping;
|
32
|
import org.springframework.web.bind.annotation.RequestMethod;
|
33
|
import org.springframework.web.bind.annotation.RequestParam;
|
34
|
import org.springframework.web.servlet.ModelAndView;
|
35
|
|
36
|
import eu.etaxonomy.cdm.api.service.INameService;
|
37
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
38
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
39
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
40
|
import eu.etaxonomy.cdm.api.util.TaxonRelationshipEdge;
|
41
|
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
|
42
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
43
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
44
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
45
|
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
|
46
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
47
|
import eu.etaxonomy.cdm.model.media.Media;
|
48
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
49
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
50
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
51
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
52
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
53
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
54
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
55
|
import eu.etaxonomy.cdm.persistence.dao.initializer.EntityInitStrategy;
|
56
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
57
|
import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;
|
58
|
import eu.etaxonomy.cdm.remote.controller.util.IMediaToolbox;
|
59
|
import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor;
|
60
|
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
|
61
|
import eu.etaxonomy.cdm.remote.editor.MatchModePropertyEditor;
|
62
|
import eu.etaxonomy.cdm.remote.editor.NamedAreaPropertyEditor;
|
63
|
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
|
64
|
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
65
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
66
|
import io.swagger.annotations.Api;
|
67
|
|
68
|
/**
|
69
|
* The TaxonPortalController class is a Spring MVC Controller.
|
70
|
* <p>
|
71
|
* The syntax of the mapped service URIs contains the the {datasource-name} path element.
|
72
|
* The available {datasource-name}s are defined in a configuration file which
|
73
|
* is loaded by the {@link UpdatableRoutingDataSource}. If the
|
74
|
* UpdatableRoutingDataSource is not being used in the actual application
|
75
|
* context any arbitrary {datasource-name} may be used.
|
76
|
* <p>
|
77
|
* Methods mapped at type level, inherited from super classes ({@link BaseController}):
|
78
|
* <blockquote>
|
79
|
* URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}</b>
|
80
|
*
|
81
|
* Get the {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
|
82
|
* The returned Taxon is initialized by
|
83
|
* the following strategy {@link #TAXON_INIT_STRATEGY}
|
84
|
* </blockquote>
|
85
|
*
|
86
|
* @author a.kohlbecker
|
87
|
* @since 20.07.2009
|
88
|
*
|
89
|
*/
|
90
|
@Controller
|
91
|
@Api("portal_taxon")
|
92
|
@RequestMapping(value = {"/portal/taxon/{uuid}"})
|
93
|
public class TaxonPortalController extends TaxonController{
|
94
|
|
95
|
public static final Logger logger = Logger.getLogger(TaxonPortalController.class);
|
96
|
|
97
|
@Autowired
|
98
|
private INameService nameService;
|
99
|
|
100
|
@Autowired
|
101
|
private ITaxonNodeService taxonNodeService;
|
102
|
|
103
|
@Autowired
|
104
|
private ITaxonService taxonService;
|
105
|
|
106
|
@Autowired
|
107
|
private ITermService termService;
|
108
|
|
109
|
@Autowired
|
110
|
private IMediaToolbox mediaToolbox;
|
111
|
|
112
|
|
113
|
public static final EntityInitStrategy TAXON_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
114
|
"$",
|
115
|
"sources",
|
116
|
"statusNote",
|
117
|
// taxon relations, see TaxonRelationshipBeanProcessor
|
118
|
"relationsFromThisTaxon.toTaxon.taxonNodes",
|
119
|
"relationsToThisTaxon.fromTaxon.taxonNodes",
|
120
|
// the name
|
121
|
"name.$",
|
122
|
"name.nomenclaturalSource.citation.authorship",
|
123
|
"name.nomenclaturalSource.citation.inReference.authorship",
|
124
|
"name.rank.representations",
|
125
|
"name.status.type.representations",
|
126
|
"name.status.source.citation",
|
127
|
"sec.authorship"
|
128
|
// "descriptions" // TODO remove
|
129
|
|
130
|
}));
|
131
|
|
132
|
public static final EntityInitStrategy TAXON_WITH_CHILDNODES_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
133
|
"taxonNodes.$",
|
134
|
"taxonNodes.classification.$",
|
135
|
"taxonNodes.childNodes.$"
|
136
|
}));
|
137
|
|
138
|
public static final EntityInitStrategy SIMPLE_TAXON_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
139
|
"$",
|
140
|
// the name
|
141
|
"name.$",
|
142
|
"name.rank.representations",
|
143
|
"name.status.type.representations",
|
144
|
"name.status.source.citation",
|
145
|
"name.nomenclaturalSource.citation.authorship",
|
146
|
"name.nomenclaturalSource.citation.inReference.authorship",
|
147
|
"taxonNodes.classification",
|
148
|
"sec.authorship"
|
149
|
}));
|
150
|
|
151
|
public static final EntityInitStrategy SYNONYMY_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
152
|
// initialize homotypical and heterotypical groups; needs synonyms
|
153
|
"synonyms.$",
|
154
|
"synonyms.name.status.type.representations",
|
155
|
"synonyms.name.status.source.citation",
|
156
|
"synonyms.name.nomenclaturalSource.citation.authorship",
|
157
|
"synonyms.name.nomenclaturalSource.citation.inReference.authorship",
|
158
|
// "synonyms.name.homotypicalGroup.typifiedNames.$",
|
159
|
// "synonyms.name.homotypicalGroup.typifiedNames.taxonBases.$",
|
160
|
"synonyms.name.combinationAuthorship.$",
|
161
|
|
162
|
"name.typeDesignations",
|
163
|
|
164
|
"name.homotypicalGroup.$",
|
165
|
"name.homotypicalGroup.typifiedNames.$",
|
166
|
"name.homotypicalGroup.typifiedNames.nomenclaturalSource.citation.authorship",
|
167
|
"name.homotypicalGroup.typifiedNames.nomenclaturalSource.citation.inReference.authorship",
|
168
|
// "name.homotypicalGroup.typifiedNames.taxonBases.$"
|
169
|
}));
|
170
|
|
171
|
|
172
|
private static final EntityInitStrategy TAXONRELATIONSHIP_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
173
|
"$",
|
174
|
"type.inverseRepresentations",
|
175
|
"fromTaxon.sec",
|
176
|
"fromTaxon.name",
|
177
|
"toTaxon.sec",
|
178
|
"toTaxon.name"
|
179
|
}));
|
180
|
|
181
|
public static final EntityInitStrategy NAMERELATIONSHIP_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
182
|
"$",
|
183
|
"type.inverseRepresentations",
|
184
|
"source.citation",
|
185
|
"toName.$",
|
186
|
"toName.nomenclaturalSource.citation.authorship",
|
187
|
"toName.nomenclaturalSource.citation.inReference.authorship",
|
188
|
"fromName.$",
|
189
|
"fromName.nomenclaturalSource.citation.authorship",
|
190
|
"fromName.nomenclaturalSource.citation.inReference.authorship",
|
191
|
|
192
|
}));
|
193
|
|
194
|
protected static final EntityInitStrategy TAXONDESCRIPTION_INIT_STRATEGY = DescriptionPortalController.DESCRIPTION_INIT_STRATEGY;
|
195
|
|
196
|
protected static final EntityInitStrategy DESCRIPTION_ELEMENT_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
197
|
"$",
|
198
|
"sources.citation.authorship",
|
199
|
"sources.citation.inReference.authorship",
|
200
|
"sources.nameUsedInSource",
|
201
|
"multilanguageText",
|
202
|
"media",
|
203
|
}));
|
204
|
|
205
|
|
206
|
// private static final List<String> NAMEDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
|
207
|
// "uuid",
|
208
|
// "feature",
|
209
|
// "elements.$",
|
210
|
// "elements.multilanguageText",
|
211
|
// "elements.media",
|
212
|
// });
|
213
|
|
214
|
protected static final EntityInitStrategy TAXONDESCRIPTION_MEDIA_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
215
|
"elements.media"
|
216
|
|
217
|
}));
|
218
|
|
219
|
private static final EntityInitStrategy TYPEDESIGNATION_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
220
|
"typeSpecimen.$",
|
221
|
"citation.authorship.$",
|
222
|
"typeName",
|
223
|
"typeStatus"
|
224
|
}));
|
225
|
|
226
|
protected static final EntityInitStrategy TAXONNODE_WITH_CHILDNODES_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
227
|
"childNodes.taxon",
|
228
|
}));
|
229
|
|
230
|
protected static final EntityInitStrategy TAXONNODE_INIT_STRATEGY = new EntityInitStrategy(Arrays.asList(new String []{
|
231
|
"taxonNodes.classification",
|
232
|
"taxonNodes.parent",
|
233
|
"taxonNodes.statusNote.*",
|
234
|
"taxonNodes.taxon.name",
|
235
|
"taxonNodes.taxon.secSource.citation",
|
236
|
"taxonNodes.source.citation.authorship",
|
237
|
"taxonNodes.source.citation.inReference.authorship",
|
238
|
"acceptedTaxon.taxonNodes.classification",
|
239
|
}));
|
240
|
|
241
|
private static final String termTreeUuidPattern = "^/taxon(?:(?:/)([^/?#&\\.]+))+.*";
|
242
|
|
243
|
@Override
|
244
|
protected <CDM_BASE extends CdmBase> List<String> complementInitStrategy(Class<CDM_BASE> clazz,
|
245
|
List<String> pathProperties) {
|
246
|
|
247
|
if(pathProperties != null) {
|
248
|
List<String> complemented = new ArrayList<>(pathProperties);
|
249
|
if(pathProperties.contains("name")) {
|
250
|
// pathProperties for web service request for portal/taxon/{uuid}/name
|
251
|
complemented.add("name.nomenclaturalSource.citation.authorship");
|
252
|
complemented.add("name.nomenclaturalSource.citation.inReference.authorship");
|
253
|
return complemented;
|
254
|
}
|
255
|
}
|
256
|
return pathProperties;
|
257
|
}
|
258
|
|
259
|
public TaxonPortalController(){
|
260
|
super();
|
261
|
setInitializationStrategy(TAXON_INIT_STRATEGY.getPropertyPaths());
|
262
|
}
|
263
|
|
264
|
@Autowired
|
265
|
@Override
|
266
|
public void setService(ITaxonService service) {
|
267
|
this.service = service;
|
268
|
}
|
269
|
|
270
|
@InitBinder
|
271
|
@Override
|
272
|
public void initBinder(WebDataBinder binder) {
|
273
|
super.initBinder(binder);
|
274
|
binder.registerCustomEditor(NamedArea.class, new NamedAreaPropertyEditor());
|
275
|
binder.registerCustomEditor(MatchMode.class, new MatchModePropertyEditor());
|
276
|
binder.registerCustomEditor(Class.class, new CdmTypePropertyEditor());
|
277
|
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
278
|
binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<>(termService));
|
279
|
}
|
280
|
|
281
|
/**
|
282
|
* Get the synonymy for a taxon identified by the <code>{taxon-uuid}</code>.
|
283
|
* The synonymy consists
|
284
|
* of two parts: The group of homotypic synonyms of the taxon and the
|
285
|
* heterotypic synonymy groups of the taxon. The synonymy is ordered
|
286
|
* historically by the type designations and by the publication date of the
|
287
|
* nomenclatural reference
|
288
|
* <p>
|
289
|
* URI:
|
290
|
* <b>/{datasource-name}/portal/taxon/{taxon-uuid}/synonymy</b>
|
291
|
*
|
292
|
*
|
293
|
* @param request
|
294
|
* @param response
|
295
|
* @return a Map with two entries which are mapped by the following keys:
|
296
|
* "homotypicSynonymsByHomotypicGroup", "heterotypicSynonymyGroups",
|
297
|
* containing lists of {@link Synonym}s which // TODO Auto-generated catch block
|
298
|
e.printStackTrace();are initialized using the
|
299
|
* following initialization strategy: {@link #SYNONYMY_INIT_STRATEGY}
|
300
|
*
|
301
|
* @throws IOException
|
302
|
*/
|
303
|
@RequestMapping(
|
304
|
value = {"synonymy"},
|
305
|
method = RequestMethod.GET)
|
306
|
public ModelAndView doGetSynonymy(@PathVariable("uuid") UUID taxonUuid,
|
307
|
@RequestParam(value = "subtree", required = false) UUID subtreeUuid,
|
308
|
HttpServletRequest request,
|
309
|
HttpServletResponse response)throws IOException {
|
310
|
|
311
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
312
|
if(request != null){
|
313
|
logger.info("doGetSynonymy() " + requestPathAndQuery(request));
|
314
|
}
|
315
|
ModelAndView mv = new ModelAndView();
|
316
|
|
317
|
Taxon taxon = getCdmBaseInstance(Taxon.class, taxonUuid, response, getTaxonNodeInitStrategy().getPropertyPaths());
|
318
|
TaxonNode subtree = getSubtreeOrError(subtreeUuid, taxonNodeService, response);
|
319
|
taxon = checkExistsSubtreeAndAccess(taxon, subtree, NO_UNPUBLISHED, response);
|
320
|
|
321
|
Map<String, List<?>> synonymy = new Hashtable<>();
|
322
|
|
323
|
//new
|
324
|
List<List<Synonym>> synonymyGroups = service.getSynonymsByHomotypicGroup(taxon, SYNONYMY_INIT_STRATEGY.getPropertyPaths());
|
325
|
if(!includeUnpublished){
|
326
|
synonymyGroups = removeUnpublishedSynonyms(synonymyGroups);
|
327
|
}
|
328
|
|
329
|
synonymy.put("homotypicSynonymsByHomotypicGroup", synonymyGroups.get(0));
|
330
|
synonymyGroups.remove(0);
|
331
|
synonymy.put("heterotypicSynonymyGroups", synonymyGroups);
|
332
|
|
333
|
//old
|
334
|
// synonymy.put("homotypicSynonymsByHomotypicGroup", service.getHomotypicSynonymsByHomotypicGroup(taxon, SYNONYMY_INIT_STRATEGY));
|
335
|
// synonymy.put("heterotypicSynonymyGroups", service.getHeterotypicSynonymyGroups(taxon, SYNONYMY_INIT_STRATEGY));
|
336
|
|
337
|
mv.addObject(synonymy);
|
338
|
return mv;
|
339
|
}
|
340
|
|
341
|
|
342
|
/**
|
343
|
* @param synonymyGroups
|
344
|
*/
|
345
|
private List<List<Synonym>> removeUnpublishedSynonyms(List<List<Synonym>> synonymyGroups) {
|
346
|
List<List<Synonym>> result = new ArrayList<>();
|
347
|
boolean isHomotypicToAccepted = true;
|
348
|
|
349
|
for (List<Synonym> oldList : synonymyGroups){
|
350
|
List<Synonym> newList = new ArrayList<>();
|
351
|
for (Synonym oldSyn : oldList){
|
352
|
if (oldSyn.isPublish()){
|
353
|
newList.add(oldSyn);
|
354
|
}
|
355
|
}
|
356
|
if (isHomotypicToAccepted || !newList.isEmpty()){
|
357
|
result.add(newList);
|
358
|
}
|
359
|
isHomotypicToAccepted = false;
|
360
|
}
|
361
|
return result;
|
362
|
}
|
363
|
|
364
|
/**
|
365
|
* {@inheritDoc}
|
366
|
*/
|
367
|
@Override
|
368
|
protected List<String> getTaxonDescriptionInitStrategy() {
|
369
|
return TAXONDESCRIPTION_INIT_STRATEGY.getPropertyPaths();
|
370
|
}
|
371
|
|
372
|
@Override
|
373
|
protected List<String> getTaxonDescriptionElementInitStrategy() {
|
374
|
return DESCRIPTION_ELEMENT_INIT_STRATEGY.getPropertyPaths();
|
375
|
}
|
376
|
|
377
|
@Override
|
378
|
protected EntityInitStrategy getTaxonNodeInitStrategy() {
|
379
|
return TAXONNODE_INIT_STRATEGY;
|
380
|
}
|
381
|
|
382
|
/**
|
383
|
* Get the list of {@link TaxonRelationship}s for the given
|
384
|
* {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
|
385
|
* <p>
|
386
|
* URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/taxonRelationships</b>
|
387
|
*
|
388
|
* @param request
|
389
|
* @param response
|
390
|
* @return a List of {@link TaxonRelationship} entities which are initialized
|
391
|
* using the following initialization strategy:
|
392
|
* {@link #TAXONRELATIONSHIP_INIT_STRATEGY}
|
393
|
* @throws IOException
|
394
|
*/
|
395
|
@RequestMapping(
|
396
|
value = {"taxonRelationships"},
|
397
|
method = RequestMethod.GET)
|
398
|
public List<TaxonRelationship> doGetTaxonRelations(@PathVariable("uuid") UUID uuid,
|
399
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
400
|
|
401
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
402
|
logger.info("doGetTaxonRelations()" + requestPathAndQuery(request));
|
403
|
Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, (List<String>)null);
|
404
|
taxon = checkExistsAndAccess(taxon, includeUnpublished, response);
|
405
|
|
406
|
List<TaxonRelationship> toRelationships = service.listToTaxonRelationships(taxon, null,
|
407
|
includeUnpublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY.getPropertyPaths());
|
408
|
List<TaxonRelationship> fromRelationships = service.listFromTaxonRelationships(taxon, null,
|
409
|
includeUnpublished, null, null, null, TAXONRELATIONSHIP_INIT_STRATEGY.getPropertyPaths());
|
410
|
|
411
|
List<TaxonRelationship> allRelationships = new ArrayList<>(toRelationships.size() + fromRelationships.size());
|
412
|
allRelationships.addAll(toRelationships);
|
413
|
allRelationships.addAll(fromRelationships);
|
414
|
|
415
|
return allRelationships;
|
416
|
}
|
417
|
|
418
|
/**
|
419
|
* Get the list of {@link NameRelationship}s of the Name associated with the
|
420
|
* {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
|
421
|
* <p>
|
422
|
* URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
|
423
|
*
|
424
|
* @param request
|
425
|
* @param response
|
426
|
* @return a List of {@link NameRelationship} entities which are initialized
|
427
|
* using the following initialization strategy:
|
428
|
* {@link #NAMERELATIONSHIP_INIT_STRATEGY}
|
429
|
* @throws IOException
|
430
|
*/
|
431
|
@RequestMapping(
|
432
|
value = {"toNameRelationships"},
|
433
|
method = RequestMethod.GET)
|
434
|
public List<NameRelationship> doGetToNameRelations(@PathVariable("uuid") UUID uuid,
|
435
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
436
|
logger.info("doGetNameRelations()" + request.getRequestURI());
|
437
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
438
|
|
439
|
TaxonBase<?> taxonBase = getCdmBaseInstance(TaxonBase.class, uuid, response, (List<String>)null);
|
440
|
taxonBase = checkExistsAndAccess(taxonBase, includeUnpublished, response);
|
441
|
|
442
|
List<NameRelationship> list = nameService.listNameRelationships(taxonBase.getName(), Direction.relatedTo, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY.getPropertyPaths());
|
443
|
return list;
|
444
|
}
|
445
|
|
446
|
/**
|
447
|
* Get the list of {@link NameRelationship}s of the Name associated with the
|
448
|
* {@link TaxonBase} instance identified by the <code>{taxon-uuid}</code>.
|
449
|
* <p>
|
450
|
* URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/nameRelationships</b>
|
451
|
*
|
452
|
* @param request
|
453
|
* @param response
|
454
|
* @return a List of {@link NameRelationship} entities which are initialized
|
455
|
* using the following initialization strategy:
|
456
|
* {@link #NAMERELATIONSHIP_INIT_STRATEGY}
|
457
|
* @throws IOException
|
458
|
*/
|
459
|
@RequestMapping(
|
460
|
value = {"fromNameRelationships"},
|
461
|
method = RequestMethod.GET)
|
462
|
public List<NameRelationship> doGetFromNameRelations(@PathVariable("uuid") UUID uuid,
|
463
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
464
|
logger.info("doGetNameFromNameRelations()" + requestPathAndQuery(request));
|
465
|
|
466
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
467
|
|
468
|
TaxonBase<?> taxonBase = getCdmBaseInstance(TaxonBase.class, uuid, response, SIMPLE_TAXON_INIT_STRATEGY.getPropertyPaths());
|
469
|
taxonBase = checkExistsAndAccess(taxonBase, includeUnpublished, response);
|
470
|
|
471
|
List<NameRelationship> list = nameService.listNameRelationships(taxonBase.getName(), Direction.relatedFrom, null, null, 0, null, NAMERELATIONSHIP_INIT_STRATEGY.getPropertyPaths());
|
472
|
|
473
|
return list;
|
474
|
}
|
475
|
|
476
|
|
477
|
// @RequestMapping(value = "specimens", method = RequestMethod.GET)
|
478
|
// public ModelAndView doGetSpecimens(
|
479
|
// @PathVariable("uuid") UUID uuid,
|
480
|
// HttpServletRequest request,
|
481
|
// HttpServletResponse response) throws IOException, ClassNotFoundException {
|
482
|
// logger.info("doGetSpecimens() - " + request.getRequestURI());
|
483
|
//
|
484
|
// ModelAndView mv = new ModelAndView();
|
485
|
//
|
486
|
// List<DerivedUnitFacade> derivedUnitFacadeList = new ArrayList<>();
|
487
|
//
|
488
|
// // find speciemens in the TaxonDescriptions
|
489
|
// List<TaxonDescription> taxonDescriptions = doGetDescriptions(uuid, request, response);
|
490
|
// if (taxonDescriptions != null) {
|
491
|
//
|
492
|
// for (TaxonDescription description : taxonDescriptions) {
|
493
|
// derivedUnitFacadeList.addAll( occurrenceService.listDerivedUnitFacades(description, null) );
|
494
|
// }
|
495
|
// }
|
496
|
// // TODO find specimens in the NameDescriptions ??
|
497
|
//
|
498
|
// // TODO also find type specimens
|
499
|
//
|
500
|
// mv.addObject(derivedUnitFacadeList);
|
501
|
//
|
502
|
// return mv;
|
503
|
// }
|
504
|
|
505
|
/**
|
506
|
* Get the {@link Media} attached to the {@link Taxon} instance
|
507
|
* identified by the <code>{taxon-uuid}</code>.
|
508
|
*
|
509
|
* Usage /{datasource-name}/portal/taxon/{taxon-
|
510
|
* uuid}/media/{mime type
|
511
|
* list}/{size}[,[widthOrDuration}][,{height}]/
|
512
|
*
|
513
|
* Whereas
|
514
|
* <ul>
|
515
|
* <li><b>{mime type list}</b>: a comma separated list of mime types, in the
|
516
|
* order of preference. The forward slashes contained in the mime types must
|
517
|
* be replaced by a colon. Regular expressions can be used. Each media
|
518
|
* associated with this given taxon is being searched whereas the first
|
519
|
* matching mime type matching a representation always rules.</li>
|
520
|
* <li><b>{size},{widthOrDuration},{height}</b>: <i>not jet implemented</i>
|
521
|
* valid values are an integer or the asterisk '*' as a wildcard</li>
|
522
|
* </ul>
|
523
|
*
|
524
|
* @param request
|
525
|
* @param response
|
526
|
* @return a List of {@link Media} entities which are initialized
|
527
|
* using the following initialization strategy:
|
528
|
* {@link #TAXONDESCRIPTION_INIT_STRATEGY}
|
529
|
* @throws IOException
|
530
|
*/
|
531
|
@RequestMapping(
|
532
|
value = {"media"},
|
533
|
method = RequestMethod.GET)
|
534
|
public List<Media> doGetMedia(
|
535
|
@PathVariable("uuid") UUID uuid,
|
536
|
@RequestParam(value = "type", required = false) Class<? extends MediaRepresentationPart> type,
|
537
|
@RequestParam(value = "mimeTypes", required = false) String[] mimeTypes,
|
538
|
@RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
|
539
|
@RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
|
540
|
@RequestParam(value = "includeTaxonDescriptions", required = true) Boolean includeTaxonDescriptions,
|
541
|
@RequestParam(value = "includeOccurrences", required = true) Boolean includeOccurrences,
|
542
|
@RequestParam(value = "includeTaxonNameDescriptions", required = true) Boolean includeTaxonNameDescriptions,
|
543
|
@RequestParam(value = "widthOrDuration", required = false) Integer widthOrDuration,
|
544
|
@RequestParam(value = "height", required = false) Integer height,
|
545
|
@RequestParam(value = "size", required = false) Integer size,
|
546
|
HttpServletRequest request, HttpServletResponse response) throws IOException {
|
547
|
|
548
|
logger.info("doGetMedia() " + requestPathAndQuery(request));
|
549
|
|
550
|
List<String> initStrategy = null;
|
551
|
|
552
|
EntityMediaContext<Taxon> taxonMediaContext = loadMediaForTaxonAndRelated(uuid, relationshipUuids,
|
553
|
relationshipInversUuids, includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions,
|
554
|
response, initStrategy, MediaPortalController.MEDIA_INIT_STRATEGY.getPropertyPaths());
|
555
|
|
556
|
List<Media> mediafilteredForPreferredRepresentations = mediaToolbox.processAndFilterPreferredMediaRepresentations(type, mimeTypes, widthOrDuration, height, size,
|
557
|
taxonMediaContext.media);
|
558
|
|
559
|
return mediafilteredForPreferredRepresentations;
|
560
|
}
|
561
|
|
562
|
/**
|
563
|
* @param uuid
|
564
|
* @param type
|
565
|
* @param mimeTypes
|
566
|
* @param relationshipUuids
|
567
|
* @param relationshipInversUuids
|
568
|
* @param includeTaxonDescriptions
|
569
|
* @param includeOccurrences
|
570
|
* @param includeTaxonNameDescriptions
|
571
|
* @param widthOrDuration
|
572
|
* @param height
|
573
|
* @param size
|
574
|
* @param response
|
575
|
* @param initStrategy
|
576
|
* @return
|
577
|
* @throws IOException
|
578
|
* @Deprecated To be replaced by other loadMediaForTaxonAndRelated method
|
579
|
*/
|
580
|
@Deprecated
|
581
|
public EntityMediaContext<Taxon> loadMediaForTaxonAndRelated(UUID uuid,
|
582
|
UuidList relationshipUuids, UuidList relationshipInversUuids,
|
583
|
Boolean includeTaxonDescriptions, Boolean includeOccurrences, Boolean includeTaxonNameDescriptions,
|
584
|
HttpServletResponse response,
|
585
|
List<String> taxonInitStrategy) throws IOException {
|
586
|
return loadMediaForTaxonAndRelated(uuid, relationshipUuids, relationshipInversUuids,
|
587
|
includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions, response, taxonInitStrategy, null);
|
588
|
}
|
589
|
|
590
|
/**
|
591
|
* @param uuid
|
592
|
* @param type
|
593
|
* @param mimeTypes
|
594
|
* @param relationshipUuids
|
595
|
* @param relationshipInversUuids
|
596
|
* @param includeTaxonDescriptions
|
597
|
* @param includeOccurrences
|
598
|
* @param includeTaxonNameDescriptions
|
599
|
* @param widthOrDuration
|
600
|
* @param height
|
601
|
* @param size
|
602
|
* @param response
|
603
|
* @param initStrategy
|
604
|
* @return
|
605
|
* @throws IOException
|
606
|
*/
|
607
|
public EntityMediaContext<Taxon> loadMediaForTaxonAndRelated(UUID uuid,
|
608
|
UuidList relationshipUuids, UuidList relationshipInversUuids,
|
609
|
Boolean includeTaxonDescriptions, Boolean includeOccurrences, Boolean includeTaxonNameDescriptions,
|
610
|
HttpServletResponse response,
|
611
|
List<String> taxonInitStrategy, List<String> mediaInitStrategy) throws IOException {
|
612
|
|
613
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
614
|
|
615
|
|
616
|
Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, taxonInitStrategy);
|
617
|
taxon = checkExistsAndAccess(taxon, includeUnpublished, response);
|
618
|
|
619
|
Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);
|
620
|
|
621
|
List<Media> media = listMediaForTaxon(taxon, includeRelationships,
|
622
|
includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions, mediaInitStrategy);
|
623
|
|
624
|
EntityMediaContext<Taxon> entityMediaContext = new EntityMediaContext<Taxon>(taxon, media);
|
625
|
|
626
|
return entityMediaContext;
|
627
|
}
|
628
|
|
629
|
@RequestMapping(
|
630
|
value = {"subtree/media"},
|
631
|
method = RequestMethod.GET)
|
632
|
public List<Media> doGetSubtreeMedia(
|
633
|
@PathVariable("uuid") UUID uuid,
|
634
|
@RequestParam(value = "type", required = false) Class<? extends MediaRepresentationPart> type,
|
635
|
@RequestParam(value = "mimeTypes", required = false) String[] mimeTypes,
|
636
|
@RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
|
637
|
@RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
|
638
|
@RequestParam(value = "includeTaxonDescriptions", required = true) Boolean includeTaxonDescriptions,
|
639
|
@RequestParam(value = "includeOccurrences", required = true) Boolean includeOccurrences,
|
640
|
@RequestParam(value = "includeTaxonNameDescriptions", required = true) Boolean includeTaxonNameDescriptions,
|
641
|
@RequestParam(value = "widthOrDuration", required = false) Integer widthOrDuration,
|
642
|
@RequestParam(value = "height", required = false) Integer height,
|
643
|
@RequestParam(value = "size", required = false) Integer size,
|
644
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
645
|
|
646
|
|
647
|
boolean includeUnpublished = NO_UNPUBLISHED;
|
648
|
|
649
|
logger.info("doGetSubtreeMedia() " + requestPathAndQuery(request));
|
650
|
|
651
|
List<String> initStrategy = TAXON_WITH_CHILDNODES_INIT_STRATEGY.getPropertyPaths();
|
652
|
|
653
|
Taxon taxon = getCdmBaseInstance(Taxon.class, uuid, response, initStrategy);
|
654
|
taxon = checkExistsAndAccess(taxon, includeUnpublished, response);
|
655
|
|
656
|
Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);
|
657
|
|
658
|
List<Media> media = listMediaForTaxon(taxon, includeRelationships,
|
659
|
includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions, null);
|
660
|
media = addTaxonomicChildrenMedia(includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions, taxon,
|
661
|
includeRelationships, media);
|
662
|
|
663
|
List<Media> mediafilteredForPreferredRepresentations = mediaToolbox.processAndFilterPreferredMediaRepresentations(type, mimeTypes, widthOrDuration, height, size,
|
664
|
media);
|
665
|
|
666
|
return mediafilteredForPreferredRepresentations;
|
667
|
}
|
668
|
|
669
|
/**
|
670
|
* @param includeTaxonDescriptions
|
671
|
* @param includeOccurrences
|
672
|
* @param includeTaxonNameDescriptions
|
673
|
* @param taxon
|
674
|
* @param includeRelationships
|
675
|
* @param media
|
676
|
*/
|
677
|
public List<Media> addTaxonomicChildrenMedia(Boolean includeTaxonDescriptions, Boolean includeOccurrences,
|
678
|
Boolean includeTaxonNameDescriptions, Taxon taxon, Set<TaxonRelationshipEdge> includeRelationships,
|
679
|
List<Media> media) {
|
680
|
|
681
|
//TODO use treeindex
|
682
|
//looking for all medias of direct children
|
683
|
TaxonNode node;
|
684
|
if (taxon.getTaxonNodes().size()>0){
|
685
|
Set<TaxonNode> nodes = taxon.getTaxonNodes();
|
686
|
Iterator<TaxonNode> iterator = nodes.iterator();
|
687
|
//TaxonNode holen
|
688
|
node = iterator.next();
|
689
|
//Check if TaxonNode belongs to the current tree
|
690
|
|
691
|
node = taxonNodeService.load(node.getUuid(), TAXONNODE_WITH_CHILDNODES_INIT_STRATEGY.getPropertyPaths());
|
692
|
List<TaxonNode> children = node.getChildNodes();
|
693
|
Taxon childTaxon;
|
694
|
for (TaxonNode child : children){
|
695
|
childTaxon = child.getTaxon();
|
696
|
if(childTaxon != null) {
|
697
|
childTaxon = (Taxon)taxonService.load(childTaxon.getUuid(), NO_UNPUBLISHED, null);
|
698
|
media.addAll(listMediaForTaxon(childTaxon, includeRelationships,
|
699
|
includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions, MediaPortalController.MEDIA_INIT_STRATEGY.getPropertyPaths()));
|
700
|
}
|
701
|
}
|
702
|
}
|
703
|
return media;
|
704
|
}
|
705
|
|
706
|
/**
|
707
|
*
|
708
|
* @param taxon
|
709
|
* @param includeRelationships
|
710
|
* @param type
|
711
|
* @param mimeTypes
|
712
|
* @param widthOrDuration
|
713
|
* @param height
|
714
|
* @param size
|
715
|
* @return
|
716
|
*/
|
717
|
private List<Media> listMediaForTaxon(Taxon taxon, Set<TaxonRelationshipEdge> includeRelationships,
|
718
|
Boolean includeTaxonDescriptions, Boolean includeOccurrences, Boolean includeTaxonNameDescriptions, List<String> propertyPath) {
|
719
|
|
720
|
List<Media> media = service.listMedia(taxon, includeRelationships,
|
721
|
false, includeTaxonDescriptions, includeOccurrences, includeTaxonNameDescriptions, propertyPath);
|
722
|
|
723
|
return media;
|
724
|
}
|
725
|
|
726
|
|
727
|
public class EntityMediaContext<T extends IdentifiableEntity> {
|
728
|
|
729
|
T entity;
|
730
|
List<Media> media;
|
731
|
/**
|
732
|
* @param entity
|
733
|
* @param media
|
734
|
*/
|
735
|
public EntityMediaContext(T entity, List<Media> media) {
|
736
|
|
737
|
this.entity = HibernateProxyHelper.deproxy(entity);
|
738
|
this.media = media;
|
739
|
}
|
740
|
public T getEntity() {
|
741
|
return entity;
|
742
|
}
|
743
|
public List<Media> getMedia() {
|
744
|
return media;
|
745
|
}
|
746
|
/**
|
747
|
* @param addTaxonomicChildrenMedia
|
748
|
*/
|
749
|
public void setMedia(List<Media> media) {
|
750
|
this.media = media;
|
751
|
|
752
|
}
|
753
|
|
754
|
|
755
|
|
756
|
}
|
757
|
|
758
|
// ---------------------- code snippet preserved for possible later use --------------------
|
759
|
// @RequestMapping(
|
760
|
// value = {"//*/portal/taxon/*/descriptions"}, // mapped as absolute path, see CdmAntPathMatcher
|
761
|
// method = RequestMethod.GET)
|
762
|
// public List<TaxonDescription> doGetDescriptionsbyFeatureTree(HttpServletRequest request, HttpServletResponse response)throws IOException {
|
763
|
// TaxonBase tb = getCdmBase(request, response, null, Taxon.class);
|
764
|
// if(tb instanceof Taxon){
|
765
|
// //T O D O this is a quick and dirty implementation -> generalize
|
766
|
// UUID featureTreeUuid = readValueUuid(request, termTreeUuidPattern);
|
767
|
//
|
768
|
// FeatureTree featureTree = descriptionService.getFeatureTreeByUuid(featureTreeUuid);
|
769
|
// Pager<TaxonDescription> p = descriptionService.getTaxonDescriptions((Taxon)tb, null, null, null, null, TAXONDESCRIPTION_INIT_STRATEGY);
|
770
|
// List<TaxonDescription> descriptions = p.getRecords();
|
771
|
//
|
772
|
// if(!featureTree.isDescriptionSeparated()){
|
773
|
//
|
774
|
// TaxonDescription superDescription = TaxonDescription.NewInstance();
|
775
|
// //put all descriptionElements in superDescription and make it invisible
|
776
|
// for(TaxonDescription description: descriptions){
|
777
|
// for(DescriptionElementBase element: description.getElements()){
|
778
|
// superDescription.addElement(element);
|
779
|
// }
|
780
|
// }
|
781
|
// List<TaxonDescription> separatedDescriptions = new ArrayList<TaxonDescription>(descriptions.size());
|
782
|
// separatedDescriptions.add(superDescription);
|
783
|
// return separatedDescriptions;
|
784
|
// }else{
|
785
|
// return descriptions;
|
786
|
// }
|
787
|
// } else {
|
788
|
// response.sendError(HttpServletResponse.SC_NOT_FOUND, "invalid type; Taxon expected but " + tb.getClass().getSimpleName() + " found.");
|
789
|
// return null;
|
790
|
// }
|
791
|
// }
|
792
|
|
793
|
}
|