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();
236 // if(sourcedObject instanceof IIdentifiableEntity){
237 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
238 // }else if(sourcedObject instanceof DescriptionElementBase){
239 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
241 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
244 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
245 }catch(LazyInitializationException e
){
246 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
247 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
248 resultString
= "TODO: " + result
;
250 }else if (element
instanceof LanguageStringBase
) {
251 resultString
= ((LanguageStringBase
) element
).getText();
252 }else if (element
instanceof DescriptionElementBase
) {
253 resultString
= getCache((DescriptionElementBase
) element
);
254 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
255 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
256 }else if (element
instanceof TypeDesignationBase
<?
>) {
257 resultString
= getCache((TypeDesignationBase
<?
>) element
);
258 }else if (element
instanceof HomotypicalGroup
) {
259 resultString
= getCache((HomotypicalGroup
) element
);
260 }else if (element
instanceof TaxonNode
) {
261 resultString
= getCache((TaxonNode
) element
);
262 }else if (element
instanceof DeterminationEvent
) {
263 resultString
= getCache((DeterminationEvent
) element
);
264 }else if (element
instanceof GatheringEvent
){
265 resultString
= getCache((GatheringEvent
) element
);
266 }else if (element
instanceof Marker
) {
267 Marker marker
= (Marker
) element
;
268 MarkerType type
= marker
.getMarkerType();
269 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
270 }else if (element
instanceof User
) {
271 User user
= (User
) element
;
272 resultString
= user
.getUsername();
273 }else if (element
instanceof Group
) {
274 Group group
= (Group
) element
;
275 resultString
= group
.getName();
276 }else if (element
instanceof KeyStatement
) {
277 KeyStatement keyStatement
= (KeyStatement
) element
;
278 resultString
= getCache(keyStatement
);
280 // TODO write return texts for HomotypicalGroup, etc.
281 resultString
= element
.toString();
284 if (resultString
== null){
285 resultString
= element
.toString();
290 private static String
getCache(GatheringEvent gatheringEvent
){
291 String ALTITUDE_PREFIX
= "alt. ";
292 final String METER
= "m";
297 AgentBase
<?
> collector
= CdmBase
.deproxy(gatheringEvent
.getCollector());
298 String collectorStr
= collector
== null?
null : collector
.getTitleCache();
299 result
= CdmUtils
.concat(", ", result
, collectorStr
);
302 TimePeriod gatheringPeriod
= gatheringEvent
.getTimeperiod();
303 result
= CdmUtils
.concat(", ", result
, (gatheringPeriod
== null?
null : gatheringPeriod
.toString()));
306 String strCountry
= null;
307 NamedArea country
= gatheringEvent
.getCountry();
308 Representation repCountry
= country
== null ?
null : country
.getRepresentation(Language
.DEFAULT());
309 strCountry
= repCountry
== null ?
null: repCountry
.getLabel();
310 result
= CdmUtils
.concat(", ", result
, strCountry
);
313 LanguageString locality
= gatheringEvent
.getLocality();
314 if (locality
!= null) {
315 result
= CdmUtils
.concat(", ", result
, locality
.getText());
320 if (isNotBlank(gatheringEvent
.getAbsoluteElevationText())){
321 elevationStr
= gatheringEvent
.getAbsoluteElevationText();
323 String text
= gatheringEvent
.getAbsoluteElevationText();
324 Integer min
= gatheringEvent
.getAbsoluteElevation();
325 Integer max
= gatheringEvent
.getAbsoluteElevationMax();
326 elevationStr
= DerivedUnitFacade
.distanceString(min
, max
, text
, METER
);
328 if (isNotBlank(elevationStr
)){
329 result
= CdmUtils
.concat(", " , result
, ALTITUDE_PREFIX
);
330 result
+= elevationStr
;
334 if (gatheringEvent
.getExactLocation() != null){
335 String exactLocation
= gatheringEvent
.getExactLocation().toSexagesimalString(false, false);
336 result
= CdmUtils
.concat(", ", result
, exactLocation
);
342 private static String
getCache(DeterminationEvent detEvent
) {
344 String taxonStr
= null;
345 TaxonName taxonName
= detEvent
.getTaxonName();
346 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
347 if (taxonName
!= null){
348 taxonStr
= taxonName
.getTitleCache();
350 if (isBlank(taxonStr
) && taxon
!= null){
351 taxonStr
= taxon
.getTitleCache();
353 if (isBlank(taxonStr
)){
354 taxonStr
= "no or unlabled taxon";
358 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
361 unitStr
= unit
.getTitleCache();
362 if (isBlank(unitStr
)){
363 unitStr
= "Unlabled unit";
369 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
374 private static String
getCache(TaxonNode taxonNode
) {
376 Classification classification
= taxonNode
.getClassification();
377 if (classification
!= null){
378 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
379 result
= CdmUtils
.concat("" , result
, classificationStr
);
380 if (isBlank(result
)){
381 result
= classification
.toString();
385 TaxonNode parentNode
= taxonNode
.getParent();
386 if (parentNode
== null){
387 parentStr
= "no parent";
389 Taxon parentTaxon
= parentNode
.getTaxon();
390 if (parentTaxon
== null){
391 parentStr
= "no parent taxon";
393 TaxonName parentName
= parentTaxon
.getName();
394 if (parentName
== null){
395 parentStr
= "child of " + parentTaxon
.getTitleCache();
397 parentStr
= "child of " + parentName
.getTitleCache();
401 result
= CdmUtils
.concat(": ", result
, parentStr
);
406 private static String
getCache(TypeDesignationBase
<?
> designation
) {
407 designation
= CdmBase
.deproxy(designation
);
409 String fromString
= null;
410 Set
<TaxonName
> from
= designation
.getTypifiedNames();
412 for (TaxonName name
: from
){
413 fromString
= CdmUtils
.concat(",", fromString
, name
.getTitleCache());
417 IdentifiableEntity
<?
> to
= null;
419 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
420 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
421 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
422 to
= ((NameTypeDesignation
)designation
).getTypeName();
423 }else if (designation
.isInstanceOf(TextualTypeDesignation
.class)){
424 toStr
= ((TextualTypeDesignation
)designation
).getPreferredText(CdmStore
.getDefaultLanguage());
426 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
428 toStr
= to
== null? toStr
: to
.getTitleCache();
430 String typeLabel
= null;
431 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
433 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
434 if (typeRepr
!= null){
435 typeLabel
= typeRepr
.getAbbreviatedLabel();
437 if (isBlank(typeLabel
) && typeRepr
!= null){
438 typeLabel
= typeRepr
.getLabel();
440 if (isBlank(typeLabel
) ){
441 typeLabel
= status
.getSymbol();
443 if (isBlank(typeLabel
)){
444 typeLabel
= status
.getTitleCache();
447 if (isBlank(typeLabel
)){
451 String result
= CdmUtils
.concat(" ", new String
[]{fromString
, typeLabel
, toStr
});
455 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
456 rel
= CdmBase
.deproxy(rel
);
457 RelationshipTermBase
<?
> type
= rel
.getType();
458 IdentifiableEntity
<?
> from
;
459 IdentifiableEntity
<?
> to
;
460 if (rel
.isInstanceOf(NameRelationship
.class)){
461 from
= ((NameRelationship
)rel
).getFromName();
462 to
= ((NameRelationship
)rel
).getToName();
463 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
464 from
= ((HybridRelationship
)rel
).getParentName();
465 to
= ((HybridRelationship
)rel
).getHybridName();
466 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
467 from
= ((TaxonRelationship
)rel
).getFromTaxon();
468 to
= ((TaxonRelationship
)rel
).getToTaxon();
471 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
472 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
473 fromMethod
.setAccessible(true);
474 toMethod
.setAccessible(true);
475 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
476 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
477 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
478 | IllegalArgumentException
| InvocationTargetException e
) {
479 throw new RuntimeException(e
);
482 String typeLabel
= null;
484 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
485 if (typeRepr
!= null){
486 typeLabel
= typeRepr
.getAbbreviatedLabel();
488 if (isBlank(typeLabel
) && typeRepr
!= null){
489 typeLabel
= typeRepr
.getLabel();
491 if (isBlank(typeLabel
) ){
492 typeLabel
= type
.getSymbol();
494 if (isBlank(typeLabel
)){
495 typeLabel
= type
.getTitleCache();
498 if (isBlank(typeLabel
)){
501 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
502 typeLabel
, to
== null?
null : to
.getTitleCache()});
507 private static String
getCache(HomotypicalGroup hg
) {
509 for (TaxonName tnb
: hg
.getTypifiedNames()){
510 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
512 if (isBlank(result
)){
513 result
= "No typified names";
518 private static String
getCache(KeyStatement ks
) {
521 result
= "KeyStatement";
526 public static String
getObjectClassname(Object element
) {
527 return element
.getClass().getSimpleName();
530 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
531 String result
= null;
532 if(element
.getFeatureNode() != null && element
.getFeatureNode().getTerm() != null){
533 result
= element
.getFeatureNode().getTerm().getLabel(CdmStore
.getDefaultLanguage());
535 return "No label set";
538 result
= element
.getFeatureNode().getTerm().getLabel();
543 public static String
getQuantitativeDataText(QuantitativeData element
) {
544 QuantitativeDataFormatter formatter
= new QuantitativeDataFormatter(null, null);
545 String label
= formatter
.format(element
, getLanguageList());
549 public static String
getCategoricalDataText(CategoricalData element
) {
550 CategoricalDataFormatter formatter
= new CategoricalDataFormatter(null, null);
551 return formatter
.format(element
, getLanguageList());
554 private static List
<Language
> getLanguageList(){
555 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
558 public static String
getDistributionText(Distribution element
) {
560 String text
= "EMPTY";
562 Distribution distribution
= element
;
564 NamedArea area
= distribution
.getArea();
567 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
569 PresenceAbsenceTerm status
= distribution
.getStatus();
571 if (status
!= null) {
572 text
+= ", " + status
.getLabel();
574 text
+= ", NO STATUS";
580 public static String
getImageText(Media media
) {
581 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
583 return title
.getText();
588 public static String
getElementText(TextData element
) {
590 if(element
.getFeature().equals(Feature
.CITATION())){
592 for(DescriptionElementSource source
: element
.getSources()){
593 if(source
.getCitation() != null){
594 text
+= source
.getCitation().getTitleCache();
596 if(source
.getNameUsedInSource() != null){
597 text
+= " [" + source
.getNameUsedInSource().getTitleCache() + "]";
601 text
= "No sources provided";
604 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
605 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
606 text
= languageString
!= null ? languageString
.getText() : null;
608 return isBlank(text
) ?
"No text provided" : text
;
611 public static String
getTaxonInteractionText(TaxonInteraction element
) {
613 Taxon taxon2
= element
.getTaxon2();
614 if(taxon2
!= null && taxon2
.getName() != null){
615 text
= taxon2
.getName().getTitleCache();
617 text
= "No taxon chosen";
623 public static String
getCommonNameText(CommonTaxonName commonName
) {
624 String name
= commonName
.getName();
625 if (name
== null || name
.length() == 0) {
626 name
= "No name provided";
628 Language language
= commonName
.getLanguage();
629 if (language
== null) {
630 name
+= " (No language provided)";
632 name
+= " (" + language
.getLabel(CdmStore
.getDefaultLanguage()) + ")";
637 public static String
getDescriptionText(DescriptionBase element
) {
638 String text
= element
.getTitleCache();
639 if (text
== null || text
.length() == 0) {
640 text
= "No label provided";
646 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
647 SpecimenOrObservationBase
<?
> derivedUnit
= element
.getAssociatedSpecimenOrObservation();
648 if(derivedUnit
!= null){
649 return derivedUnit
.getTitleCache();
651 return "No unit chosen";
654 public static String
getLabel(Object element
){
655 if (element
instanceof FeatureNodeContainer
){
656 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
658 else if (element
instanceof DescriptionBase
) {
659 return getDescriptionText((DescriptionBase
<?
>) element
);
661 else if(element
instanceof CategoricalData
){
662 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
663 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
664 categoricalDataText
= NO_LABEL_STRING
;
666 return categoricalDataText
;
668 else if (element
instanceof CommonTaxonName
) {
669 return getCommonNameText((CommonTaxonName
) element
);
671 else if (element
instanceof Distribution
) {
672 return getDistributionText((Distribution
) element
);
674 else if (element
instanceof IndividualsAssociation
) {
675 return getIndividualsAssociationText((IndividualsAssociation
) element
);
677 else if (element
instanceof QuantitativeData
) {
678 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
679 if(isBlank(quantitativeDataText
)){
680 quantitativeDataText
= NO_LABEL_STRING
;
682 return quantitativeDataText
;
684 else if (element
instanceof TaxonInteraction
) {
685 return getTaxonInteractionText((TaxonInteraction
) element
);
687 else if (element
instanceof TextData
) {
688 return getElementText((TextData
) element
);
690 else if (element
instanceof TemporalData
) {
691 String lable
= getTemporalDataText((TemporalData
) element
);
693 lable
= NO_LABEL_STRING
;
698 return element
.toString();
702 private static String
getTemporalDataText(TemporalData element
) {
703 ExtendedTimePeriod period
= element
.getPeriod();
704 ExtendedTimePeriodFormatter formatter
= ExtendedTimePeriodFormatter
.NewDefaultInstance();
705 return period
== null ? NO_LABEL_STRING
: formatter
.format(period
);
708 private static boolean isNotBlank(String str
){
709 return StringUtils
.isNotBlank(str
);
712 private static boolean isBlank(String str
){
713 return StringUtils
.isBlank(str
);