Project

General

Profile

Download (23.2 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.model;
12

    
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
15
import java.util.Arrays;
16
import java.util.List;
17
import java.util.Set;
18

    
19
import org.apache.commons.lang.StringUtils;
20
import org.hibernate.LazyInitializationException;
21

    
22
import eu.etaxonomy.cdm.api.service.DefaultCategoricalDescriptionBuilder;
23
import eu.etaxonomy.cdm.api.service.DefaultQuantitativeDescriptionBuilder;
24
import eu.etaxonomy.cdm.api.service.DescriptionBuilder;
25
import eu.etaxonomy.cdm.common.CdmUtils;
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.common.Group;
28
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
29
import eu.etaxonomy.cdm.model.common.Language;
30
import eu.etaxonomy.cdm.model.common.LanguageString;
31
import eu.etaxonomy.cdm.model.common.LanguageStringBase;
32
import eu.etaxonomy.cdm.model.common.Marker;
33
import eu.etaxonomy.cdm.model.common.MarkerType;
34
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
35
import eu.etaxonomy.cdm.model.common.RelationshipBase;
36
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
37
import eu.etaxonomy.cdm.model.common.Representation;
38
import eu.etaxonomy.cdm.model.common.User;
39
import eu.etaxonomy.cdm.model.description.CategoricalData;
40
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
41
import eu.etaxonomy.cdm.model.description.DescriptionBase;
42
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
43
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
44
import eu.etaxonomy.cdm.model.description.Distribution;
45
import eu.etaxonomy.cdm.model.description.Feature;
46
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
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.TaxonNameBase;
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.SynonymRelationship;
68
import eu.etaxonomy.cdm.model.taxon.Taxon;
69
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
70
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
71
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
72
import eu.etaxonomy.taxeditor.store.CdmStore;
73

    
74
/**
75
 * <p>DescriptionHelper class.</p>
76
 *
77
 * @author p.ciardelli
78
 * @author n.hoffmann
79
 * @created 02.04.2009
80
 */
81
public class DescriptionHelper {
82

    
83
	/**
84
	 * Returns whatever the element's title cache equivalent is,
85
	 * depending on its class.
86
	 *
87
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
88
	 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
89
	 * @return a {@link java.lang.String} object.
90
	 */
91
	public static String getCache(DescriptionElementBase element,
92
			Language language) {
93
		
94
		String mainElementLabel= null;
95
		DescriptionBase<?> descr = element.getInDescription();
96
		if (descr != null){
97
			if (descr.isInstanceOf(TaxonDescription.class)){
98
				Taxon taxon = CdmBase.deproxy(descr, TaxonDescription.class).getTaxon();
99
				if (taxon != null){
100
					mainElementLabel = taxon.getTitleCache();
101
				}
102
			}else if (descr.isInstanceOf(SpecimenDescription.class)){
103
				SpecimenOrObservationBase<?> specimen = CdmBase.deproxy(descr, SpecimenDescription.class).getDescribedSpecimenOrObservation();
104
				if (specimen != null){
105
					mainElementLabel = specimen.getTitleCache();
106
				}
107
			}else if (descr.isInstanceOf(TaxonNameDescription.class)){
108
				TaxonNameBase<?, ?> name = CdmBase.deproxy(descr, TaxonNameDescription.class).getTaxonName();
109
				if (name != null){
110
					mainElementLabel = name.getTitleCache();
111
				}
112
			}
113
		}
114
		
115
		String cache = null;
116
		if (element instanceof TextData) {
117
			cache = ((TextData) element).getText(language);
118
		}
119
		if (element instanceof CommonTaxonName) {
120
			cache = ((CommonTaxonName) element).getName();
121
		}
122
		if (element instanceof TaxonInteraction) {
123
			Taxon taxon2 = ((TaxonInteraction) element).getTaxon2();
124
			if(taxon2 != null && taxon2.getName() != null){
125
				cache = taxon2.getName().getTitleCache();
126
			}else{
127
				cache = "No taxon chosen";
128
			}
129

    
130
		}
131
		if (element instanceof Distribution) {
132
			Distribution distribution = (Distribution) element;
133

    
134
			NamedArea area = distribution.getArea();
135
			if(area != null){
136
				cache =  area.getLabel();
137

    
138
				PresenceAbsenceTerm status = distribution.getStatus();
139
				if (status == null){
140
					cache += ", no status";
141
				}else {
142
					cache += ", " + status.getLabel();
143
				}
144
			}
145
		}
146
		String result = cache == null ? "" : cache;
147
		if (StringUtils.isNotBlank(mainElementLabel)){
148
			result = CdmUtils.concat(" ", result, "(" + mainElementLabel + ")");
149
		}
150
		return result;
151
	}
152

    
153
	/**
154
	 * Returns whatever the element's title cache equivalent is,
155
	 * depending on its class, using the default language.
156
	 *
157
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
158
	 * @return a {@link java.lang.String} object.
159
	 */
160
	public static String getCache(DescriptionElementBase element) {
161
		return getCache(element, CdmStore.getDefaultLanguage());
162
	}
163

    
164
	/**
165
	 * Set whatever the element's title cache equivalent is,
166
	 * depending on its class.
167
	 *
168
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
169
	 * @param value a {@link java.lang.String} object.
170
	 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
171
	 */
172
	public static void setCache(DescriptionElementBase element,
173
			String value, Language language) {
174
		if (element instanceof TextData) {
175
			((TextData) element).putText(language, value);
176
			return;
177
		}else if (element instanceof CommonTaxonName) {
178
			((CommonTaxonName) element).setName(value);
179
			return;
180
		}else if (element instanceof TaxonInteraction) {
181

    
182
		}else if(element instanceof Distribution){
183
			MessagingUtils.warn(DescriptionHelper.class, "trying to set cache on distribution, don't know what to do at the moment.");
184
			return;
185
		}else{
186
			MessagingUtils.warn(DescriptionHelper.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
187
		}
188
	}
189

    
190
	/**
191
	 * Set whatever the element's title cache equivalent is,
192
	 * depending on its class, using the default language.
193
	 *
194
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
195
	 * @param value a {@link java.lang.String} object.
196
	 */
197
	public static void setCache(DescriptionElementBase element,
198
			String value) {
199
		setCache(element, value, CdmStore.getDefaultLanguage());
200
	}
201

    
202

    
203
	/**
204
	 * <p>getObjectDescription</p>
205
	 *
206
	 * @param element a {@link java.lang.Object} object.
207
	 * @return a {@link java.lang.String} object.
208
	 */
209
	public static String getObjectDescription(Object element) {
210
		if (element instanceof IdentifiableEntity) {
211
			try{
212
				return ((IdentifiableEntity) element).getTitleCache();
213
			}catch(LazyInitializationException e){
214
				String result = "No Session to initialize title cache for IdentifiableEntity";
215
				MessagingUtils.error(DescriptionHelper.class, result, e);
216
				return "TODO: " + result;
217
			}
218
		}else if (element instanceof OriginalSourceBase) {
219
			try{
220
				OriginalSourceBase<?> originalSource = (OriginalSourceBase<?>) element;
221
//				ISourceable sourcedObject = originalSource.getSourcedObj();
222
				//due to #5743 the bidirectionality for sourced object had to be removed 
223
				String sourceObjectTitle = "sourced object data not available (#5743)";
224
//				if(sourcedObject instanceof IIdentifiableEntity){
225
//					sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
226
//				}else if(sourcedObject instanceof DescriptionElementBase){
227
//					sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
228
//				}else{
229
//					throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
230
//				}
231

    
232
				return CdmUtils.concat("; ", new String[]{originalSource.getIdNamespace(), originalSource.getIdInSource(), sourceObjectTitle});
233
			}catch(LazyInitializationException e){
234
				String result = "Error initializing title cache for ISourceable of an OriginalSourceBase";
235
				MessagingUtils.error(DescriptionHelper.class, result, e);
236
				return "TODO: " + result;
237
			}
238
		}else if (element instanceof LanguageStringBase) {
239
			return ((LanguageStringBase) element).getText();
240
		}else if (element instanceof DescriptionElementBase) {
241
			return getCache((DescriptionElementBase) element);
242
		}else if (element instanceof RelationshipBase<?, ?, ?>) {
243
			return getCache((RelationshipBase<?, ?, ?>) element);
244
		}else if (element instanceof TypeDesignationBase<?>) {
245
			return getCache((TypeDesignationBase<?>) element);
246
		}else if (element instanceof HomotypicalGroup) {
247
			return getCache((HomotypicalGroup) element);
248
		}else if (element instanceof TaxonNode) {
249
			return getCache((TaxonNode) element);
250
		}else if (element instanceof DeterminationEvent) {
251
			return getCache((DeterminationEvent) element);
252
		}else if (element instanceof Marker) {
253
			Marker marker = (Marker) element;
254
			MarkerType type = marker.getMarkerType();
255
			return (type == null ? "- no marker type -" : marker.getMarkerType().getLabel()) + " (" + marker.getFlag() + ")";
256
		}else if (element instanceof User) {
257
			User user = (User) element;
258
			return user.getUsername();
259
		}else if (element instanceof Group) {
260
			Group group = (Group) element;
261
			return group.getName();
262
		}else{
263
			// TODO write return texts for HomotypicalGroup, etc.
264
			return element.toString();
265
		}
266
	}
267

    
268

    
269
	private static String getCache(DeterminationEvent detEvent) {
270
		//taxon
271
		String taxonStr = "no taxon";
272
		TaxonNameBase<?,?> taxonName = detEvent.getTaxonName();
273
		TaxonBase<?> taxon = detEvent.getTaxon();
274
		if (taxonName != null){
275
			taxonStr = taxonName.getTitleCache();
276
		}else if (taxon != null){
277
			taxonStr = taxon.getTitleCache();
278
		}
279
		//unit
280
		String unitStr = "no unit";
281
		SpecimenOrObservationBase<?> unit = detEvent.getIdentifiedUnit();
282
		if (unit != null){
283
			unitStr = unit.getTitleCache();
284
		}
285
		
286
		String result = CdmUtils.concat(" determined as ", unitStr, taxonStr);
287

    
288
		return result;
289
	}
290

    
291
	private static String getCache(TaxonNode taxonNode) {
292
		String result = "";
293
		Classification classification = taxonNode.getClassification();
294
		if (classification != null){
295
			String classificationStr = classification.getName() == null ? "" : classification.getName().getText();
296
			result = CdmUtils.concat("" , result, classificationStr);
297
			if (StringUtils.isBlank(result)){
298
				result = classification.toString();
299
			}
300
		}
301
		String parentStr;
302
		TaxonNode parentNode = taxonNode.getParent();
303
		if (parentNode == null){
304
			parentStr = "no parent";
305
		}else{
306
			Taxon parentTaxon = parentNode.getTaxon();
307
			if (parentTaxon == null){
308
				parentStr = "no parent taxon";
309
			}else{
310
				TaxonNameBase<?,?> parentName = parentTaxon.getName();
311
				if (parentName == null){
312
					parentStr = parentTaxon.getTitleCache();
313
				}else{
314
					parentStr = parentName.getTitleCache();
315
				}
316
			}
317
		}
318
		result = CdmUtils.concat(": ", result, parentStr);
319
		
320
		return result;
321
	}
322

    
323
	private static String getCache(TypeDesignationBase<?> designation) {
324
		designation = CdmBase.deproxy(designation);
325
		TypeDesignationStatusBase<?> status = designation.getTypeStatus();
326
		Set<TaxonNameBase> from;
327
		IdentifiableEntity<?> to;
328
		from = designation.getTypifiedNames();
329
		if (designation.isInstanceOf(SpecimenTypeDesignation.class)){
330
			to = ((SpecimenTypeDesignation)designation).getTypeSpecimen();
331
		}else if (designation.isInstanceOf(NameTypeDesignation.class)){
332
			to = ((NameTypeDesignation)designation).getTypeName();	
333
		}else{
334
			throw new RuntimeException("Type Designation class not supported: " +  designation.getClass().getName());
335
		}
336
		String typeLabel = null;
337
		if (status != null){
338
			Representation typeRepr = status.getPreferredRepresentation(CdmStore.getDefaultLanguage());
339
			if (typeRepr != null){
340
				typeLabel = typeRepr.getAbbreviatedLabel();
341
			}
342
			if (StringUtils.isBlank(typeLabel) && typeRepr != null){
343
				typeLabel = typeRepr.getLabel();
344
			}
345
			if (StringUtils.isBlank(typeLabel) ){
346
				typeLabel = status.getSymbol();
347
			}
348
			if (StringUtils.isBlank(typeLabel)){
349
				typeLabel = status.getTitleCache();
350
			}
351
		}
352
		if (StringUtils.isBlank(typeLabel)){
353
			typeLabel = "->";
354
		}
355
		String fromString = "";
356
		for (TaxonNameBase<?,?> name : from){
357
			CdmUtils.concat(",", fromString, name.getTitleCache());
358
		}
359
		String result = CdmUtils.concat(" ", new String[]{from == null ? null : fromString, 
360
				typeLabel, to == null? null : to.getTitleCache()});
361
		return result;
362
	}
363

    
364
	private static String getCache(RelationshipBase<?, ?, ?> rel) {
365
		rel = CdmBase.deproxy(rel);
366
		RelationshipTermBase<?> type = rel.getType();
367
		IdentifiableEntity<?> from;
368
		IdentifiableEntity<?> to;
369
		if (rel.isInstanceOf(SynonymRelationship.class)){
370
			from = ((SynonymRelationship)rel).getSynonym();
371
			to = ((SynonymRelationship)rel).getAcceptedTaxon();
372
		}else if (rel.isInstanceOf(NameRelationship.class)){
373
			from = ((NameRelationship)rel).getFromName();
374
			to = ((NameRelationship)rel).getToName();
375
		}else if (rel.isInstanceOf(HybridRelationship.class)){
376
			from = ((HybridRelationship)rel).getParentName();
377
			to = ((HybridRelationship)rel).getHybridName();
378
		}else if (rel.isInstanceOf(TaxonRelationship.class)){
379
			from = ((TaxonRelationship)rel).getFromTaxon();
380
			to = ((TaxonRelationship)rel).getToTaxon();
381
		}else{
382
			try {
383
				Method fromMethod = rel.getClass().getMethod("getRelatedFrom");
384
				Method toMethod = rel.getClass().getMethod("getRelatedFrom");
385
				fromMethod.setAccessible(true);
386
				toMethod.setAccessible(true);
387
				from = (IdentifiableEntity<?>)fromMethod.invoke(rel);
388
				to = (IdentifiableEntity<?>)toMethod.invoke(rel);
389
			} catch (NoSuchMethodException | SecurityException | IllegalAccessException
390
				| IllegalArgumentException | InvocationTargetException e) {
391
				throw new RuntimeException(e);
392
			}
393
		}
394
		String typeLabel = null;
395
		if (type != null){
396
			Representation typeRepr = type.getPreferredRepresentation(CdmStore.getDefaultLanguage());
397
			if (typeRepr != null){
398
				typeLabel = typeRepr.getAbbreviatedLabel();
399
			}
400
			if (StringUtils.isBlank(typeLabel) && typeRepr != null){
401
				typeLabel = typeRepr.getLabel();
402
			}
403
			if (StringUtils.isBlank(typeLabel) ){
404
				typeLabel = type.getSymbol();
405
			}
406
			if (StringUtils.isBlank(typeLabel)){
407
				typeLabel = type.getTitleCache();
408
			}
409
		}
410
		if (StringUtils.isBlank(typeLabel)){
411
			typeLabel = "->";
412
		}
413
		String result = CdmUtils.concat(" ", new String[]{from == null ? null : from.getTitleCache(), 
414
				typeLabel, to == null? null : to.getTitleCache()});
415
		return result;
416
	}
417
	
418

    
419
	private static String getCache(HomotypicalGroup hg) {
420
		String result = "";
421
		for (TaxonNameBase<?,?> tnb : hg.getTypifiedNames()){
422
			result = CdmUtils.concat(", ", result, tnb.getTitleCache());
423
		}
424
		if (StringUtils.isBlank(result)){
425
			result = "No typified names";
426
		}
427
		return result;
428
	}
429

    
430
	/**
431
	 * <p>getObjectClassname</p>
432
	 *
433
	 * @param element a {@link java.lang.Object} object.
434
	 * @return a {@link java.lang.String} object.
435
	 */
436
	public static String getObjectClassname(Object element) {
437
		return element.getClass().getSimpleName();
438
	}
439

    
440
	/**
441
	 * <p>getFeatureNodeContainerText</p>
442
	 *
443
	 * @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
444
	 * @return a {@link java.lang.String} object.
445
	 */
446
	public static String getFeatureNodeContainerText(FeatureNodeContainer element) {
447
		String result = null;
448
		if(element.getFeatureNode() != null && element.getFeatureNode().getFeature() != null){
449
			result = element.getFeatureNode().getFeature().getLabel(CdmStore.getDefaultLanguage());
450
		} else{
451
			return "No label set";
452
		}
453
		if (result == null){
454
			result = element.getFeatureNode().getFeature().getLabel();
455
		}
456
		return result;
457
	}
458

    
459
	/**
460
	 * <p>getQuantitativeDataText</p>
461
	 *
462
	 * @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
463
	 * @return a {@link java.lang.String} object.
464
	 */
465
	public static String getQuantitativeDataText(QuantitativeData element) {
466
		TextData textData = quantitativeDescriptionBuilder.build(element, getLanguageList());
467

    
468
		return textData.getText(CdmStore.getDefaultLanguage());
469
	}
470

    
471
	/**
472
	 * <p>getCategoricalDataText</p>
473
	 *
474
	 * @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
475
	 * @return a {@link java.lang.String} object.
476
	 */
477
	public static String getCategoricalDataText(CategoricalData element) {
478
		TextData textData = categoricalDescriptionBuilder.build(element, getLanguageList());
479

    
480
		return textData.getText(CdmStore.getDefaultLanguage());
481
	}
482

    
483
	private static List<Language> getLanguageList(){
484
		return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
485
	}
486

    
487
	private static DescriptionBuilder<QuantitativeData> quantitativeDescriptionBuilder = new DefaultQuantitativeDescriptionBuilder();
488
	private static DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder();
489

    
490

    
491
	/**
492
	 * <p>getDistributionText</p>
493
	 *
494
	 * @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
495
	 * @return a {@link java.lang.String} object.
496
	 */
497
	public static String getDistributionText(Distribution element) {
498

    
499
		String text = "EMPTY";
500

    
501
		Distribution distribution = element;
502

    
503
		NamedArea area = distribution.getArea();
504
		if(area != null){
505

    
506
			text = NamedArea.labelWithLevel(area, CdmStore.getDefaultLanguage());
507

    
508
			PresenceAbsenceTerm status = distribution.getStatus();
509

    
510
			if (status != null) {
511
				text += ", " + status.getLabel();
512
			}else{
513
				text += ", NO STATUS";
514
			}
515
		}
516
		return text;
517
	}
518

    
519
	/**
520
	 * <p>getImageText</p>
521
	 *
522
	 * @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
523
	 * @return a {@link java.lang.String} object.
524
	 */
525
	public static  String getImageText(Media media) {
526
		 LanguageString title = media.getTitle(CdmStore.getDefaultLanguage());
527
		if (title != null) {
528
			return title.getText();
529
		}
530
		return "No title.";
531
	}
532

    
533

    
534

    
535
	/**
536
	 * <p>getElementText</p>
537
	 *
538
	 * @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
539
	 * @return a {@link java.lang.String} object.
540
	 */
541
	public static  String getElementText(TextData element) {
542
		String text = null;
543
		if(element.getFeature().equals(Feature.CITATION())){
544
			text = "";
545
			for(DescriptionElementSource source : element.getSources()){
546
				if(source.getCitation() != null){
547
					text += source.getCitation().getTitleCache();
548
				}
549
				if(source.getNameUsedInSource() != null){
550
					text += " [ " + source.getNameUsedInSource().getTitleCache() + " ]";
551
				}
552
			}
553
			if(CdmUtils.isEmpty(text)){
554
				text = "No sources provided";
555
			}
556
		}else{
557
			List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
558
			LanguageString languageString = element.getPreferredLanguageString(languages);
559
			text = languageString != null ? languageString.getText() : null;
560
		}
561
		return CdmUtils.isEmpty(text) ? "No text provided" : text;
562
	}
563

    
564
	/**
565
	 * <p>getTaxonInteractionText</p>
566
	 *
567
	 * @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
568
	 * @return a {@link java.lang.String} object.
569
	 */
570
	public static  String getTaxonInteractionText(TaxonInteraction element) {
571
		String text = "";
572
		Taxon taxon2 = element.getTaxon2();
573
		if(taxon2 != null && taxon2.getName() != null){
574
			text = taxon2.getName().getTitleCache();
575
		}else{
576
			text = "No taxon chosen";
577
		}
578

    
579
		return text;
580
	}
581

    
582
	/**
583
	 * <p>getCommonNameText</p>
584
	 *
585
	 * @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
586
	 * @return a {@link java.lang.String} object.
587
	 */
588
	public static  String getCommonNameText(CommonTaxonName commonName) {
589
		String name = commonName.getName();
590
		if (name == null || name.length() == 0) {
591
			name = "No name provided";
592
		}
593
		Language language = commonName.getLanguage();
594
		if (language == null) {
595
			name += " (No language provided)";
596
		} else {
597
			name += " (" + language.getDescription() + ")";
598
		}
599
		return name;
600
	}
601

    
602
	/**
603
	 * <p>getDescriptionText</p>
604
	 *
605
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
606
	 * @return a {@link java.lang.String} object.
607
	 */
608
	public static  String getDescriptionText(DescriptionBase element) {
609
		String text = element.getTitleCache();
610
		if (text == null || text.length() == 0) {
611
			text = "No label provided";
612
		}
613

    
614
		return text;
615
	}
616

    
617
	/**
618
	 * <p>getIndividualsAssociationText</p>
619
	 *
620
	 * @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
621
	 * @return a {@link java.lang.String} object.
622
	 */
623
	public static  String getIndividualsAssociationText(IndividualsAssociation element) {
624
		SpecimenOrObservationBase derivedUnit = element.getAssociatedSpecimenOrObservation();
625
		if(derivedUnit != null){
626
			return derivedUnit.getTitleCache();
627
		}
628
		return "No unit chosen";
629
	}
630

    
631
	/**
632
	 * <p>getLabel</p>
633
	 *
634
	 * @param element a {@link java.lang.Object} object.
635
	 * @return a {@link java.lang.String} object.
636
	 */
637
	public static String getLabel(Object element){
638
	    String noLabelString = "[no label]";
639
		if (element instanceof FeatureNodeContainer){
640
			return getFeatureNodeContainerText((FeatureNodeContainer) element);
641
		}
642
		else if (element instanceof DescriptionBase) {
643
			return getDescriptionText((DescriptionBase) element);
644
		}
645
		else if(element instanceof CategoricalData){
646
			String categoricalDataText = getCategoricalDataText((CategoricalData) element);
647
			if(categoricalDataText==null || categoricalDataText.isEmpty()){
648
			    categoricalDataText = noLabelString;
649
			}
650
            return categoricalDataText;
651
		}
652
		else if (element instanceof CommonTaxonName) {
653
			return getCommonNameText((CommonTaxonName) element);
654
		}
655
		else if (element instanceof Distribution) {
656
			return getDistributionText((Distribution) element);
657
		}
658
		else if (element instanceof IndividualsAssociation) {
659
			return getIndividualsAssociationText((IndividualsAssociation) element);
660
		}
661
		else if (element instanceof QuantitativeData) {
662
			String quantitativeDataText = getQuantitativeDataText((QuantitativeData) element);
663
			if(quantitativeDataText==null || quantitativeDataText.isEmpty()){
664
                quantitativeDataText = noLabelString;
665
			}
666
            return quantitativeDataText;
667
		}
668
		else if (element instanceof TaxonInteraction) {
669
			return getTaxonInteractionText((TaxonInteraction) element);
670
		}
671
		else if (element instanceof TextData) {
672
			return getElementText((TextData) element);
673
		}
674
		else{
675
			return element.toString();
676
		}
677
	}
678
}
(12-12/38)