Project

General

Profile

Download (23.4 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 = null;
272
		TaxonNameBase<?,?> taxonName = detEvent.getTaxonName();
273
		TaxonBase<?> taxon = detEvent.getTaxon();
274
		if (taxonName != null){
275
			taxonStr = taxonName.getTitleCache();
276
		}
277
		if (StringUtils.isBlank(taxonStr) && taxon != null){
278
			taxonStr = taxon.getTitleCache();
279
		}
280
		if (StringUtils.isBlank(taxonStr)){
281
			taxonStr = "no or unlabled taxon";
282
		}
283
			
284
			
285
		//unit
286
		SpecimenOrObservationBase<?> unit = detEvent.getIdentifiedUnit();
287
		String unitStr;
288
		if (unit != null){
289
			unitStr = unit.getTitleCache();
290
			if (StringUtils.isNotBlank(unitStr)){
291
				unitStr = "Unlabled unit";
292
			}
293
		}else{
294
			unitStr = "no unit";
295
		}
296
		
297
		String result = CdmUtils.concat(" determined as ", unitStr, taxonStr);
298

    
299
		return result;
300
	}
301

    
302
	private static String getCache(TaxonNode taxonNode) {
303
		String result = "";
304
		Classification classification = taxonNode.getClassification();
305
		if (classification != null){
306
			String classificationStr = classification.getName() == null ? "" : classification.getName().getText();
307
			result = CdmUtils.concat("" , result, classificationStr);
308
			if (StringUtils.isBlank(result)){
309
				result = classification.toString();
310
			}
311
		}
312
		String parentStr;
313
		TaxonNode parentNode = taxonNode.getParent();
314
		if (parentNode == null){
315
			parentStr = "no parent";
316
		}else{
317
			Taxon parentTaxon = parentNode.getTaxon();
318
			if (parentTaxon == null){
319
				parentStr = "no parent taxon";
320
			}else{
321
				TaxonNameBase<?,?> parentName = parentTaxon.getName();
322
				if (parentName == null){
323
					parentStr = parentTaxon.getTitleCache();
324
				}else{
325
					parentStr = parentName.getTitleCache();
326
				}
327
			}
328
		}
329
		result = CdmUtils.concat(": ", result, parentStr);
330
		
331
		return result;
332
	}
333

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

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

    
430
	private static String getCache(HomotypicalGroup hg) {
431
		String result = "";
432
		for (TaxonNameBase<?,?> tnb : hg.getTypifiedNames()){
433
			result = CdmUtils.concat(", ", result, tnb.getTitleCache());
434
		}
435
		if (StringUtils.isBlank(result)){
436
			result = "No typified names";
437
		}
438
		return result;
439
	}
440

    
441
	/**
442
	 * <p>getObjectClassname</p>
443
	 *
444
	 * @param element a {@link java.lang.Object} object.
445
	 * @return a {@link java.lang.String} object.
446
	 */
447
	public static String getObjectClassname(Object element) {
448
		return element.getClass().getSimpleName();
449
	}
450

    
451
	/**
452
	 * <p>getFeatureNodeContainerText</p>
453
	 *
454
	 * @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
455
	 * @return a {@link java.lang.String} object.
456
	 */
457
	public static String getFeatureNodeContainerText(FeatureNodeContainer element) {
458
		String result = null;
459
		if(element.getFeatureNode() != null && element.getFeatureNode().getFeature() != null){
460
			result = element.getFeatureNode().getFeature().getLabel(CdmStore.getDefaultLanguage());
461
		} else{
462
			return "No label set";
463
		}
464
		if (result == null){
465
			result = element.getFeatureNode().getFeature().getLabel();
466
		}
467
		return result;
468
	}
469

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

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

    
482
	/**
483
	 * <p>getCategoricalDataText</p>
484
	 *
485
	 * @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
486
	 * @return a {@link java.lang.String} object.
487
	 */
488
	public static String getCategoricalDataText(CategoricalData element) {
489
		TextData textData = categoricalDescriptionBuilder.build(element, getLanguageList());
490

    
491
		return textData.getText(CdmStore.getDefaultLanguage());
492
	}
493

    
494
	private static List<Language> getLanguageList(){
495
		return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
496
	}
497

    
498
	private static DescriptionBuilder<QuantitativeData> quantitativeDescriptionBuilder = new DefaultQuantitativeDescriptionBuilder();
499
	private static DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder();
500

    
501

    
502
	/**
503
	 * <p>getDistributionText</p>
504
	 *
505
	 * @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
506
	 * @return a {@link java.lang.String} object.
507
	 */
508
	public static String getDistributionText(Distribution element) {
509

    
510
		String text = "EMPTY";
511

    
512
		Distribution distribution = element;
513

    
514
		NamedArea area = distribution.getArea();
515
		if(area != null){
516

    
517
			text = NamedArea.labelWithLevel(area, CdmStore.getDefaultLanguage());
518

    
519
			PresenceAbsenceTerm status = distribution.getStatus();
520

    
521
			if (status != null) {
522
				text += ", " + status.getLabel();
523
			}else{
524
				text += ", NO STATUS";
525
			}
526
		}
527
		return text;
528
	}
529

    
530
	/**
531
	 * <p>getImageText</p>
532
	 *
533
	 * @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
534
	 * @return a {@link java.lang.String} object.
535
	 */
536
	public static  String getImageText(Media media) {
537
		 LanguageString title = media.getTitle(CdmStore.getDefaultLanguage());
538
		if (title != null) {
539
			return title.getText();
540
		}
541
		return "No title.";
542
	}
543

    
544

    
545

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

    
575
	/**
576
	 * <p>getTaxonInteractionText</p>
577
	 *
578
	 * @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
579
	 * @return a {@link java.lang.String} object.
580
	 */
581
	public static  String getTaxonInteractionText(TaxonInteraction element) {
582
		String text = "";
583
		Taxon taxon2 = element.getTaxon2();
584
		if(taxon2 != null && taxon2.getName() != null){
585
			text = taxon2.getName().getTitleCache();
586
		}else{
587
			text = "No taxon chosen";
588
		}
589

    
590
		return text;
591
	}
592

    
593
	/**
594
	 * <p>getCommonNameText</p>
595
	 *
596
	 * @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
597
	 * @return a {@link java.lang.String} object.
598
	 */
599
	public static  String getCommonNameText(CommonTaxonName commonName) {
600
		String name = commonName.getName();
601
		if (name == null || name.length() == 0) {
602
			name = "No name provided";
603
		}
604
		Language language = commonName.getLanguage();
605
		if (language == null) {
606
			name += " (No language provided)";
607
		} else {
608
			name += " (" + language.getDescription() + ")";
609
		}
610
		return name;
611
	}
612

    
613
	/**
614
	 * <p>getDescriptionText</p>
615
	 *
616
	 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
617
	 * @return a {@link java.lang.String} object.
618
	 */
619
	public static  String getDescriptionText(DescriptionBase element) {
620
		String text = element.getTitleCache();
621
		if (text == null || text.length() == 0) {
622
			text = "No label provided";
623
		}
624

    
625
		return text;
626
	}
627

    
628
	/**
629
	 * <p>getIndividualsAssociationText</p>
630
	 *
631
	 * @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
632
	 * @return a {@link java.lang.String} object.
633
	 */
634
	public static  String getIndividualsAssociationText(IndividualsAssociation element) {
635
		SpecimenOrObservationBase derivedUnit = element.getAssociatedSpecimenOrObservation();
636
		if(derivedUnit != null){
637
			return derivedUnit.getTitleCache();
638
		}
639
		return "No unit chosen";
640
	}
641

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