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());
218 * <p>getObjectDescription</p>
220 * @param element a {@link java.lang.Object} object.
221 * @return a {@link java.lang.String} object.
223 public static String
getObjectDescription(Object element
) {
224 String resultString
= null;
225 if (element
instanceof IdentifiableEntity
) {
227 resultString
= ((IdentifiableEntity
) element
).getTitleCache();
228 }catch(LazyInitializationException e
){
229 String result
= "No Session to initialize title cache for IdentifiableEntity";
230 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
231 resultString
= "TODO: " + result
;
233 }else if (element
instanceof OriginalSourceBase
) {
235 OriginalSourceBase
<?
> originalSource
= (OriginalSourceBase
<?
>) element
;
236 // ISourceable sourcedObject = originalSource.getSourcedObj();
237 //due to #5743 the bidirectionality for sourced object had to be removed
238 String sourceObjectTitle
= "sourced object data not available (#5743)";
239 // if(sourcedObject instanceof IIdentifiableEntity){
240 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
241 // }else if(sourcedObject instanceof DescriptionElementBase){
242 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
244 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
247 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
248 }catch(LazyInitializationException e
){
249 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
250 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
251 resultString
= "TODO: " + result
;
253 }else if (element
instanceof LanguageStringBase
) {
254 resultString
= ((LanguageStringBase
) element
).getText();
255 }else if (element
instanceof DescriptionElementBase
) {
256 resultString
= getCache((DescriptionElementBase
) element
);
257 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
258 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
259 }else if (element
instanceof TypeDesignationBase
<?
>) {
260 resultString
= getCache((TypeDesignationBase
<?
>) element
);
261 }else if (element
instanceof HomotypicalGroup
) {
262 resultString
= getCache((HomotypicalGroup
) element
);
263 }else if (element
instanceof TaxonNode
) {
264 resultString
= getCache((TaxonNode
) element
);
265 }else if (element
instanceof DeterminationEvent
) {
266 resultString
= getCache((DeterminationEvent
) element
);
267 }else if (element
instanceof GatheringEvent
){
268 resultString
= getCache((GatheringEvent
) element
);
269 }else if (element
instanceof Marker
) {
270 Marker marker
= (Marker
) element
;
271 MarkerType type
= marker
.getMarkerType();
272 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
273 }else if (element
instanceof User
) {
274 User user
= (User
) element
;
275 resultString
= user
.getUsername();
276 }else if (element
instanceof Group
) {
277 Group group
= (Group
) element
;
278 resultString
= group
.getName();
279 }else if (element
instanceof KeyStatement
) {
280 KeyStatement keyStatement
= (KeyStatement
) element
;
281 resultString
= getCache(keyStatement
);
283 // TODO write return texts for HomotypicalGroup, etc.
284 resultString
= element
.toString();
287 if (resultString
== null){
288 resultString
= element
.toString();
293 private static String
getCache(GatheringEvent gatheringEvent
){
294 String ALTITUDE_PREFIX
= "alt. ";
295 final String METER
= "m";
300 AgentBase
<?
> collector
= CdmBase
.deproxy(gatheringEvent
.getCollector());
301 String collectorStr
= collector
== null?
null : collector
.getTitleCache();
302 result
= CdmUtils
.concat(", ", result
, collectorStr
);
305 TimePeriod gatheringPeriod
= gatheringEvent
.getTimeperiod();
306 result
= CdmUtils
.concat(", ", result
, (gatheringPeriod
== null?
null : gatheringPeriod
.toString()));
309 String strCountry
= null;
310 NamedArea country
= gatheringEvent
.getCountry();
311 Representation repCountry
= country
== null ?
null : country
.getRepresentation(Language
.DEFAULT());
312 strCountry
= repCountry
== null ?
null: repCountry
.getLabel();
313 result
= CdmUtils
.concat(", ", result
, strCountry
);
316 LanguageString locality
= gatheringEvent
.getLocality();
317 if (locality
!= null) {
318 result
= CdmUtils
.concat(", ", result
, locality
.getText());
323 if (isNotBlank(gatheringEvent
.getAbsoluteElevationText())){
324 elevationStr
= gatheringEvent
.getAbsoluteElevationText();
326 String text
= gatheringEvent
.getAbsoluteElevationText();
327 Integer min
= gatheringEvent
.getAbsoluteElevation();
328 Integer max
= gatheringEvent
.getAbsoluteElevationMax();
329 elevationStr
= DerivedUnitFacade
.distanceString(min
, max
, text
, METER
);
331 if (isNotBlank(elevationStr
)){
332 result
= CdmUtils
.concat(", " , result
, ALTITUDE_PREFIX
);
333 result
+= elevationStr
;
337 if (gatheringEvent
.getExactLocation() != null){
338 String exactLocation
= gatheringEvent
.getExactLocation().toSexagesimalString(false, false);
339 result
= CdmUtils
.concat(", ", result
, exactLocation
);
346 private static String
getCache(DeterminationEvent detEvent
) {
348 String taxonStr
= null;
349 TaxonName taxonName
= detEvent
.getTaxonName();
350 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
351 if (taxonName
!= null){
352 taxonStr
= taxonName
.getTitleCache();
354 if (isBlank(taxonStr
) && taxon
!= null){
355 taxonStr
= taxon
.getTitleCache();
357 if (isBlank(taxonStr
)){
358 taxonStr
= "no or unlabled taxon";
363 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
366 unitStr
= unit
.getTitleCache();
367 if (isBlank(unitStr
)){
368 unitStr
= "Unlabled unit";
374 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
379 private static String
getCache(TaxonNode taxonNode
) {
381 Classification classification
= taxonNode
.getClassification();
382 if (classification
!= null){
383 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
384 result
= CdmUtils
.concat("" , result
, classificationStr
);
385 if (isBlank(result
)){
386 result
= classification
.toString();
390 TaxonNode parentNode
= taxonNode
.getParent();
391 if (parentNode
== null){
392 parentStr
= "no parent";
394 Taxon parentTaxon
= parentNode
.getTaxon();
395 if (parentTaxon
== null){
396 parentStr
= "no parent taxon";
398 TaxonName parentName
= parentTaxon
.getName();
399 if (parentName
== null){
400 parentStr
= "child of " + parentTaxon
.getTitleCache();
402 parentStr
= "child of " + parentName
.getTitleCache();
406 result
= CdmUtils
.concat(": ", result
, parentStr
);
411 private static String
getCache(TypeDesignationBase
<?
> designation
) {
412 designation
= CdmBase
.deproxy(designation
);
414 String fromString
= null;
415 Set
<TaxonName
> from
= designation
.getTypifiedNames();
417 for (TaxonName name
: from
){
418 fromString
= CdmUtils
.concat(",", fromString
, name
.getTitleCache());
422 IdentifiableEntity
<?
> to
= null;
424 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
425 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
426 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
427 to
= ((NameTypeDesignation
)designation
).getTypeName();
428 }else if (designation
.isInstanceOf(TextualTypeDesignation
.class)){
429 toStr
= ((TextualTypeDesignation
)designation
).getPreferredText(CdmStore
.getDefaultLanguage());
431 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
433 toStr
= to
== null? toStr
: to
.getTitleCache();
435 String typeLabel
= null;
436 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
438 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
439 if (typeRepr
!= null){
440 typeLabel
= typeRepr
.getAbbreviatedLabel();
442 if (isBlank(typeLabel
) && typeRepr
!= null){
443 typeLabel
= typeRepr
.getLabel();
445 if (isBlank(typeLabel
) ){
446 typeLabel
= status
.getSymbol();
448 if (isBlank(typeLabel
)){
449 typeLabel
= status
.getTitleCache();
452 if (isBlank(typeLabel
)){
456 String result
= CdmUtils
.concat(" ", new String
[]{fromString
, typeLabel
, toStr
});
460 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
461 rel
= CdmBase
.deproxy(rel
);
462 RelationshipTermBase
<?
> type
= rel
.getType();
463 IdentifiableEntity
<?
> from
;
464 IdentifiableEntity
<?
> to
;
465 if (rel
.isInstanceOf(NameRelationship
.class)){
466 from
= ((NameRelationship
)rel
).getFromName();
467 to
= ((NameRelationship
)rel
).getToName();
468 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
469 from
= ((HybridRelationship
)rel
).getParentName();
470 to
= ((HybridRelationship
)rel
).getHybridName();
471 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
472 from
= ((TaxonRelationship
)rel
).getFromTaxon();
473 to
= ((TaxonRelationship
)rel
).getToTaxon();
476 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
477 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
478 fromMethod
.setAccessible(true);
479 toMethod
.setAccessible(true);
480 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
481 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
482 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
483 | IllegalArgumentException
| InvocationTargetException e
) {
484 throw new RuntimeException(e
);
487 String typeLabel
= null;
489 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
490 if (typeRepr
!= null){
491 typeLabel
= typeRepr
.getAbbreviatedLabel();
493 if (isBlank(typeLabel
) && typeRepr
!= null){
494 typeLabel
= typeRepr
.getLabel();
496 if (isBlank(typeLabel
) ){
497 typeLabel
= type
.getSymbol();
499 if (isBlank(typeLabel
)){
500 typeLabel
= type
.getTitleCache();
503 if (isBlank(typeLabel
)){
506 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
507 typeLabel
, to
== null?
null : to
.getTitleCache()});
512 private static String
getCache(HomotypicalGroup hg
) {
514 for (TaxonName tnb
: hg
.getTypifiedNames()){
515 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
517 if (isBlank(result
)){
518 result
= "No typified names";
523 private static String
getCache(KeyStatement ks
) {
526 result
= "KeyStatement";
532 * <p>getObjectClassname</p>
534 * @param element a {@link java.lang.Object} object.
535 * @return a {@link java.lang.String} object.
537 public static String
getObjectClassname(Object element
) {
538 return element
.getClass().getSimpleName();
542 * <p>getFeatureNodeContainerText</p>
544 * @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
545 * @return a {@link java.lang.String} object.
547 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
548 String result
= null;
549 if(element
.getFeatureNode() != null && element
.getFeatureNode().getTerm() != null){
550 result
= element
.getFeatureNode().getTerm().getLabel(CdmStore
.getDefaultLanguage());
552 return "No label set";
555 result
= element
.getFeatureNode().getTerm().getLabel();
561 * <p>getQuantitativeDataText</p>
563 * @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
564 * @return a {@link java.lang.String} object.
566 public static String
getQuantitativeDataText(QuantitativeData element
) {
567 QuantitativeDataFormatter formatter
= new QuantitativeDataFormatter(null, null);
568 String label
= formatter
.doFormat(element
);
574 * <p>getCategoricalDataText</p>
576 * @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
577 * @return a {@link java.lang.String} object.
579 public static String
getCategoricalDataText(CategoricalData element
) {
580 TextData textData
= categoricalDescriptionBuilder
.build(element
, getLanguageList());
582 return textData
.getText(CdmStore
.getDefaultLanguage());
585 private static List
<Language
> getLanguageList(){
586 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
589 private static DescriptionBuilder
<QuantitativeData
> quantitativeDescriptionBuilder
= new DefaultQuantitativeDescriptionBuilder();
590 private static DescriptionBuilder
<CategoricalData
> categoricalDescriptionBuilder
= new DefaultCategoricalDescriptionBuilder();
591 public static final String NO_LABEL_STRING
= "[no label]";
595 * <p>getDistributionText</p>
597 * @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
598 * @return a {@link java.lang.String} object.
600 public static String
getDistributionText(Distribution element
) {
602 String text
= "EMPTY";
604 Distribution distribution
= element
;
606 NamedArea area
= distribution
.getArea();
609 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
611 PresenceAbsenceTerm status
= distribution
.getStatus();
613 if (status
!= null) {
614 text
+= ", " + status
.getLabel();
616 text
+= ", NO STATUS";
623 * <p>getImageText</p>
625 * @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
626 * @return a {@link java.lang.String} object.
628 public static String
getImageText(Media media
) {
629 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
631 return title
.getText();
639 * <p>getElementText</p>
641 * @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
642 * @return a {@link java.lang.String} object.
644 public static String
getElementText(TextData element
) {
646 if(element
.getFeature().equals(Feature
.CITATION())){
648 for(DescriptionElementSource source
: element
.getSources()){
649 if(source
.getCitation() != null){
650 text
+= source
.getCitation().getTitleCache();
652 if(source
.getNameUsedInSource() != null){
653 text
+= " [ " + source
.getNameUsedInSource().getTitleCache() + " ]";
657 text
= "No sources provided";
660 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
661 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
662 text
= languageString
!= null ? languageString
.getText() : null;
664 return isBlank(text
) ?
"No text provided" : text
;
668 * <p>getTaxonInteractionText</p>
670 * @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
671 * @return a {@link java.lang.String} object.
673 public static String
getTaxonInteractionText(TaxonInteraction element
) {
675 Taxon taxon2
= element
.getTaxon2();
676 if(taxon2
!= null && taxon2
.getName() != null){
677 text
= taxon2
.getName().getTitleCache();
679 text
= "No taxon chosen";
686 * <p>getCommonNameText</p>
688 * @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
689 * @return a {@link java.lang.String} object.
691 public static String
getCommonNameText(CommonTaxonName commonName
) {
692 String name
= commonName
.getName();
693 if (name
== null || name
.length() == 0) {
694 name
= "No name provided";
696 Language language
= commonName
.getLanguage();
697 if (language
== null) {
698 name
+= " (No language provided)";
700 name
+= " (" + language
.getLabel(CdmStore
.getDefaultLanguage()) + ")";
706 * <p>getDescriptionText</p>
708 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
709 * @return a {@link java.lang.String} object.
711 public static String
getDescriptionText(DescriptionBase element
) {
712 String text
= element
.getTitleCache();
713 if (text
== null || text
.length() == 0) {
714 text
= "No label provided";
721 * <p>getIndividualsAssociationText</p>
723 * @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
724 * @return a {@link java.lang.String} object.
726 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
727 SpecimenOrObservationBase derivedUnit
= element
.getAssociatedSpecimenOrObservation();
728 if(derivedUnit
!= null){
729 return derivedUnit
.getTitleCache();
731 return "No unit chosen";
737 * @param element a {@link java.lang.Object} object.
738 * @return a {@link java.lang.String} object.
740 public static String
getLabel(Object element
){
741 if (element
instanceof FeatureNodeContainer
){
742 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
744 else if (element
instanceof DescriptionBase
) {
745 return getDescriptionText((DescriptionBase
) element
);
747 else if(element
instanceof CategoricalData
){
748 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
749 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
750 categoricalDataText
= NO_LABEL_STRING
;
752 return categoricalDataText
;
754 else if (element
instanceof CommonTaxonName
) {
755 return getCommonNameText((CommonTaxonName
) element
);
757 else if (element
instanceof Distribution
) {
758 return getDistributionText((Distribution
) element
);
760 else if (element
instanceof IndividualsAssociation
) {
761 return getIndividualsAssociationText((IndividualsAssociation
) element
);
763 else if (element
instanceof QuantitativeData
) {
764 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
765 if(quantitativeDataText
==null || quantitativeDataText
.isEmpty()){
766 quantitativeDataText
= NO_LABEL_STRING
;
768 return quantitativeDataText
;
770 else if (element
instanceof TaxonInteraction
) {
771 return getTaxonInteractionText((TaxonInteraction
) element
);
773 else if (element
instanceof TextData
) {
774 return getElementText((TextData
) element
);
776 else if (element
instanceof TemporalData
) {
777 return getTemporalDataText((TemporalData
) element
);
780 return element
.toString();
788 private static String
getTemporalDataText(TemporalData element
) {
789 ExtendedTimePeriod period
= element
.getPeriod();
790 Partial end
= period
.getEnd()==null?
null:period
.getEnd().without(DateTimeFieldType
.year());
791 Partial extremeEnd
= period
.getExtremeEnd()== null?
null: period
.getExtremeEnd().without(DateTimeFieldType
.year());
793 Partial start
= period
.getStart()==null?
null: period
.getStart().without(DateTimeFieldType
.year());
794 Partial extremeStart
= period
.getExtremeStart()==null?
null : period
.getExtremeStart().without(DateTimeFieldType
.year());
797 DateTimeFormatter formatter
= ExtendedTimePeriodPartialFormatter
.NewInstance();
798 if (extremeStart
!= null){
799 result
= "(" + extremeStart
.toString(formatter
) +"-)";
802 result
+= start
.toString(formatter
);
805 result
+= "-" + end
.toString(formatter
);
808 if (extremeEnd
!= null){
809 result
+= "(-" + extremeEnd
.toString(formatter
)+")";
813 // return element.getPeriod().toString();
816 private static boolean isNotBlank(String str
){
817 return StringUtils
.isNotBlank(str
);
820 private static boolean isBlank(String str
){
821 return StringUtils
.isBlank(str
);