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
;
20 import org
.joda
.time
.DateTimeFieldType
;
21 import org
.joda
.time
.Partial
;
22 import org
.joda
.time
.format
.DateTimeFormatter
;
24 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
25 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
26 import eu
.etaxonomy
.cdm
.format
.description
.DefaultCategoricalDescriptionBuilder
;
27 import eu
.etaxonomy
.cdm
.format
.description
.DefaultQuantitativeDescriptionBuilder
;
28 import eu
.etaxonomy
.cdm
.format
.description
.DescriptionBuilder
;
29 import eu
.etaxonomy
.cdm
.format
.description
.QuantitativeDataFormatter
;
30 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
32 import eu
.etaxonomy
.cdm
.model
.common
.ExtendedTimePeriod
;
33 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
35 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
36 import eu
.etaxonomy
.cdm
.model
.common
.LanguageStringBase
;
37 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
38 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
39 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
40 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
41 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
42 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
43 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
44 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
45 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
46 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
47 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
48 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
49 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
50 import eu
.etaxonomy
.cdm
.model
.description
.KeyStatement
;
51 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
52 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
53 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
54 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
55 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
56 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
57 import eu
.etaxonomy
.cdm
.model
.description
.TemporalData
;
58 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
59 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
60 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
61 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
62 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
63 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
64 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
65 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
66 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
67 import eu
.etaxonomy
.cdm
.model
.name
.TextualTypeDesignation
;
68 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
69 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatusBase
;
70 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
71 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
72 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
73 import eu
.etaxonomy
.cdm
.model
.permission
.Group
;
74 import eu
.etaxonomy
.cdm
.model
.permission
.User
;
75 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceBase
;
76 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
77 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
78 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
79 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
80 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
81 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
82 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.ExtendedTimePeriodPartialFormatter
;
83 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
86 * <p>DescriptionHelper class.</p>
91 public class DescriptionHelper
{
94 * Returns whatever the element's title cache equivalent is,
95 * depending on its class.
97 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
98 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
99 * @return a {@link java.lang.String} object.
101 public static String
getCache(DescriptionElementBase element
,
104 String mainElementLabel
= null;
105 DescriptionBase
<?
> descr
= element
.getInDescription();
106 descr
= CdmBase
.deproxy(descr
, DescriptionBase
.class);
109 if (descr
.isInstanceOf(TaxonDescription
.class)){
110 Taxon taxon
= CdmBase
.deproxy(descr
, TaxonDescription
.class).getTaxon();
112 mainElementLabel
= taxon
.getTitleCache();
114 }else if (descr
.isInstanceOf(SpecimenDescription
.class)){
115 SpecimenOrObservationBase
<?
> specimen
= CdmBase
.deproxy(descr
, SpecimenDescription
.class).getDescribedSpecimenOrObservation();
116 if (specimen
!= null){
117 mainElementLabel
= specimen
.getTitleCache();
119 }else if (descr
.isInstanceOf(TaxonNameDescription
.class)){
120 TaxonName name
= CdmBase
.deproxy(descr
, TaxonNameDescription
.class).getTaxonName();
122 mainElementLabel
= name
.getTitleCache();
129 if (element
instanceof TextData
) {
130 //cache = ((TextData) element).getText(language);
133 if (element
instanceof CommonTaxonName
) {
134 cache
= ((CommonTaxonName
) element
).getName();
136 if (element
instanceof TaxonInteraction
) {
137 Taxon taxon2
= ((TaxonInteraction
) element
).getTaxon2();
138 if(taxon2
!= null && taxon2
.getName() != null){
139 cache
= taxon2
.getName().getTitleCache();
141 cache
= "No taxon chosen";
145 if (element
instanceof Distribution
) {
146 Distribution distribution
= (Distribution
) element
;
148 NamedArea area
= distribution
.getArea();
150 cache
= area
.getLabel();
152 PresenceAbsenceTerm status
= distribution
.getStatus();
154 cache
+= ", no status";
156 cache
+= ", " + status
.getLabel();
160 String result
= cache
== null ?
"" : cache
;
161 if (isNotBlank(mainElementLabel
)){
162 result
= CdmUtils
.concat(" ", result
, "(" + mainElementLabel
+ ")");
168 * Returns whatever the element's title cache equivalent is,
169 * depending on its class, using the default language.
171 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
172 * @return a {@link java.lang.String} object.
174 public static String
getCache(DescriptionElementBase element
) {
175 return getCache(element
, CdmStore
.getDefaultLanguage());
179 * Set whatever the element's title cache equivalent is,
180 * depending on its class.
182 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
183 * @param value a {@link java.lang.String} object.
184 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
186 public static void setCache(DescriptionElementBase element
,
187 String value
, Language language
) {
188 if (element
instanceof TextData
) {
189 ((TextData
) element
).putText(language
, value
);
191 }else if (element
instanceof CommonTaxonName
) {
192 ((CommonTaxonName
) element
).setName(value
);
194 }else if (element
instanceof TaxonInteraction
) {
196 }else if(element
instanceof Distribution
){
197 MessagingUtils
.warn(DescriptionHelper
.class, "trying to set cache on distribution, don't know what to do at the moment.");
200 MessagingUtils
.warn(DescriptionHelper
.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
205 * Set whatever the element's title cache equivalent is,
206 * depending on its class, using the default language.
208 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
209 * @param value a {@link java.lang.String} object.
211 public static void setCache(DescriptionElementBase element
,
213 setCache(element
, value
, CdmStore
.getDefaultLanguage());
216 public static String
getObjectDescription(Object element
) {
217 String resultString
= null;
218 if (element
instanceof IdentifiableEntity
) {
220 resultString
= ((IdentifiableEntity
) element
).getTitleCache();
221 }catch(LazyInitializationException e
){
222 String result
= "No Session to initialize title cache for IdentifiableEntity";
223 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
224 resultString
= "TODO: " + result
;
226 }else if (element
instanceof OriginalSourceBase
) {
228 OriginalSourceBase
<?
> originalSource
= (OriginalSourceBase
<?
>) element
;
229 // ISourceable sourcedObject = originalSource.getSourcedObj();
230 //due to #5743 the bidirectionality for sourced object had to be removed
231 String sourceObjectTitle
= "sourced object data not available (#5743)";
232 // if(sourcedObject instanceof IIdentifiableEntity){
233 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
234 // }else if(sourcedObject instanceof DescriptionElementBase){
235 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
237 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
240 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
241 }catch(LazyInitializationException e
){
242 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
243 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
244 resultString
= "TODO: " + result
;
246 }else if (element
instanceof LanguageStringBase
) {
247 resultString
= ((LanguageStringBase
) element
).getText();
248 }else if (element
instanceof DescriptionElementBase
) {
249 resultString
= getCache((DescriptionElementBase
) element
);
250 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
251 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
252 }else if (element
instanceof TypeDesignationBase
<?
>) {
253 resultString
= getCache((TypeDesignationBase
<?
>) element
);
254 }else if (element
instanceof HomotypicalGroup
) {
255 resultString
= getCache((HomotypicalGroup
) element
);
256 }else if (element
instanceof TaxonNode
) {
257 resultString
= getCache((TaxonNode
) element
);
258 }else if (element
instanceof DeterminationEvent
) {
259 resultString
= getCache((DeterminationEvent
) element
);
260 }else if (element
instanceof GatheringEvent
){
261 resultString
= getCache((GatheringEvent
) element
);
262 }else if (element
instanceof Marker
) {
263 Marker marker
= (Marker
) element
;
264 MarkerType type
= marker
.getMarkerType();
265 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
266 }else if (element
instanceof User
) {
267 User user
= (User
) element
;
268 resultString
= user
.getUsername();
269 }else if (element
instanceof Group
) {
270 Group group
= (Group
) element
;
271 resultString
= group
.getName();
272 }else if (element
instanceof KeyStatement
) {
273 KeyStatement keyStatement
= (KeyStatement
) element
;
274 resultString
= getCache(keyStatement
);
276 // TODO write return texts for HomotypicalGroup, etc.
277 resultString
= element
.toString();
280 if (resultString
== null){
281 resultString
= element
.toString();
286 private static String
getCache(GatheringEvent gatheringEvent
){
287 String ALTITUDE_PREFIX
= "alt. ";
288 final String METER
= "m";
293 AgentBase
<?
> collector
= CdmBase
.deproxy(gatheringEvent
.getCollector());
294 String collectorStr
= collector
== null?
null : collector
.getTitleCache();
295 result
= CdmUtils
.concat(", ", result
, collectorStr
);
298 TimePeriod gatheringPeriod
= gatheringEvent
.getTimeperiod();
299 result
= CdmUtils
.concat(", ", result
, (gatheringPeriod
== null?
null : gatheringPeriod
.toString()));
302 String strCountry
= null;
303 NamedArea country
= gatheringEvent
.getCountry();
304 Representation repCountry
= country
== null ?
null : country
.getRepresentation(Language
.DEFAULT());
305 strCountry
= repCountry
== null ?
null: repCountry
.getLabel();
306 result
= CdmUtils
.concat(", ", result
, strCountry
);
309 LanguageString locality
= gatheringEvent
.getLocality();
310 if (locality
!= null) {
311 result
= CdmUtils
.concat(", ", result
, locality
.getText());
316 if (isNotBlank(gatheringEvent
.getAbsoluteElevationText())){
317 elevationStr
= gatheringEvent
.getAbsoluteElevationText();
319 String text
= gatheringEvent
.getAbsoluteElevationText();
320 Integer min
= gatheringEvent
.getAbsoluteElevation();
321 Integer max
= gatheringEvent
.getAbsoluteElevationMax();
322 elevationStr
= DerivedUnitFacade
.distanceString(min
, max
, text
, METER
);
324 if (isNotBlank(elevationStr
)){
325 result
= CdmUtils
.concat(", " , result
, ALTITUDE_PREFIX
);
326 result
+= elevationStr
;
330 if (gatheringEvent
.getExactLocation() != null){
331 String exactLocation
= gatheringEvent
.getExactLocation().toSexagesimalString(false, false);
332 result
= CdmUtils
.concat(", ", result
, exactLocation
);
338 private static String
getCache(DeterminationEvent detEvent
) {
340 String taxonStr
= null;
341 TaxonName taxonName
= detEvent
.getTaxonName();
342 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
343 if (taxonName
!= null){
344 taxonStr
= taxonName
.getTitleCache();
346 if (isBlank(taxonStr
) && taxon
!= null){
347 taxonStr
= taxon
.getTitleCache();
349 if (isBlank(taxonStr
)){
350 taxonStr
= "no or unlabled taxon";
354 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
357 unitStr
= unit
.getTitleCache();
358 if (isBlank(unitStr
)){
359 unitStr
= "Unlabled unit";
365 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
370 private static String
getCache(TaxonNode taxonNode
) {
372 Classification classification
= taxonNode
.getClassification();
373 if (classification
!= null){
374 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
375 result
= CdmUtils
.concat("" , result
, classificationStr
);
376 if (isBlank(result
)){
377 result
= classification
.toString();
381 TaxonNode parentNode
= taxonNode
.getParent();
382 if (parentNode
== null){
383 parentStr
= "no parent";
385 Taxon parentTaxon
= parentNode
.getTaxon();
386 if (parentTaxon
== null){
387 parentStr
= "no parent taxon";
389 TaxonName parentName
= parentTaxon
.getName();
390 if (parentName
== null){
391 parentStr
= "child of " + parentTaxon
.getTitleCache();
393 parentStr
= "child of " + parentName
.getTitleCache();
397 result
= CdmUtils
.concat(": ", result
, parentStr
);
402 private static String
getCache(TypeDesignationBase
<?
> designation
) {
403 designation
= CdmBase
.deproxy(designation
);
405 String fromString
= null;
406 Set
<TaxonName
> from
= designation
.getTypifiedNames();
408 for (TaxonName name
: from
){
409 fromString
= CdmUtils
.concat(",", fromString
, name
.getTitleCache());
413 IdentifiableEntity
<?
> to
= null;
415 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
416 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
417 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
418 to
= ((NameTypeDesignation
)designation
).getTypeName();
419 }else if (designation
.isInstanceOf(TextualTypeDesignation
.class)){
420 toStr
= ((TextualTypeDesignation
)designation
).getPreferredText(CdmStore
.getDefaultLanguage());
422 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
424 toStr
= to
== null? toStr
: to
.getTitleCache();
426 String typeLabel
= null;
427 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
429 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
430 if (typeRepr
!= null){
431 typeLabel
= typeRepr
.getAbbreviatedLabel();
433 if (isBlank(typeLabel
) && typeRepr
!= null){
434 typeLabel
= typeRepr
.getLabel();
436 if (isBlank(typeLabel
) ){
437 typeLabel
= status
.getSymbol();
439 if (isBlank(typeLabel
)){
440 typeLabel
= status
.getTitleCache();
443 if (isBlank(typeLabel
)){
447 String result
= CdmUtils
.concat(" ", new String
[]{fromString
, typeLabel
, toStr
});
451 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
452 rel
= CdmBase
.deproxy(rel
);
453 RelationshipTermBase
<?
> type
= rel
.getType();
454 IdentifiableEntity
<?
> from
;
455 IdentifiableEntity
<?
> to
;
456 if (rel
.isInstanceOf(NameRelationship
.class)){
457 from
= ((NameRelationship
)rel
).getFromName();
458 to
= ((NameRelationship
)rel
).getToName();
459 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
460 from
= ((HybridRelationship
)rel
).getParentName();
461 to
= ((HybridRelationship
)rel
).getHybridName();
462 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
463 from
= ((TaxonRelationship
)rel
).getFromTaxon();
464 to
= ((TaxonRelationship
)rel
).getToTaxon();
467 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
468 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
469 fromMethod
.setAccessible(true);
470 toMethod
.setAccessible(true);
471 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
472 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
473 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
474 | IllegalArgumentException
| InvocationTargetException e
) {
475 throw new RuntimeException(e
);
478 String typeLabel
= null;
480 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
481 if (typeRepr
!= null){
482 typeLabel
= typeRepr
.getAbbreviatedLabel();
484 if (isBlank(typeLabel
) && typeRepr
!= null){
485 typeLabel
= typeRepr
.getLabel();
487 if (isBlank(typeLabel
) ){
488 typeLabel
= type
.getSymbol();
490 if (isBlank(typeLabel
)){
491 typeLabel
= type
.getTitleCache();
494 if (isBlank(typeLabel
)){
497 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
498 typeLabel
, to
== null?
null : to
.getTitleCache()});
503 private static String
getCache(HomotypicalGroup hg
) {
505 for (TaxonName tnb
: hg
.getTypifiedNames()){
506 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
508 if (isBlank(result
)){
509 result
= "No typified names";
514 private static String
getCache(KeyStatement ks
) {
517 result
= "KeyStatement";
522 public static String
getObjectClassname(Object element
) {
523 return element
.getClass().getSimpleName();
526 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
527 String result
= null;
528 if(element
.getFeatureNode() != null && element
.getFeatureNode().getTerm() != null){
529 result
= element
.getFeatureNode().getTerm().getLabel(CdmStore
.getDefaultLanguage());
531 return "No label set";
534 result
= element
.getFeatureNode().getTerm().getLabel();
539 public static String
getQuantitativeDataText(QuantitativeData element
) {
540 QuantitativeDataFormatter formatter
= new QuantitativeDataFormatter(null, null);
541 String label
= formatter
.doFormat(element
);
546 public static String
getCategoricalDataText(CategoricalData element
) {
547 TextData textData
= categoricalDescriptionBuilder
.build(element
, getLanguageList());
549 return textData
.getText(CdmStore
.getDefaultLanguage());
552 private static List
<Language
> getLanguageList(){
553 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
556 private static DescriptionBuilder
<QuantitativeData
> quantitativeDescriptionBuilder
= new DefaultQuantitativeDescriptionBuilder();
557 private static DescriptionBuilder
<CategoricalData
> categoricalDescriptionBuilder
= new DefaultCategoricalDescriptionBuilder();
558 public static final String NO_LABEL_STRING
= "[no label]";
561 public static String
getDistributionText(Distribution element
) {
563 String text
= "EMPTY";
565 Distribution distribution
= element
;
567 NamedArea area
= distribution
.getArea();
570 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
572 PresenceAbsenceTerm status
= distribution
.getStatus();
574 if (status
!= null) {
575 text
+= ", " + status
.getLabel();
577 text
+= ", NO STATUS";
583 public static String
getImageText(Media media
) {
584 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
586 return title
.getText();
591 public static String
getElementText(TextData element
) {
593 if(element
.getFeature().equals(Feature
.CITATION())){
595 for(DescriptionElementSource source
: element
.getSources()){
596 if(source
.getCitation() != null){
597 text
+= source
.getCitation().getTitleCache();
599 if(source
.getNameUsedInSource() != null){
600 text
+= " [ " + source
.getNameUsedInSource().getTitleCache() + " ]";
604 text
= "No sources provided";
607 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
608 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
609 text
= languageString
!= null ? languageString
.getText() : null;
611 return isBlank(text
) ?
"No text provided" : text
;
614 public static String
getTaxonInteractionText(TaxonInteraction element
) {
616 Taxon taxon2
= element
.getTaxon2();
617 if(taxon2
!= null && taxon2
.getName() != null){
618 text
= taxon2
.getName().getTitleCache();
620 text
= "No taxon chosen";
626 public static String
getCommonNameText(CommonTaxonName commonName
) {
627 String name
= commonName
.getName();
628 if (name
== null || name
.length() == 0) {
629 name
= "No name provided";
631 Language language
= commonName
.getLanguage();
632 if (language
== null) {
633 name
+= " (No language provided)";
635 name
+= " (" + language
.getLabel(CdmStore
.getDefaultLanguage()) + ")";
640 public static String
getDescriptionText(DescriptionBase element
) {
641 String text
= element
.getTitleCache();
642 if (text
== null || text
.length() == 0) {
643 text
= "No label provided";
649 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
650 SpecimenOrObservationBase
<?
> derivedUnit
= element
.getAssociatedSpecimenOrObservation();
651 if(derivedUnit
!= null){
652 return derivedUnit
.getTitleCache();
654 return "No unit chosen";
657 public static String
getLabel(Object element
){
658 if (element
instanceof FeatureNodeContainer
){
659 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
661 else if (element
instanceof DescriptionBase
) {
662 return getDescriptionText((DescriptionBase
<?
>) element
);
664 else if(element
instanceof CategoricalData
){
665 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
666 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
667 categoricalDataText
= NO_LABEL_STRING
;
669 return categoricalDataText
;
671 else if (element
instanceof CommonTaxonName
) {
672 return getCommonNameText((CommonTaxonName
) element
);
674 else if (element
instanceof Distribution
) {
675 return getDistributionText((Distribution
) element
);
677 else if (element
instanceof IndividualsAssociation
) {
678 return getIndividualsAssociationText((IndividualsAssociation
) element
);
680 else if (element
instanceof QuantitativeData
) {
681 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
682 if(quantitativeDataText
==null || quantitativeDataText
.isEmpty()){
683 quantitativeDataText
= NO_LABEL_STRING
;
685 return quantitativeDataText
;
687 else if (element
instanceof TaxonInteraction
) {
688 return getTaxonInteractionText((TaxonInteraction
) element
);
690 else if (element
instanceof TextData
) {
691 return getElementText((TextData
) element
);
693 else if (element
instanceof TemporalData
) {
694 return getTemporalDataText((TemporalData
) element
);
697 return element
.toString();
701 private static String
getTemporalDataText(TemporalData element
) {
702 ExtendedTimePeriod period
= element
.getPeriod();
703 Partial end
= period
.getEnd()==null?
null:period
.getEnd().without(DateTimeFieldType
.year());
704 Partial extremeEnd
= period
.getExtremeEnd()== null?
null: period
.getExtremeEnd().without(DateTimeFieldType
.year());
706 Partial start
= period
.getStart()==null?
null: period
.getStart().without(DateTimeFieldType
.year());
707 Partial extremeStart
= period
.getExtremeStart()==null?
null : period
.getExtremeStart().without(DateTimeFieldType
.year());
710 DateTimeFormatter formatter
= ExtendedTimePeriodPartialFormatter
.NewInstance();
711 if (extremeStart
!= null){
712 result
= "(" + extremeStart
.toString(formatter
) +"-)";
715 result
+= start
.toString(formatter
);
718 result
+= "-" + end
.toString(formatter
);
721 if (extremeEnd
!= null){
722 result
+= "(-" + extremeEnd
.toString(formatter
)+")";
726 // return element.getPeriod().toString();
729 private static boolean isNotBlank(String str
){
730 return StringUtils
.isNotBlank(str
);
733 private static boolean isBlank(String str
){
734 return StringUtils
.isBlank(str
);