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.taxeditor.model;
|
11
|
|
12
|
import java.lang.reflect.InvocationTargetException;
|
13
|
import java.lang.reflect.Method;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
|
18
|
import org.apache.commons.lang.StringUtils;
|
19
|
import org.hibernate.LazyInitializationException;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.service.DefaultCategoricalDescriptionBuilder;
|
22
|
import eu.etaxonomy.cdm.api.service.DefaultQuantitativeDescriptionBuilder;
|
23
|
import eu.etaxonomy.cdm.api.service.DescriptionBuilder;
|
24
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
25
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
26
|
import eu.etaxonomy.cdm.model.common.Group;
|
27
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
28
|
import eu.etaxonomy.cdm.model.common.Language;
|
29
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
30
|
import eu.etaxonomy.cdm.model.common.LanguageStringBase;
|
31
|
import eu.etaxonomy.cdm.model.common.Marker;
|
32
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
33
|
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
|
34
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
35
|
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
|
36
|
import eu.etaxonomy.cdm.model.common.Representation;
|
37
|
import eu.etaxonomy.cdm.model.common.User;
|
38
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
39
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
40
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
41
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
42
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
43
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
44
|
import eu.etaxonomy.cdm.model.description.Feature;
|
45
|
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
|
46
|
import eu.etaxonomy.cdm.model.description.KeyStatement;
|
47
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
48
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
49
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
50
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
51
|
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
|
52
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
53
|
import eu.etaxonomy.cdm.model.description.TextData;
|
54
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
55
|
import eu.etaxonomy.cdm.model.media.Media;
|
56
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
57
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
58
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
59
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
60
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
61
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
62
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
63
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
|
64
|
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
|
65
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
66
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
67
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
68
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
69
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
70
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
71
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
72
|
|
73
|
/**
|
74
|
* <p>DescriptionHelper class.</p>
|
75
|
*
|
76
|
* @author p.ciardelli
|
77
|
* @author n.hoffmann
|
78
|
* @created 02.04.2009
|
79
|
*/
|
80
|
public class DescriptionHelper {
|
81
|
|
82
|
/**
|
83
|
* Returns whatever the element's title cache equivalent is,
|
84
|
* depending on its class.
|
85
|
*
|
86
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
87
|
* @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
|
88
|
* @return a {@link java.lang.String} object.
|
89
|
*/
|
90
|
public static String getCache(DescriptionElementBase element,
|
91
|
Language language) {
|
92
|
|
93
|
String mainElementLabel= null;
|
94
|
DescriptionBase<?> descr = element.getInDescription();
|
95
|
descr = CdmBase.deproxy(descr, DescriptionBase.class);
|
96
|
|
97
|
if (descr != null){
|
98
|
if (descr.isInstanceOf(TaxonDescription.class)){
|
99
|
Taxon taxon = CdmBase.deproxy(descr, TaxonDescription.class).getTaxon();
|
100
|
if (taxon != null){
|
101
|
mainElementLabel = taxon.getTitleCache();
|
102
|
}
|
103
|
}else if (descr.isInstanceOf(SpecimenDescription.class)){
|
104
|
SpecimenOrObservationBase<?> specimen = CdmBase.deproxy(descr, SpecimenDescription.class).getDescribedSpecimenOrObservation();
|
105
|
if (specimen != null){
|
106
|
mainElementLabel = specimen.getTitleCache();
|
107
|
}
|
108
|
}else if (descr.isInstanceOf(TaxonNameDescription.class)){
|
109
|
TaxonName name = CdmBase.deproxy(descr, TaxonNameDescription.class).getTaxonName();
|
110
|
if (name != null){
|
111
|
mainElementLabel = name.getTitleCache();
|
112
|
}
|
113
|
}
|
114
|
}
|
115
|
|
116
|
|
117
|
String cache = null;
|
118
|
if (element instanceof TextData) {
|
119
|
//cache = ((TextData) element).getText(language);
|
120
|
cache = "Text Data";
|
121
|
}
|
122
|
if (element instanceof CommonTaxonName) {
|
123
|
cache = ((CommonTaxonName) element).getName();
|
124
|
}
|
125
|
if (element instanceof TaxonInteraction) {
|
126
|
Taxon taxon2 = ((TaxonInteraction) element).getTaxon2();
|
127
|
if(taxon2 != null && taxon2.getName() != null){
|
128
|
cache = taxon2.getName().getTitleCache();
|
129
|
}else{
|
130
|
cache = "No taxon chosen";
|
131
|
}
|
132
|
|
133
|
}
|
134
|
if (element instanceof Distribution) {
|
135
|
Distribution distribution = (Distribution) element;
|
136
|
|
137
|
NamedArea area = distribution.getArea();
|
138
|
if(area != null){
|
139
|
cache = area.getLabel();
|
140
|
|
141
|
PresenceAbsenceTerm status = distribution.getStatus();
|
142
|
if (status == null){
|
143
|
cache += ", no status";
|
144
|
}else {
|
145
|
cache += ", " + status.getLabel();
|
146
|
}
|
147
|
}
|
148
|
}
|
149
|
String result = cache == null ? "" : cache;
|
150
|
if (StringUtils.isNotBlank(mainElementLabel)){
|
151
|
result = CdmUtils.concat(" ", result, "(" + mainElementLabel + ")");
|
152
|
}
|
153
|
return result;
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Returns whatever the element's title cache equivalent is,
|
158
|
* depending on its class, using the default language.
|
159
|
*
|
160
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
161
|
* @return a {@link java.lang.String} object.
|
162
|
*/
|
163
|
public static String getCache(DescriptionElementBase element) {
|
164
|
return getCache(element, CdmStore.getDefaultLanguage());
|
165
|
}
|
166
|
|
167
|
/**
|
168
|
* Set whatever the element's title cache equivalent is,
|
169
|
* depending on its class.
|
170
|
*
|
171
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
172
|
* @param value a {@link java.lang.String} object.
|
173
|
* @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
|
174
|
*/
|
175
|
public static void setCache(DescriptionElementBase element,
|
176
|
String value, Language language) {
|
177
|
if (element instanceof TextData) {
|
178
|
((TextData) element).putText(language, value);
|
179
|
return;
|
180
|
}else if (element instanceof CommonTaxonName) {
|
181
|
((CommonTaxonName) element).setName(value);
|
182
|
return;
|
183
|
}else if (element instanceof TaxonInteraction) {
|
184
|
|
185
|
}else if(element instanceof Distribution){
|
186
|
MessagingUtils.warn(DescriptionHelper.class, "trying to set cache on distribution, don't know what to do at the moment.");
|
187
|
return;
|
188
|
}else{
|
189
|
MessagingUtils.warn(DescriptionHelper.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
|
190
|
}
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* Set whatever the element's title cache equivalent is,
|
195
|
* depending on its class, using the default language.
|
196
|
*
|
197
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
|
198
|
* @param value a {@link java.lang.String} object.
|
199
|
*/
|
200
|
public static void setCache(DescriptionElementBase element,
|
201
|
String value) {
|
202
|
setCache(element, value, CdmStore.getDefaultLanguage());
|
203
|
}
|
204
|
|
205
|
|
206
|
/**
|
207
|
* <p>getObjectDescription</p>
|
208
|
*
|
209
|
* @param element a {@link java.lang.Object} object.
|
210
|
* @return a {@link java.lang.String} object.
|
211
|
*/
|
212
|
public static String getObjectDescription(Object element) {
|
213
|
String resultString = null;
|
214
|
if (element instanceof IdentifiableEntity) {
|
215
|
try{
|
216
|
resultString = ((IdentifiableEntity) element).getTitleCache();
|
217
|
}catch(LazyInitializationException e){
|
218
|
String result = "No Session to initialize title cache for IdentifiableEntity";
|
219
|
MessagingUtils.error(DescriptionHelper.class, result, e);
|
220
|
resultString = "TODO: " + result;
|
221
|
}
|
222
|
}else if (element instanceof OriginalSourceBase) {
|
223
|
try{
|
224
|
OriginalSourceBase<?> originalSource = (OriginalSourceBase<?>) element;
|
225
|
// ISourceable sourcedObject = originalSource.getSourcedObj();
|
226
|
//due to #5743 the bidirectionality for sourced object had to be removed
|
227
|
String sourceObjectTitle = "sourced object data not available (#5743)";
|
228
|
// if(sourcedObject instanceof IIdentifiableEntity){
|
229
|
// sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
|
230
|
// }else if(sourcedObject instanceof DescriptionElementBase){
|
231
|
// sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
|
232
|
// }else{
|
233
|
// throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
|
234
|
// }
|
235
|
|
236
|
resultString = CdmUtils.concat("; ", new String[]{originalSource.getIdNamespace(), originalSource.getIdInSource(), sourceObjectTitle});
|
237
|
}catch(LazyInitializationException e){
|
238
|
String result = "Error initializing title cache for ISourceable of an OriginalSourceBase";
|
239
|
MessagingUtils.error(DescriptionHelper.class, result, e);
|
240
|
resultString = "TODO: " + result;
|
241
|
}
|
242
|
}else if (element instanceof LanguageStringBase) {
|
243
|
resultString = ((LanguageStringBase) element).getText();
|
244
|
}else if (element instanceof DescriptionElementBase) {
|
245
|
resultString = getCache((DescriptionElementBase) element);
|
246
|
}else if (element instanceof RelationshipBase<?, ?, ?>) {
|
247
|
resultString = getCache((RelationshipBase<?, ?, ?>) element);
|
248
|
}else if (element instanceof TypeDesignationBase<?>) {
|
249
|
resultString = getCache((TypeDesignationBase<?>) element);
|
250
|
}else if (element instanceof HomotypicalGroup) {
|
251
|
resultString = getCache((HomotypicalGroup) element);
|
252
|
}else if (element instanceof TaxonNode) {
|
253
|
resultString = getCache((TaxonNode) element);
|
254
|
}else if (element instanceof DeterminationEvent) {
|
255
|
resultString = getCache((DeterminationEvent) element);
|
256
|
}else if (element instanceof Marker) {
|
257
|
Marker marker = (Marker) element;
|
258
|
MarkerType type = marker.getMarkerType();
|
259
|
resultString = (type == null ? "- no marker type -" : marker.getMarkerType().getLabel()) + " (" + marker.getFlag() + ")";
|
260
|
}else if (element instanceof User) {
|
261
|
User user = (User) element;
|
262
|
resultString = user.getUsername();
|
263
|
}else if (element instanceof Group) {
|
264
|
Group group = (Group) element;
|
265
|
resultString = group.getName();
|
266
|
}else if (element instanceof KeyStatement) {
|
267
|
KeyStatement keyStatement = (KeyStatement) element;
|
268
|
resultString = getCache(keyStatement);
|
269
|
}else{
|
270
|
// TODO write return texts for HomotypicalGroup, etc.
|
271
|
resultString = element.toString();
|
272
|
}
|
273
|
|
274
|
if (resultString == null){
|
275
|
resultString = element.toString();
|
276
|
}
|
277
|
return resultString;
|
278
|
}
|
279
|
|
280
|
|
281
|
private static String getCache(DeterminationEvent detEvent) {
|
282
|
//taxon
|
283
|
String taxonStr = null;
|
284
|
TaxonName taxonName = detEvent.getTaxonName();
|
285
|
TaxonBase<?> taxon = detEvent.getTaxon();
|
286
|
if (taxonName != null){
|
287
|
taxonStr = taxonName.getTitleCache();
|
288
|
}
|
289
|
if (StringUtils.isBlank(taxonStr) && taxon != null){
|
290
|
taxonStr = taxon.getTitleCache();
|
291
|
}
|
292
|
if (StringUtils.isBlank(taxonStr)){
|
293
|
taxonStr = "no or unlabled taxon";
|
294
|
}
|
295
|
|
296
|
|
297
|
//unit
|
298
|
SpecimenOrObservationBase<?> unit = detEvent.getIdentifiedUnit();
|
299
|
String unitStr;
|
300
|
if (unit != null){
|
301
|
unitStr = unit.getTitleCache();
|
302
|
if (StringUtils.isBlank(unitStr)){
|
303
|
unitStr = "Unlabled unit";
|
304
|
}
|
305
|
}else{
|
306
|
unitStr = "no unit";
|
307
|
}
|
308
|
|
309
|
String result = CdmUtils.concat(" determined as ", unitStr, taxonStr);
|
310
|
|
311
|
return result;
|
312
|
}
|
313
|
|
314
|
private static String getCache(TaxonNode taxonNode) {
|
315
|
String result = "";
|
316
|
Classification classification = taxonNode.getClassification();
|
317
|
if (classification != null){
|
318
|
String classificationStr = classification.getName() == null ? "" : classification.getName().getText();
|
319
|
result = CdmUtils.concat("" , result, classificationStr);
|
320
|
if (StringUtils.isBlank(result)){
|
321
|
result = classification.toString();
|
322
|
}
|
323
|
}
|
324
|
String parentStr;
|
325
|
TaxonNode parentNode = taxonNode.getParent();
|
326
|
if (parentNode == null){
|
327
|
parentStr = "no parent";
|
328
|
}else{
|
329
|
Taxon parentTaxon = parentNode.getTaxon();
|
330
|
if (parentTaxon == null){
|
331
|
parentStr = "no parent taxon";
|
332
|
}else{
|
333
|
TaxonName parentName = parentTaxon.getName();
|
334
|
if (parentName == null){
|
335
|
parentStr = "child of " + parentTaxon.getTitleCache();
|
336
|
}else{
|
337
|
parentStr = "child of " + parentName.getTitleCache();
|
338
|
}
|
339
|
}
|
340
|
}
|
341
|
result = CdmUtils.concat(": ", result, parentStr);
|
342
|
|
343
|
return result;
|
344
|
}
|
345
|
|
346
|
private static String getCache(TypeDesignationBase<?> designation) {
|
347
|
designation = CdmBase.deproxy(designation);
|
348
|
TypeDesignationStatusBase<?> status = designation.getTypeStatus();
|
349
|
Set<TaxonName> from;
|
350
|
IdentifiableEntity<?> to;
|
351
|
from = designation.getTypifiedNames();
|
352
|
if (designation.isInstanceOf(SpecimenTypeDesignation.class)){
|
353
|
to = ((SpecimenTypeDesignation)designation).getTypeSpecimen();
|
354
|
}else if (designation.isInstanceOf(NameTypeDesignation.class)){
|
355
|
to = ((NameTypeDesignation)designation).getTypeName();
|
356
|
}else{
|
357
|
throw new RuntimeException("Type Designation class not supported: " + designation.getClass().getName());
|
358
|
}
|
359
|
String typeLabel = null;
|
360
|
if (status != null){
|
361
|
Representation typeRepr = status.getPreferredRepresentation(CdmStore.getDefaultLanguage());
|
362
|
if (typeRepr != null){
|
363
|
typeLabel = typeRepr.getAbbreviatedLabel();
|
364
|
}
|
365
|
if (StringUtils.isBlank(typeLabel) && typeRepr != null){
|
366
|
typeLabel = typeRepr.getLabel();
|
367
|
}
|
368
|
if (StringUtils.isBlank(typeLabel) ){
|
369
|
typeLabel = status.getSymbol();
|
370
|
}
|
371
|
if (StringUtils.isBlank(typeLabel)){
|
372
|
typeLabel = status.getTitleCache();
|
373
|
}
|
374
|
}
|
375
|
if (StringUtils.isBlank(typeLabel)){
|
376
|
typeLabel = "->";
|
377
|
}
|
378
|
String fromString = "";
|
379
|
for (TaxonName name : from){
|
380
|
CdmUtils.concat(",", fromString, name.getTitleCache());
|
381
|
}
|
382
|
String result = CdmUtils.concat(" ", new String[]{from == null ? null : fromString,
|
383
|
typeLabel, to == null? null : to.getTitleCache()});
|
384
|
return result;
|
385
|
}
|
386
|
|
387
|
private static String getCache(RelationshipBase<?, ?, ?> rel) {
|
388
|
rel = CdmBase.deproxy(rel);
|
389
|
RelationshipTermBase<?> type = rel.getType();
|
390
|
IdentifiableEntity<?> from;
|
391
|
IdentifiableEntity<?> to;
|
392
|
if (rel.isInstanceOf(NameRelationship.class)){
|
393
|
from = ((NameRelationship)rel).getFromName();
|
394
|
to = ((NameRelationship)rel).getToName();
|
395
|
}else if (rel.isInstanceOf(HybridRelationship.class)){
|
396
|
from = ((HybridRelationship)rel).getParentName();
|
397
|
to = ((HybridRelationship)rel).getHybridName();
|
398
|
}else if (rel.isInstanceOf(TaxonRelationship.class)){
|
399
|
from = ((TaxonRelationship)rel).getFromTaxon();
|
400
|
to = ((TaxonRelationship)rel).getToTaxon();
|
401
|
}else{
|
402
|
try {
|
403
|
Method fromMethod = rel.getClass().getMethod("getRelatedFrom");
|
404
|
Method toMethod = rel.getClass().getMethod("getRelatedFrom");
|
405
|
fromMethod.setAccessible(true);
|
406
|
toMethod.setAccessible(true);
|
407
|
from = (IdentifiableEntity<?>)fromMethod.invoke(rel);
|
408
|
to = (IdentifiableEntity<?>)toMethod.invoke(rel);
|
409
|
} catch (NoSuchMethodException | SecurityException | IllegalAccessException
|
410
|
| IllegalArgumentException | InvocationTargetException e) {
|
411
|
throw new RuntimeException(e);
|
412
|
}
|
413
|
}
|
414
|
String typeLabel = null;
|
415
|
if (type != null){
|
416
|
Representation typeRepr = type.getPreferredRepresentation(CdmStore.getDefaultLanguage());
|
417
|
if (typeRepr != null){
|
418
|
typeLabel = typeRepr.getAbbreviatedLabel();
|
419
|
}
|
420
|
if (StringUtils.isBlank(typeLabel) && typeRepr != null){
|
421
|
typeLabel = typeRepr.getLabel();
|
422
|
}
|
423
|
if (StringUtils.isBlank(typeLabel) ){
|
424
|
typeLabel = type.getSymbol();
|
425
|
}
|
426
|
if (StringUtils.isBlank(typeLabel)){
|
427
|
typeLabel = type.getTitleCache();
|
428
|
}
|
429
|
}
|
430
|
if (StringUtils.isBlank(typeLabel)){
|
431
|
typeLabel = "->";
|
432
|
}
|
433
|
String result = CdmUtils.concat(" ", new String[]{from == null ? null : from.getTitleCache(),
|
434
|
typeLabel, to == null? null : to.getTitleCache()});
|
435
|
return result;
|
436
|
}
|
437
|
|
438
|
|
439
|
private static String getCache(HomotypicalGroup hg) {
|
440
|
String result = "";
|
441
|
for (TaxonName tnb : hg.getTypifiedNames()){
|
442
|
result = CdmUtils.concat(", ", result, tnb.getTitleCache());
|
443
|
}
|
444
|
if (StringUtils.isBlank(result)){
|
445
|
result = "No typified names";
|
446
|
}
|
447
|
return result;
|
448
|
}
|
449
|
|
450
|
private static String getCache(KeyStatement ks) {
|
451
|
String result = "";
|
452
|
|
453
|
result = "KeyStatement";
|
454
|
|
455
|
return result;
|
456
|
}
|
457
|
|
458
|
/**
|
459
|
* <p>getObjectClassname</p>
|
460
|
*
|
461
|
* @param element a {@link java.lang.Object} object.
|
462
|
* @return a {@link java.lang.String} object.
|
463
|
*/
|
464
|
public static String getObjectClassname(Object element) {
|
465
|
return element.getClass().getSimpleName();
|
466
|
}
|
467
|
|
468
|
/**
|
469
|
* <p>getFeatureNodeContainerText</p>
|
470
|
*
|
471
|
* @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
|
472
|
* @return a {@link java.lang.String} object.
|
473
|
*/
|
474
|
public static String getFeatureNodeContainerText(FeatureNodeContainer element) {
|
475
|
String result = null;
|
476
|
if(element.getFeatureNode() != null && element.getFeatureNode().getFeature() != null){
|
477
|
result = element.getFeatureNode().getFeature().getLabel(CdmStore.getDefaultLanguage());
|
478
|
} else{
|
479
|
return "No label set";
|
480
|
}
|
481
|
if (result == null){
|
482
|
result = element.getFeatureNode().getFeature().getLabel();
|
483
|
}
|
484
|
return result;
|
485
|
}
|
486
|
|
487
|
/**
|
488
|
* <p>getQuantitativeDataText</p>
|
489
|
*
|
490
|
* @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
|
491
|
* @return a {@link java.lang.String} object.
|
492
|
*/
|
493
|
public static String getQuantitativeDataText(QuantitativeData element) {
|
494
|
TextData textData = quantitativeDescriptionBuilder.build(element, getLanguageList());
|
495
|
|
496
|
return textData.getText(CdmStore.getDefaultLanguage());
|
497
|
}
|
498
|
|
499
|
/**
|
500
|
* <p>getCategoricalDataText</p>
|
501
|
*
|
502
|
* @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
|
503
|
* @return a {@link java.lang.String} object.
|
504
|
*/
|
505
|
public static String getCategoricalDataText(CategoricalData element) {
|
506
|
TextData textData = categoricalDescriptionBuilder.build(element, getLanguageList());
|
507
|
|
508
|
return textData.getText(CdmStore.getDefaultLanguage());
|
509
|
}
|
510
|
|
511
|
private static List<Language> getLanguageList(){
|
512
|
return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
|
513
|
}
|
514
|
|
515
|
private static DescriptionBuilder<QuantitativeData> quantitativeDescriptionBuilder = new DefaultQuantitativeDescriptionBuilder();
|
516
|
private static DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder();
|
517
|
|
518
|
|
519
|
/**
|
520
|
* <p>getDistributionText</p>
|
521
|
*
|
522
|
* @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
|
523
|
* @return a {@link java.lang.String} object.
|
524
|
*/
|
525
|
public static String getDistributionText(Distribution element) {
|
526
|
|
527
|
String text = "EMPTY";
|
528
|
|
529
|
Distribution distribution = element;
|
530
|
|
531
|
NamedArea area = distribution.getArea();
|
532
|
if(area != null){
|
533
|
|
534
|
text = NamedArea.labelWithLevel(area, CdmStore.getDefaultLanguage());
|
535
|
|
536
|
PresenceAbsenceTerm status = distribution.getStatus();
|
537
|
|
538
|
if (status != null) {
|
539
|
text += ", " + status.getLabel();
|
540
|
}else{
|
541
|
text += ", NO STATUS";
|
542
|
}
|
543
|
}
|
544
|
return text;
|
545
|
}
|
546
|
|
547
|
/**
|
548
|
* <p>getImageText</p>
|
549
|
*
|
550
|
* @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
|
551
|
* @return a {@link java.lang.String} object.
|
552
|
*/
|
553
|
public static String getImageText(Media media) {
|
554
|
LanguageString title = media.getTitle(CdmStore.getDefaultLanguage());
|
555
|
if (title != null) {
|
556
|
return title.getText();
|
557
|
}
|
558
|
return "No title.";
|
559
|
}
|
560
|
|
561
|
|
562
|
|
563
|
/**
|
564
|
* <p>getElementText</p>
|
565
|
*
|
566
|
* @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
|
567
|
* @return a {@link java.lang.String} object.
|
568
|
*/
|
569
|
public static String getElementText(TextData element) {
|
570
|
String text = null;
|
571
|
if(element.getFeature().equals(Feature.CITATION())){
|
572
|
text = "";
|
573
|
for(DescriptionElementSource source : element.getSources()){
|
574
|
if(source.getCitation() != null){
|
575
|
text += source.getCitation().getTitleCache();
|
576
|
}
|
577
|
if(source.getNameUsedInSource() != null){
|
578
|
text += " [ " + source.getNameUsedInSource().getTitleCache() + " ]";
|
579
|
}
|
580
|
}
|
581
|
if(CdmUtils.isEmpty(text)){
|
582
|
text = "No sources provided";
|
583
|
}
|
584
|
}else{
|
585
|
List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
|
586
|
LanguageString languageString = element.getPreferredLanguageString(languages);
|
587
|
text = languageString != null ? languageString.getText() : null;
|
588
|
}
|
589
|
return CdmUtils.isEmpty(text) ? "No text provided" : text;
|
590
|
}
|
591
|
|
592
|
/**
|
593
|
* <p>getTaxonInteractionText</p>
|
594
|
*
|
595
|
* @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
|
596
|
* @return a {@link java.lang.String} object.
|
597
|
*/
|
598
|
public static String getTaxonInteractionText(TaxonInteraction element) {
|
599
|
String text = "";
|
600
|
Taxon taxon2 = element.getTaxon2();
|
601
|
if(taxon2 != null && taxon2.getName() != null){
|
602
|
text = taxon2.getName().getTitleCache();
|
603
|
}else{
|
604
|
text = "No taxon chosen";
|
605
|
}
|
606
|
|
607
|
return text;
|
608
|
}
|
609
|
|
610
|
/**
|
611
|
* <p>getCommonNameText</p>
|
612
|
*
|
613
|
* @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
|
614
|
* @return a {@link java.lang.String} object.
|
615
|
*/
|
616
|
public static String getCommonNameText(CommonTaxonName commonName) {
|
617
|
String name = commonName.getName();
|
618
|
if (name == null || name.length() == 0) {
|
619
|
name = "No name provided";
|
620
|
}
|
621
|
Language language = commonName.getLanguage();
|
622
|
if (language == null) {
|
623
|
name += " (No language provided)";
|
624
|
} else {
|
625
|
name += " (" + language.getDescription() + ")";
|
626
|
}
|
627
|
return name;
|
628
|
}
|
629
|
|
630
|
/**
|
631
|
* <p>getDescriptionText</p>
|
632
|
*
|
633
|
* @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
|
634
|
* @return a {@link java.lang.String} object.
|
635
|
*/
|
636
|
public static String getDescriptionText(DescriptionBase element) {
|
637
|
String text = element.getTitleCache();
|
638
|
if (text == null || text.length() == 0) {
|
639
|
text = "No label provided";
|
640
|
}
|
641
|
|
642
|
return text;
|
643
|
}
|
644
|
|
645
|
/**
|
646
|
* <p>getIndividualsAssociationText</p>
|
647
|
*
|
648
|
* @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
|
649
|
* @return a {@link java.lang.String} object.
|
650
|
*/
|
651
|
public static String getIndividualsAssociationText(IndividualsAssociation element) {
|
652
|
SpecimenOrObservationBase derivedUnit = element.getAssociatedSpecimenOrObservation();
|
653
|
if(derivedUnit != null){
|
654
|
return derivedUnit.getTitleCache();
|
655
|
}
|
656
|
return "No unit chosen";
|
657
|
}
|
658
|
|
659
|
/**
|
660
|
* <p>getLabel</p>
|
661
|
*
|
662
|
* @param element a {@link java.lang.Object} object.
|
663
|
* @return a {@link java.lang.String} object.
|
664
|
*/
|
665
|
public static String getLabel(Object element){
|
666
|
String noLabelString = "[no label]";
|
667
|
if (element instanceof FeatureNodeContainer){
|
668
|
return getFeatureNodeContainerText((FeatureNodeContainer) element);
|
669
|
}
|
670
|
else if (element instanceof DescriptionBase) {
|
671
|
return getDescriptionText((DescriptionBase) element);
|
672
|
}
|
673
|
else if(element instanceof CategoricalData){
|
674
|
String categoricalDataText = getCategoricalDataText((CategoricalData) element);
|
675
|
if(categoricalDataText==null || categoricalDataText.isEmpty()){
|
676
|
categoricalDataText = noLabelString;
|
677
|
}
|
678
|
return categoricalDataText;
|
679
|
}
|
680
|
else if (element instanceof CommonTaxonName) {
|
681
|
return getCommonNameText((CommonTaxonName) element);
|
682
|
}
|
683
|
else if (element instanceof Distribution) {
|
684
|
return getDistributionText((Distribution) element);
|
685
|
}
|
686
|
else if (element instanceof IndividualsAssociation) {
|
687
|
return getIndividualsAssociationText((IndividualsAssociation) element);
|
688
|
}
|
689
|
else if (element instanceof QuantitativeData) {
|
690
|
String quantitativeDataText = getQuantitativeDataText((QuantitativeData) element);
|
691
|
if(quantitativeDataText==null || quantitativeDataText.isEmpty()){
|
692
|
quantitativeDataText = noLabelString;
|
693
|
}
|
694
|
return quantitativeDataText;
|
695
|
}
|
696
|
else if (element instanceof TaxonInteraction) {
|
697
|
return getTaxonInteractionText((TaxonInteraction) element);
|
698
|
}
|
699
|
else if (element instanceof TextData) {
|
700
|
return getElementText((TextData) element);
|
701
|
}
|
702
|
else{
|
703
|
return element.toString();
|
704
|
}
|
705
|
}
|
706
|
}
|