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
;
21 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
22 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
23 import eu
.etaxonomy
.cdm
.format
.description
.DefaultCategoricalDescriptionBuilder
;
24 import eu
.etaxonomy
.cdm
.format
.description
.DefaultQuantitativeDescriptionBuilder
;
25 import eu
.etaxonomy
.cdm
.format
.description
.DescriptionBuilder
;
26 import eu
.etaxonomy
.cdm
.format
.description
.QuantitativeDataFormatter
;
27 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
29 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
30 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
31 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
32 import eu
.etaxonomy
.cdm
.model
.common
.LanguageStringBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
34 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
35 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
37 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
38 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
39 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
40 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
41 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
42 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
43 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
44 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
45 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
46 import eu
.etaxonomy
.cdm
.model
.description
.KeyStatement
;
47 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
48 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
49 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
50 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
51 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
52 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
53 import eu
.etaxonomy
.cdm
.model
.description
.TemporalData
;
54 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
55 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
56 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
57 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
58 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
59 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
60 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
61 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
62 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
63 import eu
.etaxonomy
.cdm
.model
.name
.TextualTypeDesignation
;
64 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
65 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatusBase
;
66 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
67 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
68 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
69 import eu
.etaxonomy
.cdm
.model
.permission
.Group
;
70 import eu
.etaxonomy
.cdm
.model
.permission
.User
;
71 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceBase
;
72 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
73 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
74 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
75 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
76 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
77 import eu
.etaxonomy
.cdm
.model
.term
.Representation
;
78 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
81 * <p>DescriptionHelper class.</p>
86 public class DescriptionHelper
{
89 * Returns whatever the element's title cache equivalent is,
90 * depending on its class.
92 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
93 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
94 * @return a {@link java.lang.String} object.
96 public static String
getCache(DescriptionElementBase element
,
99 String mainElementLabel
= null;
100 DescriptionBase
<?
> descr
= element
.getInDescription();
101 descr
= CdmBase
.deproxy(descr
, DescriptionBase
.class);
104 if (descr
.isInstanceOf(TaxonDescription
.class)){
105 Taxon taxon
= CdmBase
.deproxy(descr
, TaxonDescription
.class).getTaxon();
107 mainElementLabel
= taxon
.getTitleCache();
109 }else if (descr
.isInstanceOf(SpecimenDescription
.class)){
110 SpecimenOrObservationBase
<?
> specimen
= CdmBase
.deproxy(descr
, SpecimenDescription
.class).getDescribedSpecimenOrObservation();
111 if (specimen
!= null){
112 mainElementLabel
= specimen
.getTitleCache();
114 }else if (descr
.isInstanceOf(TaxonNameDescription
.class)){
115 TaxonName name
= CdmBase
.deproxy(descr
, TaxonNameDescription
.class).getTaxonName();
117 mainElementLabel
= name
.getTitleCache();
124 if (element
instanceof TextData
) {
125 //cache = ((TextData) element).getText(language);
128 if (element
instanceof CommonTaxonName
) {
129 cache
= ((CommonTaxonName
) element
).getName();
131 if (element
instanceof TaxonInteraction
) {
132 Taxon taxon2
= ((TaxonInteraction
) element
).getTaxon2();
133 if(taxon2
!= null && taxon2
.getName() != null){
134 cache
= taxon2
.getName().getTitleCache();
136 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());
213 * <p>getObjectDescription</p>
215 * @param element a {@link java.lang.Object} object.
216 * @return a {@link java.lang.String} object.
218 public static String
getObjectDescription(Object element
) {
219 String resultString
= null;
220 if (element
instanceof IdentifiableEntity
) {
222 resultString
= ((IdentifiableEntity
) element
).getTitleCache();
223 }catch(LazyInitializationException e
){
224 String result
= "No Session to initialize title cache for IdentifiableEntity";
225 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
226 resultString
= "TODO: " + result
;
228 }else if (element
instanceof OriginalSourceBase
) {
230 OriginalSourceBase
<?
> originalSource
= (OriginalSourceBase
<?
>) element
;
231 // ISourceable sourcedObject = originalSource.getSourcedObj();
232 //due to #5743 the bidirectionality for sourced object had to be removed
233 String sourceObjectTitle
= "sourced object data not available (#5743)";
234 // if(sourcedObject instanceof IIdentifiableEntity){
235 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
236 // }else if(sourcedObject instanceof DescriptionElementBase){
237 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
239 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
242 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
243 }catch(LazyInitializationException e
){
244 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
245 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
246 resultString
= "TODO: " + result
;
248 }else if (element
instanceof LanguageStringBase
) {
249 resultString
= ((LanguageStringBase
) element
).getText();
250 }else if (element
instanceof DescriptionElementBase
) {
251 resultString
= getCache((DescriptionElementBase
) element
);
252 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
253 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
254 }else if (element
instanceof TypeDesignationBase
<?
>) {
255 resultString
= getCache((TypeDesignationBase
<?
>) element
);
256 }else if (element
instanceof HomotypicalGroup
) {
257 resultString
= getCache((HomotypicalGroup
) element
);
258 }else if (element
instanceof TaxonNode
) {
259 resultString
= getCache((TaxonNode
) element
);
260 }else if (element
instanceof DeterminationEvent
) {
261 resultString
= getCache((DeterminationEvent
) element
);
262 }else if (element
instanceof GatheringEvent
){
263 resultString
= getCache((GatheringEvent
) element
);
264 }else if (element
instanceof Marker
) {
265 Marker marker
= (Marker
) element
;
266 MarkerType type
= marker
.getMarkerType();
267 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
268 }else if (element
instanceof User
) {
269 User user
= (User
) element
;
270 resultString
= user
.getUsername();
271 }else if (element
instanceof Group
) {
272 Group group
= (Group
) element
;
273 resultString
= group
.getName();
274 }else if (element
instanceof KeyStatement
) {
275 KeyStatement keyStatement
= (KeyStatement
) element
;
276 resultString
= getCache(keyStatement
);
278 // TODO write return texts for HomotypicalGroup, etc.
279 resultString
= element
.toString();
282 if (resultString
== null){
283 resultString
= element
.toString();
288 private static String
getCache(GatheringEvent gatheringEvent
){
289 String ALTITUDE_PREFIX
= "alt. ";
290 final String METER
= "m";
295 AgentBase
<?
> collector
= CdmBase
.deproxy(gatheringEvent
.getCollector());
296 String collectorStr
= collector
== null?
null : collector
.getTitleCache();
297 result
= CdmUtils
.concat(", ", result
, collectorStr
);
300 TimePeriod gatheringPeriod
= gatheringEvent
.getTimeperiod();
301 result
= CdmUtils
.concat(", ", result
, (gatheringPeriod
== null?
null : gatheringPeriod
.toString()));
304 String strCountry
= null;
305 NamedArea country
= gatheringEvent
.getCountry();
306 Representation repCountry
= country
== null ?
null : country
.getRepresentation(Language
.DEFAULT());
307 strCountry
= repCountry
== null ?
null: repCountry
.getLabel();
308 result
= CdmUtils
.concat(", ", result
, strCountry
);
311 LanguageString locality
= gatheringEvent
.getLocality();
312 if (locality
!= null) {
313 result
= CdmUtils
.concat(", ", result
, locality
.getText());
318 if (isNotBlank(gatheringEvent
.getAbsoluteElevationText())){
319 elevationStr
= gatheringEvent
.getAbsoluteElevationText();
321 String text
= gatheringEvent
.getAbsoluteElevationText();
322 Integer min
= gatheringEvent
.getAbsoluteElevation();
323 Integer max
= gatheringEvent
.getAbsoluteElevationMax();
324 elevationStr
= DerivedUnitFacade
.distanceString(min
, max
, text
, METER
);
326 if (isNotBlank(elevationStr
)){
327 result
= CdmUtils
.concat(", " , result
, ALTITUDE_PREFIX
);
328 result
+= elevationStr
;
332 if (gatheringEvent
.getExactLocation() != null){
333 String exactLocation
= gatheringEvent
.getExactLocation().toSexagesimalString(false, false);
334 result
= CdmUtils
.concat(", ", result
, exactLocation
);
341 private static String
getCache(DeterminationEvent detEvent
) {
343 String taxonStr
= null;
344 TaxonName taxonName
= detEvent
.getTaxonName();
345 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
346 if (taxonName
!= null){
347 taxonStr
= taxonName
.getTitleCache();
349 if (isBlank(taxonStr
) && taxon
!= null){
350 taxonStr
= taxon
.getTitleCache();
352 if (isBlank(taxonStr
)){
353 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";
527 * <p>getObjectClassname</p>
529 * @param element a {@link java.lang.Object} object.
530 * @return a {@link java.lang.String} object.
532 public static String
getObjectClassname(Object element
) {
533 return element
.getClass().getSimpleName();
537 * <p>getFeatureNodeContainerText</p>
539 * @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
540 * @return a {@link java.lang.String} object.
542 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
543 String result
= null;
544 if(element
.getFeatureNode() != null && element
.getFeatureNode().getTerm() != null){
545 result
= element
.getFeatureNode().getTerm().getLabel(CdmStore
.getDefaultLanguage());
547 return "No label set";
550 result
= element
.getFeatureNode().getTerm().getLabel();
556 * <p>getQuantitativeDataText</p>
558 * @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
559 * @return a {@link java.lang.String} object.
561 public static String
getQuantitativeDataText(QuantitativeData element
) {
562 QuantitativeDataFormatter formatter
= new QuantitativeDataFormatter(null, null);
563 String label
= formatter
.doFormat(element
);
569 * <p>getCategoricalDataText</p>
571 * @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
572 * @return a {@link java.lang.String} object.
574 public static String
getCategoricalDataText(CategoricalData element
) {
575 TextData textData
= categoricalDescriptionBuilder
.build(element
, getLanguageList());
577 return textData
.getText(CdmStore
.getDefaultLanguage());
580 private static List
<Language
> getLanguageList(){
581 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
584 private static DescriptionBuilder
<QuantitativeData
> quantitativeDescriptionBuilder
= new DefaultQuantitativeDescriptionBuilder();
585 private static DescriptionBuilder
<CategoricalData
> categoricalDescriptionBuilder
= new DefaultCategoricalDescriptionBuilder();
586 public static final String NO_LABEL_STRING
= "[no label]";
590 * <p>getDistributionText</p>
592 * @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
593 * @return a {@link java.lang.String} object.
595 public static String
getDistributionText(Distribution element
) {
597 String text
= "EMPTY";
599 Distribution distribution
= element
;
601 NamedArea area
= distribution
.getArea();
604 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
606 PresenceAbsenceTerm status
= distribution
.getStatus();
608 if (status
!= null) {
609 text
+= ", " + status
.getLabel();
611 text
+= ", NO STATUS";
618 * <p>getImageText</p>
620 * @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
621 * @return a {@link java.lang.String} object.
623 public static String
getImageText(Media media
) {
624 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
626 return title
.getText();
634 * <p>getElementText</p>
636 * @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
637 * @return a {@link java.lang.String} object.
639 public static String
getElementText(TextData element
) {
641 if(element
.getFeature().equals(Feature
.CITATION())){
643 for(DescriptionElementSource source
: element
.getSources()){
644 if(source
.getCitation() != null){
645 text
+= source
.getCitation().getTitleCache();
647 if(source
.getNameUsedInSource() != null){
648 text
+= " [ " + source
.getNameUsedInSource().getTitleCache() + " ]";
652 text
= "No sources provided";
655 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
656 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
657 text
= languageString
!= null ? languageString
.getText() : null;
659 return isBlank(text
) ?
"No text provided" : text
;
663 * <p>getTaxonInteractionText</p>
665 * @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
666 * @return a {@link java.lang.String} object.
668 public static String
getTaxonInteractionText(TaxonInteraction element
) {
670 Taxon taxon2
= element
.getTaxon2();
671 if(taxon2
!= null && taxon2
.getName() != null){
672 text
= taxon2
.getName().getTitleCache();
674 text
= "No taxon chosen";
681 * <p>getCommonNameText</p>
683 * @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
684 * @return a {@link java.lang.String} object.
686 public static String
getCommonNameText(CommonTaxonName commonName
) {
687 String name
= commonName
.getName();
688 if (name
== null || name
.length() == 0) {
689 name
= "No name provided";
691 Language language
= commonName
.getLanguage();
692 if (language
== null) {
693 name
+= " (No language provided)";
695 name
+= " (" + language
.getLabel(CdmStore
.getDefaultLanguage()) + ")";
701 * <p>getDescriptionText</p>
703 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
704 * @return a {@link java.lang.String} object.
706 public static String
getDescriptionText(DescriptionBase element
) {
707 String text
= element
.getTitleCache();
708 if (text
== null || text
.length() == 0) {
709 text
= "No label provided";
716 * <p>getIndividualsAssociationText</p>
718 * @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
719 * @return a {@link java.lang.String} object.
721 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
722 SpecimenOrObservationBase derivedUnit
= element
.getAssociatedSpecimenOrObservation();
723 if(derivedUnit
!= null){
724 return derivedUnit
.getTitleCache();
726 return "No unit chosen";
732 * @param element a {@link java.lang.Object} object.
733 * @return a {@link java.lang.String} object.
735 public static String
getLabel(Object element
){
736 if (element
instanceof FeatureNodeContainer
){
737 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
739 else if (element
instanceof DescriptionBase
) {
740 return getDescriptionText((DescriptionBase
) element
);
742 else if(element
instanceof CategoricalData
){
743 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
744 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
745 categoricalDataText
= NO_LABEL_STRING
;
747 return categoricalDataText
;
749 else if (element
instanceof CommonTaxonName
) {
750 return getCommonNameText((CommonTaxonName
) element
);
752 else if (element
instanceof Distribution
) {
753 return getDistributionText((Distribution
) element
);
755 else if (element
instanceof IndividualsAssociation
) {
756 return getIndividualsAssociationText((IndividualsAssociation
) element
);
758 else if (element
instanceof QuantitativeData
) {
759 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
760 if(quantitativeDataText
==null || quantitativeDataText
.isEmpty()){
761 quantitativeDataText
= NO_LABEL_STRING
;
763 return quantitativeDataText
;
765 else if (element
instanceof TaxonInteraction
) {
766 return getTaxonInteractionText((TaxonInteraction
) element
);
768 else if (element
instanceof TextData
) {
769 return getElementText((TextData
) element
);
771 else if (element
instanceof TemporalData
) {
772 return getTemporalDataText((TemporalData
) element
);
775 return element
.toString();
783 private static String
getTemporalDataText(TemporalData element
) {
785 return element
.getPeriod().toString();
788 private static boolean isNotBlank(String str
){
789 return StringUtils
.isNotBlank(str
);
792 private static boolean isBlank(String str
){
793 return StringUtils
.isBlank(str
);