2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.model
;
12 import java
.lang
.reflect
.InvocationTargetException
;
13 import java
.lang
.reflect
.Method
;
14 import java
.util
.Arrays
;
15 import java
.util
.List
;
18 import org
.apache
.commons
.lang
.StringUtils
;
19 import org
.hibernate
.LazyInitializationException
;
21 import eu
.etaxonomy
.cdm
.api
.service
.DefaultCategoricalDescriptionBuilder
;
22 import eu
.etaxonomy
.cdm
.api
.service
.DefaultQuantitativeDescriptionBuilder
;
23 import eu
.etaxonomy
.cdm
.api
.service
.DescriptionBuilder
;
24 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
27 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
29 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
30 import eu
.etaxonomy
.cdm
.model
.common
.LanguageStringBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
32 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
33 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceBase
;
34 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
35 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
37 import eu
.etaxonomy
.cdm
.model
.common
.User
;
38 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
39 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
40 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
41 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
42 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
43 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
44 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
45 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
46 import eu
.etaxonomy
.cdm
.model
.description
.KeyStatement
;
47 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
48 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
49 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
50 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
51 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
52 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
53 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
54 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
55 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
56 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
57 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
58 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
59 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
60 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
61 import eu
.etaxonomy
.cdm
.model
.name
.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
;
74 * <p>DescriptionHelper class.</p>
80 public class DescriptionHelper
{
83 * Returns whatever the element's title cache equivalent is,
84 * depending on its class.
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.
90 public static String
getCache(DescriptionElementBase element
,
93 String mainElementLabel
= null;
94 DescriptionBase
<?
> descr
= element
.getInDescription();
95 descr
= CdmBase
.deproxy(descr
, DescriptionBase
.class);
98 if (descr
.isInstanceOf(TaxonDescription
.class)){
99 Taxon taxon
= CdmBase
.deproxy(descr
, TaxonDescription
.class).getTaxon();
101 mainElementLabel
= taxon
.getTitleCache();
103 }else if (descr
.isInstanceOf(SpecimenDescription
.class)){
104 SpecimenOrObservationBase
<?
> specimen
= CdmBase
.deproxy(descr
, SpecimenDescription
.class).getDescribedSpecimenOrObservation();
105 if (specimen
!= null){
106 mainElementLabel
= specimen
.getTitleCache();
108 }else if (descr
.isInstanceOf(TaxonNameDescription
.class)){
109 TaxonNameBase
<?
, ?
> name
= CdmBase
.deproxy(descr
, TaxonNameDescription
.class).getTaxonName();
111 mainElementLabel
= name
.getTitleCache();
118 if (element
instanceof TextData
) {
119 //cache = ((TextData) element).getText(language);
122 if (element
instanceof CommonTaxonName
) {
123 cache
= ((CommonTaxonName
) element
).getName();
125 if (element
instanceof TaxonInteraction
) {
126 Taxon taxon2
= ((TaxonInteraction
) element
).getTaxon2();
127 if(taxon2
!= null && taxon2
.getName() != null){
128 cache
= taxon2
.getName().getTitleCache();
130 cache
= "No taxon chosen";
134 if (element
instanceof Distribution
) {
135 Distribution distribution
= (Distribution
) element
;
137 NamedArea area
= distribution
.getArea();
139 cache
= area
.getLabel();
141 PresenceAbsenceTerm status
= distribution
.getStatus();
143 cache
+= ", no status";
145 cache
+= ", " + status
.getLabel();
149 String result
= cache
== null ?
"" : cache
;
150 if (StringUtils
.isNotBlank(mainElementLabel
)){
151 result
= CdmUtils
.concat(" ", result
, "(" + mainElementLabel
+ ")");
157 * Returns whatever the element's title cache equivalent is,
158 * depending on its class, using the default language.
160 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
161 * @return a {@link java.lang.String} object.
163 public static String
getCache(DescriptionElementBase element
) {
164 return getCache(element
, CdmStore
.getDefaultLanguage());
168 * Set whatever the element's title cache equivalent is,
169 * depending on its class.
171 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
172 * @param value a {@link java.lang.String} object.
173 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
175 public static void setCache(DescriptionElementBase element
,
176 String value
, Language language
) {
177 if (element
instanceof TextData
) {
178 ((TextData
) element
).putText(language
, value
);
180 }else if (element
instanceof CommonTaxonName
) {
181 ((CommonTaxonName
) element
).setName(value
);
183 }else if (element
instanceof TaxonInteraction
) {
185 }else if(element
instanceof Distribution
){
186 MessagingUtils
.warn(DescriptionHelper
.class, "trying to set cache on distribution, don't know what to do at the moment.");
189 MessagingUtils
.warn(DescriptionHelper
.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
194 * Set whatever the element's title cache equivalent is,
195 * depending on its class, using the default language.
197 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
198 * @param value a {@link java.lang.String} object.
200 public static void setCache(DescriptionElementBase element
,
202 setCache(element
, value
, CdmStore
.getDefaultLanguage());
207 * <p>getObjectDescription</p>
209 * @param element a {@link java.lang.Object} object.
210 * @return a {@link java.lang.String} object.
212 public static String
getObjectDescription(Object element
) {
213 String resultString
= null;
214 if (element
instanceof IdentifiableEntity
) {
216 resultString
= ((IdentifiableEntity
) element
).getTitleCache();
217 }catch(LazyInitializationException e
){
218 String result
= "No Session to initialize title cache for IdentifiableEntity";
219 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
220 resultString
= "TODO: " + result
;
222 }else if (element
instanceof OriginalSourceBase
) {
224 OriginalSourceBase
<?
> originalSource
= (OriginalSourceBase
<?
>) element
;
225 // ISourceable sourcedObject = originalSource.getSourcedObj();
226 //due to #5743 the bidirectionality for sourced object had to be removed
227 String sourceObjectTitle
= "sourced object data not available (#5743)";
228 // if(sourcedObject instanceof IIdentifiableEntity){
229 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
230 // }else if(sourcedObject instanceof DescriptionElementBase){
231 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
233 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
236 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
237 }catch(LazyInitializationException e
){
238 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
239 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
240 resultString
= "TODO: " + result
;
242 }else if (element
instanceof LanguageStringBase
) {
243 resultString
= ((LanguageStringBase
) element
).getText();
244 }else if (element
instanceof DescriptionElementBase
) {
245 resultString
= getCache((DescriptionElementBase
) element
);
246 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
247 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
248 }else if (element
instanceof TypeDesignationBase
<?
>) {
249 resultString
= getCache((TypeDesignationBase
<?
>) element
);
250 }else if (element
instanceof HomotypicalGroup
) {
251 resultString
= getCache((HomotypicalGroup
) element
);
252 }else if (element
instanceof TaxonNode
) {
253 resultString
= getCache((TaxonNode
) element
);
254 }else if (element
instanceof DeterminationEvent
) {
255 resultString
= getCache((DeterminationEvent
) element
);
256 }else if (element
instanceof Marker
) {
257 Marker marker
= (Marker
) element
;
258 MarkerType type
= marker
.getMarkerType();
259 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
260 }else if (element
instanceof User
) {
261 User user
= (User
) element
;
262 resultString
= user
.getUsername();
263 }else if (element
instanceof Group
) {
264 Group group
= (Group
) element
;
265 resultString
= group
.getName();
266 }else if (element
instanceof KeyStatement
) {
267 KeyStatement keyStatement
= (KeyStatement
) element
;
268 resultString
= getCache(keyStatement
);
270 // TODO write return texts for HomotypicalGroup, etc.
271 resultString
= element
.toString();
274 if (resultString
== null){
275 resultString
= element
.toString();
281 private static String
getCache(DeterminationEvent detEvent
) {
283 String taxonStr
= null;
284 TaxonNameBase
<?
,?
> taxonName
= detEvent
.getTaxonName();
285 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
286 if (taxonName
!= null){
287 taxonStr
= taxonName
.getTitleCache();
289 if (StringUtils
.isBlank(taxonStr
) && taxon
!= null){
290 taxonStr
= taxon
.getTitleCache();
292 if (StringUtils
.isBlank(taxonStr
)){
293 taxonStr
= "no or unlabled taxon";
298 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
301 unitStr
= unit
.getTitleCache();
302 if (StringUtils
.isBlank(unitStr
)){
303 unitStr
= "Unlabled unit";
309 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
314 private static String
getCache(TaxonNode taxonNode
) {
316 Classification classification
= taxonNode
.getClassification();
317 if (classification
!= null){
318 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
319 result
= CdmUtils
.concat("" , result
, classificationStr
);
320 if (StringUtils
.isBlank(result
)){
321 result
= classification
.toString();
325 TaxonNode parentNode
= taxonNode
.getParent();
326 if (parentNode
== null){
327 parentStr
= "no parent";
329 Taxon parentTaxon
= parentNode
.getTaxon();
330 if (parentTaxon
== null){
331 parentStr
= "no parent taxon";
333 TaxonNameBase
<?
,?
> parentName
= parentTaxon
.getName();
334 if (parentName
== null){
335 parentStr
= "child of " + parentTaxon
.getTitleCache();
337 parentStr
= "child of " + parentName
.getTitleCache();
341 result
= CdmUtils
.concat(": ", result
, parentStr
);
346 private static String
getCache(TypeDesignationBase
<?
> designation
) {
347 designation
= CdmBase
.deproxy(designation
);
348 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
349 Set
<TaxonNameBase
> from
;
350 IdentifiableEntity
<?
> to
;
351 from
= designation
.getTypifiedNames();
352 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
353 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
354 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
355 to
= ((NameTypeDesignation
)designation
).getTypeName();
357 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
359 String typeLabel
= null;
361 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
362 if (typeRepr
!= null){
363 typeLabel
= typeRepr
.getAbbreviatedLabel();
365 if (StringUtils
.isBlank(typeLabel
) && typeRepr
!= null){
366 typeLabel
= typeRepr
.getLabel();
368 if (StringUtils
.isBlank(typeLabel
) ){
369 typeLabel
= status
.getSymbol();
371 if (StringUtils
.isBlank(typeLabel
)){
372 typeLabel
= status
.getTitleCache();
375 if (StringUtils
.isBlank(typeLabel
)){
378 String fromString
= "";
379 for (TaxonNameBase
<?
,?
> name
: from
){
380 CdmUtils
.concat(",", fromString
, name
.getTitleCache());
382 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : fromString
,
383 typeLabel
, to
== null?
null : to
.getTitleCache()});
387 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
388 rel
= CdmBase
.deproxy(rel
);
389 RelationshipTermBase
<?
> type
= rel
.getType();
390 IdentifiableEntity
<?
> from
;
391 IdentifiableEntity
<?
> to
;
392 if (rel
.isInstanceOf(NameRelationship
.class)){
393 from
= ((NameRelationship
)rel
).getFromName();
394 to
= ((NameRelationship
)rel
).getToName();
395 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
396 from
= ((HybridRelationship
)rel
).getParentName();
397 to
= ((HybridRelationship
)rel
).getHybridName();
398 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
399 from
= ((TaxonRelationship
)rel
).getFromTaxon();
400 to
= ((TaxonRelationship
)rel
).getToTaxon();
403 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
404 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
405 fromMethod
.setAccessible(true);
406 toMethod
.setAccessible(true);
407 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
408 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
409 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
410 | IllegalArgumentException
| InvocationTargetException e
) {
411 throw new RuntimeException(e
);
414 String typeLabel
= null;
416 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
417 if (typeRepr
!= null){
418 typeLabel
= typeRepr
.getAbbreviatedLabel();
420 if (StringUtils
.isBlank(typeLabel
) && typeRepr
!= null){
421 typeLabel
= typeRepr
.getLabel();
423 if (StringUtils
.isBlank(typeLabel
) ){
424 typeLabel
= type
.getSymbol();
426 if (StringUtils
.isBlank(typeLabel
)){
427 typeLabel
= type
.getTitleCache();
430 if (StringUtils
.isBlank(typeLabel
)){
433 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
434 typeLabel
, to
== null?
null : to
.getTitleCache()});
439 private static String
getCache(HomotypicalGroup hg
) {
441 for (TaxonNameBase
<?
,?
> tnb
: hg
.getTypifiedNames()){
442 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
444 if (StringUtils
.isBlank(result
)){
445 result
= "No typified names";
450 private static String
getCache(KeyStatement ks
) {
453 result
= "KeyStatement";
459 * <p>getObjectClassname</p>
461 * @param element a {@link java.lang.Object} object.
462 * @return a {@link java.lang.String} object.
464 public static String
getObjectClassname(Object element
) {
465 return element
.getClass().getSimpleName();
469 * <p>getFeatureNodeContainerText</p>
471 * @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
472 * @return a {@link java.lang.String} object.
474 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
475 String result
= null;
476 if(element
.getFeatureNode() != null && element
.getFeatureNode().getFeature() != null){
477 result
= element
.getFeatureNode().getFeature().getLabel(CdmStore
.getDefaultLanguage());
479 return "No label set";
482 result
= element
.getFeatureNode().getFeature().getLabel();
488 * <p>getQuantitativeDataText</p>
490 * @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
491 * @return a {@link java.lang.String} object.
493 public static String
getQuantitativeDataText(QuantitativeData element
) {
494 TextData textData
= quantitativeDescriptionBuilder
.build(element
, getLanguageList());
496 return textData
.getText(CdmStore
.getDefaultLanguage());
500 * <p>getCategoricalDataText</p>
502 * @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
503 * @return a {@link java.lang.String} object.
505 public static String
getCategoricalDataText(CategoricalData element
) {
506 TextData textData
= categoricalDescriptionBuilder
.build(element
, getLanguageList());
508 return textData
.getText(CdmStore
.getDefaultLanguage());
511 private static List
<Language
> getLanguageList(){
512 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
515 private static DescriptionBuilder
<QuantitativeData
> quantitativeDescriptionBuilder
= new DefaultQuantitativeDescriptionBuilder();
516 private static DescriptionBuilder
<CategoricalData
> categoricalDescriptionBuilder
= new DefaultCategoricalDescriptionBuilder();
520 * <p>getDistributionText</p>
522 * @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
523 * @return a {@link java.lang.String} object.
525 public static String
getDistributionText(Distribution element
) {
527 String text
= "EMPTY";
529 Distribution distribution
= element
;
531 NamedArea area
= distribution
.getArea();
534 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
536 PresenceAbsenceTerm status
= distribution
.getStatus();
538 if (status
!= null) {
539 text
+= ", " + status
.getLabel();
541 text
+= ", NO STATUS";
548 * <p>getImageText</p>
550 * @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
551 * @return a {@link java.lang.String} object.
553 public static String
getImageText(Media media
) {
554 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
556 return title
.getText();
564 * <p>getElementText</p>
566 * @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
567 * @return a {@link java.lang.String} object.
569 public static String
getElementText(TextData element
) {
571 if(element
.getFeature().equals(Feature
.CITATION())){
573 for(DescriptionElementSource source
: element
.getSources()){
574 if(source
.getCitation() != null){
575 text
+= source
.getCitation().getTitleCache();
577 if(source
.getNameUsedInSource() != null){
578 text
+= " [ " + source
.getNameUsedInSource().getTitleCache() + " ]";
581 if(CdmUtils
.isEmpty(text
)){
582 text
= "No sources provided";
585 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
586 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
587 text
= languageString
!= null ? languageString
.getText() : null;
589 return CdmUtils
.isEmpty(text
) ?
"No text provided" : text
;
593 * <p>getTaxonInteractionText</p>
595 * @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
596 * @return a {@link java.lang.String} object.
598 public static String
getTaxonInteractionText(TaxonInteraction element
) {
600 Taxon taxon2
= element
.getTaxon2();
601 if(taxon2
!= null && taxon2
.getName() != null){
602 text
= taxon2
.getName().getTitleCache();
604 text
= "No taxon chosen";
611 * <p>getCommonNameText</p>
613 * @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
614 * @return a {@link java.lang.String} object.
616 public static String
getCommonNameText(CommonTaxonName commonName
) {
617 String name
= commonName
.getName();
618 if (name
== null || name
.length() == 0) {
619 name
= "No name provided";
621 Language language
= commonName
.getLanguage();
622 if (language
== null) {
623 name
+= " (No language provided)";
625 name
+= " (" + language
.getDescription() + ")";
631 * <p>getDescriptionText</p>
633 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
634 * @return a {@link java.lang.String} object.
636 public static String
getDescriptionText(DescriptionBase element
) {
637 String text
= element
.getTitleCache();
638 if (text
== null || text
.length() == 0) {
639 text
= "No label provided";
646 * <p>getIndividualsAssociationText</p>
648 * @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
649 * @return a {@link java.lang.String} object.
651 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
652 SpecimenOrObservationBase derivedUnit
= element
.getAssociatedSpecimenOrObservation();
653 if(derivedUnit
!= null){
654 return derivedUnit
.getTitleCache();
656 return "No unit chosen";
662 * @param element a {@link java.lang.Object} object.
663 * @return a {@link java.lang.String} object.
665 public static String
getLabel(Object element
){
666 String noLabelString
= "[no label]";
667 if (element
instanceof FeatureNodeContainer
){
668 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
670 else if (element
instanceof DescriptionBase
) {
671 return getDescriptionText((DescriptionBase
) element
);
673 else if(element
instanceof CategoricalData
){
674 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
675 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
676 categoricalDataText
= noLabelString
;
678 return categoricalDataText
;
680 else if (element
instanceof CommonTaxonName
) {
681 return getCommonNameText((CommonTaxonName
) element
);
683 else if (element
instanceof Distribution
) {
684 return getDistributionText((Distribution
) element
);
686 else if (element
instanceof IndividualsAssociation
) {
687 return getIndividualsAssociationText((IndividualsAssociation
) element
);
689 else if (element
instanceof QuantitativeData
) {
690 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
691 if(quantitativeDataText
==null || quantitativeDataText
.isEmpty()){
692 quantitativeDataText
= noLabelString
;
694 return quantitativeDataText
;
696 else if (element
instanceof TaxonInteraction
) {
697 return getTaxonInteractionText((TaxonInteraction
) element
);
699 else if (element
instanceof TextData
) {
700 return getElementText((TextData
) element
);
703 return element
.toString();