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