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.
9 package eu
.etaxonomy
.taxeditor
.model
;
11 import java
.lang
.reflect
.InvocationTargetException
;
12 import java
.lang
.reflect
.Method
;
13 import java
.util
.Arrays
;
14 import java
.util
.List
;
17 import org
.apache
.commons
.lang3
.StringUtils
;
18 import org
.hibernate
.LazyInitializationException
;
20 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
21 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
22 import eu
.etaxonomy
.cdm
.format
.common
.ExtendedTimePeriodFormatter
;
23 import eu
.etaxonomy
.cdm
.format
.description
.CategoricalDataFormatter
;
24 import eu
.etaxonomy
.cdm
.format
.description
.QuantitativeDataFormatter
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.ExtendedTimePeriod
;
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
.RelationshipBase
;
35 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
37 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
38 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
39 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
40 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
41 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
42 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
43 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
44 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
45 import eu
.etaxonomy
.cdm
.model
.description
.KeyStatement
;
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
.TemporalData
;
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
.NomenclaturalSource
;
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 * DescriptionHelper class.
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
227 String sourceObjectTitle
= "sourced object data not available (#5743)";
229 //it is now possible for NomenclaturalSource as they link to the sourced name
230 if (originalSource
instanceof NomenclaturalSource
){
231 TaxonName sourcedName
= ((NomenclaturalSource
)originalSource
).getSourcedName();
232 sourceObjectTitle
= sourcedName
== null ?
"Source not attached to a name" :
233 "Nom. source for " + sourcedName
.getTitleCache();
237 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
238 }catch(LazyInitializationException e
){
239 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
240 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
241 resultString
= "TODO: " + result
;
243 }else if (element
instanceof LanguageStringBase
) {
244 resultString
= ((LanguageStringBase
) element
).getText();
245 }else if (element
instanceof DescriptionElementBase
) {
246 resultString
= getCache((DescriptionElementBase
) element
);
247 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
248 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
249 }else if (element
instanceof TypeDesignationBase
<?
>) {
250 resultString
= getCache((TypeDesignationBase
<?
>) element
);
251 }else if (element
instanceof HomotypicalGroup
) {
252 resultString
= getCache((HomotypicalGroup
) element
);
253 }else if (element
instanceof TaxonNode
) {
254 resultString
= getCache((TaxonNode
) element
);
255 }else if (element
instanceof DeterminationEvent
) {
256 resultString
= getCache((DeterminationEvent
) element
);
257 }else if (element
instanceof GatheringEvent
){
258 resultString
= getCache((GatheringEvent
) element
);
259 }else if (element
instanceof Marker
) {
260 Marker marker
= (Marker
) element
;
261 MarkerType type
= marker
.getMarkerType();
262 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
263 }else if (element
instanceof User
) {
264 User user
= (User
) element
;
265 resultString
= user
.getUsername();
266 }else if (element
instanceof Group
) {
267 Group group
= (Group
) element
;
268 resultString
= group
.getName();
269 }else if (element
instanceof KeyStatement
) {
270 KeyStatement keyStatement
= (KeyStatement
) element
;
271 resultString
= getCache(keyStatement
);
273 // TODO write return texts for HomotypicalGroup, etc.
274 resultString
= element
.toString();
277 if (resultString
== null){
278 resultString
= element
.toString();
283 private static String
getCache(GatheringEvent gatheringEvent
){
284 String ALTITUDE_PREFIX
= "alt. ";
285 final String METER
= "m";
290 AgentBase
<?
> collector
= CdmBase
.deproxy(gatheringEvent
.getCollector());
291 String collectorStr
= collector
== null?
null : collector
.getTitleCache();
292 result
= CdmUtils
.concat(", ", result
, collectorStr
);
295 TimePeriod gatheringPeriod
= gatheringEvent
.getTimeperiod();
296 result
= CdmUtils
.concat(", ", result
, (gatheringPeriod
== null?
null : gatheringPeriod
.toString()));
299 String strCountry
= null;
300 NamedArea country
= gatheringEvent
.getCountry();
301 Representation repCountry
= country
== null ?
null : country
.getRepresentation(Language
.DEFAULT());
302 strCountry
= repCountry
== null ?
null: repCountry
.getLabel();
303 result
= CdmUtils
.concat(", ", result
, strCountry
);
306 LanguageString locality
= gatheringEvent
.getLocality();
307 if (locality
!= null) {
308 result
= CdmUtils
.concat(", ", result
, locality
.getText());
313 if (isNotBlank(gatheringEvent
.getAbsoluteElevationText())){
314 elevationStr
= gatheringEvent
.getAbsoluteElevationText();
316 String text
= gatheringEvent
.getAbsoluteElevationText();
317 Integer min
= gatheringEvent
.getAbsoluteElevation();
318 Integer max
= gatheringEvent
.getAbsoluteElevationMax();
319 elevationStr
= DerivedUnitFacade
.distanceString(min
, max
, text
, METER
);
321 if (isNotBlank(elevationStr
)){
322 result
= CdmUtils
.concat(", " , result
, ALTITUDE_PREFIX
);
323 result
+= elevationStr
;
327 if (gatheringEvent
.getExactLocation() != null){
328 String exactLocation
= gatheringEvent
.getExactLocation().toSexagesimalString(false, false);
329 result
= CdmUtils
.concat(", ", result
, exactLocation
);
335 private static String
getCache(DeterminationEvent detEvent
) {
337 String taxonStr
= null;
338 TaxonName taxonName
= detEvent
.getTaxonName();
339 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
340 if (taxonName
!= null){
341 taxonStr
= taxonName
.getTitleCache();
343 if (isBlank(taxonStr
) && taxon
!= null){
344 taxonStr
= taxon
.getTitleCache();
346 if (isBlank(taxonStr
)){
347 taxonStr
= "no or unlabled taxon";
351 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
354 unitStr
= unit
.getTitleCache();
355 if (isBlank(unitStr
)){
356 unitStr
= "Unlabled unit";
362 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
367 private static String
getCache(TaxonNode taxonNode
) {
369 Classification classification
= taxonNode
.getClassification();
370 if (classification
!= null){
371 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
372 result
= CdmUtils
.concat("" , result
, classificationStr
);
373 if (isBlank(result
)){
374 result
= classification
.toString();
378 TaxonNode parentNode
= taxonNode
.getParent();
379 if (parentNode
== null){
380 parentStr
= "no parent";
382 Taxon parentTaxon
= parentNode
.getTaxon();
383 if (parentTaxon
== null){
384 parentStr
= "no parent taxon";
386 TaxonName parentName
= parentTaxon
.getName();
387 if (parentName
== null){
388 parentStr
= "child of " + parentTaxon
.getTitleCache();
390 parentStr
= "child of " + parentName
.getTitleCache();
394 result
= CdmUtils
.concat(": ", result
, parentStr
);
399 private static String
getCache(TypeDesignationBase
<?
> designation
) {
400 designation
= CdmBase
.deproxy(designation
);
402 String fromString
= null;
403 Set
<TaxonName
> from
= designation
.getTypifiedNames();
405 for (TaxonName name
: from
){
406 fromString
= CdmUtils
.concat(",", fromString
, name
.getTitleCache());
410 IdentifiableEntity
<?
> to
= null;
412 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
413 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
414 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
415 to
= ((NameTypeDesignation
)designation
).getTypeName();
416 }else if (designation
.isInstanceOf(TextualTypeDesignation
.class)){
417 toStr
= ((TextualTypeDesignation
)designation
).getPreferredText(CdmStore
.getDefaultLanguage());
419 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
421 toStr
= to
== null? toStr
: to
.getTitleCache();
423 String typeLabel
= null;
424 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
426 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
427 if (typeRepr
!= null){
428 typeLabel
= typeRepr
.getAbbreviatedLabel();
430 if (isBlank(typeLabel
) && typeRepr
!= null){
431 typeLabel
= typeRepr
.getLabel();
433 if (isBlank(typeLabel
) ){
434 typeLabel
= status
.getSymbol();
436 if (isBlank(typeLabel
)){
437 typeLabel
= status
.getTitleCache();
440 if (isBlank(typeLabel
)){
444 String result
= CdmUtils
.concat(" ", new String
[]{fromString
, typeLabel
, toStr
});
448 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
449 rel
= CdmBase
.deproxy(rel
);
450 RelationshipTermBase
<?
> type
= rel
.getType();
451 IdentifiableEntity
<?
> from
;
452 IdentifiableEntity
<?
> to
;
453 if (rel
.isInstanceOf(NameRelationship
.class)){
454 from
= ((NameRelationship
)rel
).getFromName();
455 to
= ((NameRelationship
)rel
).getToName();
456 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
457 from
= ((HybridRelationship
)rel
).getParentName();
458 to
= ((HybridRelationship
)rel
).getHybridName();
459 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
460 from
= ((TaxonRelationship
)rel
).getFromTaxon();
461 to
= ((TaxonRelationship
)rel
).getToTaxon();
464 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
465 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
466 fromMethod
.setAccessible(true);
467 toMethod
.setAccessible(true);
468 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
469 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
470 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
471 | IllegalArgumentException
| InvocationTargetException e
) {
472 throw new RuntimeException(e
);
475 String typeLabel
= null;
477 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
478 if (typeRepr
!= null){
479 typeLabel
= typeRepr
.getAbbreviatedLabel();
481 if (isBlank(typeLabel
) && typeRepr
!= null){
482 typeLabel
= typeRepr
.getLabel();
484 if (isBlank(typeLabel
) ){
485 typeLabel
= type
.getSymbol();
487 if (isBlank(typeLabel
)){
488 typeLabel
= type
.getTitleCache();
491 if (isBlank(typeLabel
)){
494 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
495 typeLabel
, to
== null?
null : to
.getTitleCache()});
500 private static String
getCache(HomotypicalGroup hg
) {
502 for (TaxonName tnb
: hg
.getTypifiedNames()){
503 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
505 if (isBlank(result
)){
506 result
= "No typified names";
511 private static String
getCache(KeyStatement ks
) {
514 result
= "KeyStatement";
519 public static String
getObjectClassname(Object element
) {
520 return element
.getClass().getSimpleName();
523 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
524 String result
= null;
525 if(element
.getFeatureNode() != null && element
.getFeatureNode().getTerm() != null){
526 result
= element
.getFeatureNode().getTerm().getLabel(CdmStore
.getDefaultLanguage());
528 return "No label set";
531 result
= element
.getFeatureNode().getTerm().getLabel();
536 public static String
getQuantitativeDataText(QuantitativeData element
) {
537 QuantitativeDataFormatter formatter
= new QuantitativeDataFormatter(null, null);
538 String label
= formatter
.format(element
, getLanguageList());
542 public static String
getCategoricalDataText(CategoricalData element
) {
543 CategoricalDataFormatter formatter
= new CategoricalDataFormatter(null, null);
544 return formatter
.format(element
, getLanguageList());
547 private static List
<Language
> getLanguageList(){
548 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
551 public static String
getDistributionText(Distribution element
) {
553 String text
= "EMPTY";
555 Distribution distribution
= element
;
557 NamedArea area
= distribution
.getArea();
560 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
562 PresenceAbsenceTerm status
= distribution
.getStatus();
564 if (status
!= null) {
565 text
+= ", " + status
.getLabel();
567 text
+= ", NO STATUS";
573 public static String
getImageText(Media media
) {
574 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
576 return title
.getText();
581 public static String
getElementText(TextData element
) {
583 if(element
.getFeature().equals(Feature
.CITATION())){
585 for(DescriptionElementSource source
: element
.getSources()){
586 if(source
.getCitation() != null){
587 text
+= source
.getCitation().getTitleCache();
589 if(source
.getNameUsedInSource() != null){
590 text
+= " [" + source
.getNameUsedInSource().getTitleCache() + "]";
594 text
= "No sources provided";
597 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
598 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
599 text
= languageString
!= null ? languageString
.getText() : null;
601 return isBlank(text
) ?
"No text provided" : text
;
604 public static String
getTaxonInteractionText(TaxonInteraction element
) {
606 Taxon taxon2
= element
.getTaxon2();
607 if(taxon2
!= null && taxon2
.getName() != null){
608 text
= taxon2
.getName().getTitleCache();
610 text
= "No taxon chosen";
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
.getLabel(CdmStore
.getDefaultLanguage()) + ")";
630 public static String
getDescriptionText(DescriptionBase element
) {
631 String text
= element
.getTitleCache();
632 if (text
== null || text
.length() == 0) {
633 text
= "No label provided";
639 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
640 SpecimenOrObservationBase
<?
> derivedUnit
= element
.getAssociatedSpecimenOrObservation();
641 if(derivedUnit
!= null){
642 return derivedUnit
.getTitleCache();
644 return "No unit chosen";
647 public static String
getLabel(Object element
){
648 if (element
instanceof FeatureNodeContainer
){
649 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
651 else if (element
instanceof DescriptionBase
) {
652 return getDescriptionText((DescriptionBase
<?
>) element
);
654 else if(element
instanceof CategoricalData
){
655 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
656 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
657 categoricalDataText
= NO_LABEL_STRING
;
659 return categoricalDataText
;
661 else if (element
instanceof CommonTaxonName
) {
662 return getCommonNameText((CommonTaxonName
) element
);
664 else if (element
instanceof Distribution
) {
665 return getDistributionText((Distribution
) element
);
667 else if (element
instanceof IndividualsAssociation
) {
668 return getIndividualsAssociationText((IndividualsAssociation
) element
);
670 else if (element
instanceof QuantitativeData
) {
671 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
672 if(isBlank(quantitativeDataText
)){
673 quantitativeDataText
= NO_LABEL_STRING
;
675 return quantitativeDataText
;
677 else if (element
instanceof TaxonInteraction
) {
678 return getTaxonInteractionText((TaxonInteraction
) element
);
680 else if (element
instanceof TextData
) {
681 return getElementText((TextData
) element
);
683 else if (element
instanceof TemporalData
) {
684 String lable
= getTemporalDataText((TemporalData
) element
);
686 lable
= NO_LABEL_STRING
;
691 return element
.toString();
695 private static String
getTemporalDataText(TemporalData element
) {
696 ExtendedTimePeriod period
= element
.getPeriod();
697 ExtendedTimePeriodFormatter formatter
= ExtendedTimePeriodFormatter
.NewDefaultInstance();
698 return period
== null ? NO_LABEL_STRING
: formatter
.format(period
);
701 private static boolean isNotBlank(String str
){
702 return StringUtils
.isNotBlank(str
);
705 private static boolean isBlank(String str
){
706 return StringUtils
.isBlank(str
);