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
.lang3
.StringUtils
;
19 import org
.hibernate
.LazyInitializationException
;
21 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
22 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
23 import eu
.etaxonomy
.cdm
.format
.common
.ExtendedTimePeriodFormatter
;
24 import eu
.etaxonomy
.cdm
.format
.description
.CategoricalDataFormatter
;
25 import eu
.etaxonomy
.cdm
.format
.description
.QuantitativeDataFormatter
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.ExtendedTimePeriod
;
29 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
30 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
31 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
32 import eu
.etaxonomy
.cdm
.model
.common
.LanguageStringBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
34 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
35 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
37 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
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
.TemporalData
;
54 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
55 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
56 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
57 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
58 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
59 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
60 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
61 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
62 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
63 import eu
.etaxonomy
.cdm
.model
.name
.TextualTypeDesignation
;
64 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
65 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatusBase
;
66 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
67 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
68 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
69 import eu
.etaxonomy
.cdm
.model
.permission
.Group
;
70 import eu
.etaxonomy
.cdm
.model
.permission
.User
;
71 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceBase
;
72 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
73 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
74 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
75 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
76 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
77 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
78 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
81 * <p>DescriptionHelper class.</p>
86 public class DescriptionHelper
{
88 public static final String NO_LABEL_STRING
= "[no label]";
91 * Returns whatever the element's title cache equivalent is,
92 * depending on its class.
94 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
95 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
96 * @return a {@link java.lang.String} object.
98 public static String
getCache(DescriptionElementBase element
,
101 String mainElementLabel
= null;
102 DescriptionBase
<?
> descr
= element
.getInDescription();
103 descr
= CdmBase
.deproxy(descr
, DescriptionBase
.class);
106 if (descr
.isInstanceOf(TaxonDescription
.class)){
107 Taxon taxon
= CdmBase
.deproxy(descr
, TaxonDescription
.class).getTaxon();
109 mainElementLabel
= taxon
.getTitleCache();
111 }else if (descr
.isInstanceOf(SpecimenDescription
.class)){
112 SpecimenOrObservationBase
<?
> specimen
= CdmBase
.deproxy(descr
, SpecimenDescription
.class).getDescribedSpecimenOrObservation();
113 if (specimen
!= null){
114 mainElementLabel
= specimen
.getTitleCache();
116 }else if (descr
.isInstanceOf(TaxonNameDescription
.class)){
117 TaxonName name
= CdmBase
.deproxy(descr
, TaxonNameDescription
.class).getTaxonName();
119 mainElementLabel
= name
.getTitleCache();
125 if (element
instanceof TextData
) {
126 //cache = ((TextData) element).getText(language);
129 if (element
instanceof CommonTaxonName
) {
130 cache
= ((CommonTaxonName
) element
).getName();
132 if (element
instanceof TaxonInteraction
) {
133 Taxon taxon2
= ((TaxonInteraction
) element
).getTaxon2();
134 if(taxon2
!= null && taxon2
.getName() != null){
135 cache
= taxon2
.getName().getTitleCache();
137 cache
= "No taxon chosen";
140 if (element
instanceof Distribution
) {
141 Distribution distribution
= (Distribution
) element
;
143 NamedArea area
= distribution
.getArea();
145 cache
= area
.getLabel();
147 PresenceAbsenceTerm status
= distribution
.getStatus();
149 cache
+= ", no status";
151 cache
+= ", " + status
.getLabel();
155 String result
= cache
== null ?
"" : cache
;
156 if (isNotBlank(mainElementLabel
)){
157 result
= CdmUtils
.concat(" ", result
, "(" + mainElementLabel
+ ")");
163 * Returns whatever the element's title cache equivalent is,
164 * depending on its class, using the default language.
166 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
167 * @return a {@link java.lang.String} object.
169 public static String
getCache(DescriptionElementBase element
) {
170 return getCache(element
, CdmStore
.getDefaultLanguage());
174 * Set whatever the element's title cache equivalent is,
175 * depending on its class.
177 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
178 * @param value a {@link java.lang.String} object.
179 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
181 public static void setCache(DescriptionElementBase element
,
182 String value
, Language language
) {
183 if (element
instanceof TextData
) {
184 ((TextData
) element
).putText(language
, value
);
186 }else if (element
instanceof CommonTaxonName
) {
187 ((CommonTaxonName
) element
).setName(value
);
189 }else if (element
instanceof TaxonInteraction
) {
191 }else if(element
instanceof Distribution
){
192 MessagingUtils
.warn(DescriptionHelper
.class, "trying to set cache on distribution, don't know what to do at the moment.");
195 MessagingUtils
.warn(DescriptionHelper
.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
200 * Set whatever the element's title cache equivalent is,
201 * depending on its class, using the default language.
203 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
204 * @param value a {@link java.lang.String} object.
206 public static void setCache(DescriptionElementBase element
,
208 setCache(element
, value
, CdmStore
.getDefaultLanguage());
211 public static String
getObjectDescription(Object element
) {
212 String resultString
= null;
213 if (element
instanceof IdentifiableEntity
) {
215 resultString
= ((IdentifiableEntity
) element
).getTitleCache();
216 }catch(LazyInitializationException e
){
217 String result
= "No Session to initialize title cache for IdentifiableEntity";
218 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
219 resultString
= "TODO: " + result
;
221 }else if (element
instanceof OriginalSourceBase
) {
223 OriginalSourceBase
<?
> originalSource
= (OriginalSourceBase
<?
>) element
;
224 // ISourceable sourcedObject = originalSource.getSourcedObj();
225 //due to #5743 the bidirectionality for sourced object had to be removed
226 String sourceObjectTitle
= "sourced object data not available (#5743)";
227 // if(sourcedObject instanceof IIdentifiableEntity){
228 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
229 // }else if(sourcedObject instanceof DescriptionElementBase){
230 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
232 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
235 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
236 }catch(LazyInitializationException e
){
237 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
238 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
239 resultString
= "TODO: " + result
;
241 }else if (element
instanceof LanguageStringBase
) {
242 resultString
= ((LanguageStringBase
) element
).getText();
243 }else if (element
instanceof DescriptionElementBase
) {
244 resultString
= getCache((DescriptionElementBase
) element
);
245 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
246 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
247 }else if (element
instanceof TypeDesignationBase
<?
>) {
248 resultString
= getCache((TypeDesignationBase
<?
>) element
);
249 }else if (element
instanceof HomotypicalGroup
) {
250 resultString
= getCache((HomotypicalGroup
) element
);
251 }else if (element
instanceof TaxonNode
) {
252 resultString
= getCache((TaxonNode
) element
);
253 }else if (element
instanceof DeterminationEvent
) {
254 resultString
= getCache((DeterminationEvent
) element
);
255 }else if (element
instanceof GatheringEvent
){
256 resultString
= getCache((GatheringEvent
) element
);
257 }else if (element
instanceof Marker
) {
258 Marker marker
= (Marker
) element
;
259 MarkerType type
= marker
.getMarkerType();
260 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
261 }else if (element
instanceof User
) {
262 User user
= (User
) element
;
263 resultString
= user
.getUsername();
264 }else if (element
instanceof Group
) {
265 Group group
= (Group
) element
;
266 resultString
= group
.getName();
267 }else if (element
instanceof KeyStatement
) {
268 KeyStatement keyStatement
= (KeyStatement
) element
;
269 resultString
= getCache(keyStatement
);
271 // TODO write return texts for HomotypicalGroup, etc.
272 resultString
= element
.toString();
275 if (resultString
== null){
276 resultString
= element
.toString();
281 private static String
getCache(GatheringEvent gatheringEvent
){
282 String ALTITUDE_PREFIX
= "alt. ";
283 final String METER
= "m";
288 AgentBase
<?
> collector
= CdmBase
.deproxy(gatheringEvent
.getCollector());
289 String collectorStr
= collector
== null?
null : collector
.getTitleCache();
290 result
= CdmUtils
.concat(", ", result
, collectorStr
);
293 TimePeriod gatheringPeriod
= gatheringEvent
.getTimeperiod();
294 result
= CdmUtils
.concat(", ", result
, (gatheringPeriod
== null?
null : gatheringPeriod
.toString()));
297 String strCountry
= null;
298 NamedArea country
= gatheringEvent
.getCountry();
299 Representation repCountry
= country
== null ?
null : country
.getRepresentation(Language
.DEFAULT());
300 strCountry
= repCountry
== null ?
null: repCountry
.getLabel();
301 result
= CdmUtils
.concat(", ", result
, strCountry
);
304 LanguageString locality
= gatheringEvent
.getLocality();
305 if (locality
!= null) {
306 result
= CdmUtils
.concat(", ", result
, locality
.getText());
311 if (isNotBlank(gatheringEvent
.getAbsoluteElevationText())){
312 elevationStr
= gatheringEvent
.getAbsoluteElevationText();
314 String text
= gatheringEvent
.getAbsoluteElevationText();
315 Integer min
= gatheringEvent
.getAbsoluteElevation();
316 Integer max
= gatheringEvent
.getAbsoluteElevationMax();
317 elevationStr
= DerivedUnitFacade
.distanceString(min
, max
, text
, METER
);
319 if (isNotBlank(elevationStr
)){
320 result
= CdmUtils
.concat(", " , result
, ALTITUDE_PREFIX
);
321 result
+= elevationStr
;
325 if (gatheringEvent
.getExactLocation() != null){
326 String exactLocation
= gatheringEvent
.getExactLocation().toSexagesimalString(false, false);
327 result
= CdmUtils
.concat(", ", result
, exactLocation
);
333 private static String
getCache(DeterminationEvent detEvent
) {
335 String taxonStr
= null;
336 TaxonName taxonName
= detEvent
.getTaxonName();
337 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
338 if (taxonName
!= null){
339 taxonStr
= taxonName
.getTitleCache();
341 if (isBlank(taxonStr
) && taxon
!= null){
342 taxonStr
= taxon
.getTitleCache();
344 if (isBlank(taxonStr
)){
345 taxonStr
= "no or unlabled taxon";
349 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
352 unitStr
= unit
.getTitleCache();
353 if (isBlank(unitStr
)){
354 unitStr
= "Unlabled unit";
360 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
365 private static String
getCache(TaxonNode taxonNode
) {
367 Classification classification
= taxonNode
.getClassification();
368 if (classification
!= null){
369 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
370 result
= CdmUtils
.concat("" , result
, classificationStr
);
371 if (isBlank(result
)){
372 result
= classification
.toString();
376 TaxonNode parentNode
= taxonNode
.getParent();
377 if (parentNode
== null){
378 parentStr
= "no parent";
380 Taxon parentTaxon
= parentNode
.getTaxon();
381 if (parentTaxon
== null){
382 parentStr
= "no parent taxon";
384 TaxonName parentName
= parentTaxon
.getName();
385 if (parentName
== null){
386 parentStr
= "child of " + parentTaxon
.getTitleCache();
388 parentStr
= "child of " + parentName
.getTitleCache();
392 result
= CdmUtils
.concat(": ", result
, parentStr
);
397 private static String
getCache(TypeDesignationBase
<?
> designation
) {
398 designation
= CdmBase
.deproxy(designation
);
400 String fromString
= null;
401 Set
<TaxonName
> from
= designation
.getTypifiedNames();
403 for (TaxonName name
: from
){
404 fromString
= CdmUtils
.concat(",", fromString
, name
.getTitleCache());
408 IdentifiableEntity
<?
> to
= null;
410 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
411 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
412 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
413 to
= ((NameTypeDesignation
)designation
).getTypeName();
414 }else if (designation
.isInstanceOf(TextualTypeDesignation
.class)){
415 toStr
= ((TextualTypeDesignation
)designation
).getPreferredText(CdmStore
.getDefaultLanguage());
417 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
419 toStr
= to
== null? toStr
: to
.getTitleCache();
421 String typeLabel
= null;
422 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
424 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
425 if (typeRepr
!= null){
426 typeLabel
= typeRepr
.getAbbreviatedLabel();
428 if (isBlank(typeLabel
) && typeRepr
!= null){
429 typeLabel
= typeRepr
.getLabel();
431 if (isBlank(typeLabel
) ){
432 typeLabel
= status
.getSymbol();
434 if (isBlank(typeLabel
)){
435 typeLabel
= status
.getTitleCache();
438 if (isBlank(typeLabel
)){
442 String result
= CdmUtils
.concat(" ", new String
[]{fromString
, typeLabel
, toStr
});
446 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
447 rel
= CdmBase
.deproxy(rel
);
448 RelationshipTermBase
<?
> type
= rel
.getType();
449 IdentifiableEntity
<?
> from
;
450 IdentifiableEntity
<?
> to
;
451 if (rel
.isInstanceOf(NameRelationship
.class)){
452 from
= ((NameRelationship
)rel
).getFromName();
453 to
= ((NameRelationship
)rel
).getToName();
454 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
455 from
= ((HybridRelationship
)rel
).getParentName();
456 to
= ((HybridRelationship
)rel
).getHybridName();
457 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
458 from
= ((TaxonRelationship
)rel
).getFromTaxon();
459 to
= ((TaxonRelationship
)rel
).getToTaxon();
462 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
463 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
464 fromMethod
.setAccessible(true);
465 toMethod
.setAccessible(true);
466 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
467 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
468 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
469 | IllegalArgumentException
| InvocationTargetException e
) {
470 throw new RuntimeException(e
);
473 String typeLabel
= null;
475 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
476 if (typeRepr
!= null){
477 typeLabel
= typeRepr
.getAbbreviatedLabel();
479 if (isBlank(typeLabel
) && typeRepr
!= null){
480 typeLabel
= typeRepr
.getLabel();
482 if (isBlank(typeLabel
) ){
483 typeLabel
= type
.getSymbol();
485 if (isBlank(typeLabel
)){
486 typeLabel
= type
.getTitleCache();
489 if (isBlank(typeLabel
)){
492 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
493 typeLabel
, to
== null?
null : to
.getTitleCache()});
498 private static String
getCache(HomotypicalGroup hg
) {
500 for (TaxonName tnb
: hg
.getTypifiedNames()){
501 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
503 if (isBlank(result
)){
504 result
= "No typified names";
509 private static String
getCache(KeyStatement ks
) {
512 result
= "KeyStatement";
517 public static String
getObjectClassname(Object element
) {
518 return element
.getClass().getSimpleName();
521 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
522 String result
= null;
523 if(element
.getFeatureNode() != null && element
.getFeatureNode().getTerm() != null){
524 result
= element
.getFeatureNode().getTerm().getLabel(CdmStore
.getDefaultLanguage());
526 return "No label set";
529 result
= element
.getFeatureNode().getTerm().getLabel();
534 public static String
getQuantitativeDataText(QuantitativeData element
) {
535 QuantitativeDataFormatter formatter
= new QuantitativeDataFormatter(null, null);
536 String label
= formatter
.format(element
, getLanguageList());
540 public static String
getCategoricalDataText(CategoricalData element
) {
541 CategoricalDataFormatter formatter
= new CategoricalDataFormatter(null, null);
542 return formatter
.format(element
, getLanguageList());
545 private static List
<Language
> getLanguageList(){
546 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
549 public static String
getDistributionText(Distribution element
) {
551 String text
= "EMPTY";
553 Distribution distribution
= element
;
555 NamedArea area
= distribution
.getArea();
558 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
560 PresenceAbsenceTerm status
= distribution
.getStatus();
562 if (status
!= null) {
563 text
+= ", " + status
.getLabel();
565 text
+= ", NO STATUS";
571 public static String
getImageText(Media media
) {
572 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
574 return title
.getText();
579 public static String
getElementText(TextData element
) {
581 if(element
.getFeature().equals(Feature
.CITATION())){
583 for(DescriptionElementSource source
: element
.getSources()){
584 if(source
.getCitation() != null){
585 text
+= source
.getCitation().getTitleCache();
587 if(source
.getNameUsedInSource() != null){
588 text
+= " [" + source
.getNameUsedInSource().getTitleCache() + "]";
592 text
= "No sources provided";
595 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
596 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
597 text
= languageString
!= null ? languageString
.getText() : null;
599 return isBlank(text
) ?
"No text provided" : text
;
602 public static String
getTaxonInteractionText(TaxonInteraction element
) {
604 Taxon taxon2
= element
.getTaxon2();
605 if(taxon2
!= null && taxon2
.getName() != null){
606 text
= taxon2
.getName().getTitleCache();
608 text
= "No taxon chosen";
614 public static String
getCommonNameText(CommonTaxonName commonName
) {
615 String name
= commonName
.getName();
616 if (name
== null || name
.length() == 0) {
617 name
= "No name provided";
619 Language language
= commonName
.getLanguage();
620 if (language
== null) {
621 name
+= " (No language provided)";
623 name
+= " (" + language
.getLabel(CdmStore
.getDefaultLanguage()) + ")";
628 public static String
getDescriptionText(DescriptionBase element
) {
629 String text
= element
.getTitleCache();
630 if (text
== null || text
.length() == 0) {
631 text
= "No label provided";
637 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
638 SpecimenOrObservationBase
<?
> derivedUnit
= element
.getAssociatedSpecimenOrObservation();
639 if(derivedUnit
!= null){
640 return derivedUnit
.getTitleCache();
642 return "No unit chosen";
645 public static String
getLabel(Object element
){
646 if (element
instanceof FeatureNodeContainer
){
647 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
649 else if (element
instanceof DescriptionBase
) {
650 return getDescriptionText((DescriptionBase
<?
>) element
);
652 else if(element
instanceof CategoricalData
){
653 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
654 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
655 categoricalDataText
= NO_LABEL_STRING
;
657 return categoricalDataText
;
659 else if (element
instanceof CommonTaxonName
) {
660 return getCommonNameText((CommonTaxonName
) element
);
662 else if (element
instanceof Distribution
) {
663 return getDistributionText((Distribution
) element
);
665 else if (element
instanceof IndividualsAssociation
) {
666 return getIndividualsAssociationText((IndividualsAssociation
) element
);
668 else if (element
instanceof QuantitativeData
) {
669 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
670 if(isBlank(quantitativeDataText
)){
671 quantitativeDataText
= NO_LABEL_STRING
;
673 return quantitativeDataText
;
675 else if (element
instanceof TaxonInteraction
) {
676 return getTaxonInteractionText((TaxonInteraction
) element
);
678 else if (element
instanceof TextData
) {
679 return getElementText((TextData
) element
);
681 else if (element
instanceof TemporalData
) {
682 String lable
= getTemporalDataText((TemporalData
) element
);
684 lable
= NO_LABEL_STRING
;
689 return element
.toString();
693 private static String
getTemporalDataText(TemporalData element
) {
694 ExtendedTimePeriod period
= element
.getPeriod();
695 ExtendedTimePeriodFormatter formatter
= ExtendedTimePeriodFormatter
.NewDefaultInstance();
696 return period
== null ? NO_LABEL_STRING
: formatter
.format(period
);
699 private static boolean isNotBlank(String str
){
700 return StringUtils
.isNotBlank(str
);
703 private static boolean isBlank(String str
){
704 return StringUtils
.isBlank(str
);