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