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