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