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