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
.api
.service
.DefaultCategoricalDescriptionBuilder
;
23 import eu
.etaxonomy
.cdm
.api
.service
.DefaultQuantitativeDescriptionBuilder
;
24 import eu
.etaxonomy
.cdm
.api
.service
.DescriptionBuilder
;
25 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
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
.OriginalSourceBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
37 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
38 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
39 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
40 import eu
.etaxonomy
.cdm
.model
.common
.User
;
41 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
42 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
43 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
44 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
45 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
46 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
47 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
48 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
49 import eu
.etaxonomy
.cdm
.model
.description
.KeyStatement
;
50 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
51 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
52 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
53 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
54 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
55 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
56 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
57 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
58 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
59 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
60 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
61 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
62 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
63 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
64 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
65 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
66 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatusBase
;
67 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
68 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
69 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
70 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
71 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
72 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
73 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
74 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
75 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
78 * <p>DescriptionHelper class.</p>
83 public class DescriptionHelper
{
86 * Returns whatever the element's title cache equivalent is,
87 * depending on its class.
89 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
90 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
91 * @return a {@link java.lang.String} object.
93 public static String
getCache(DescriptionElementBase element
,
96 String mainElementLabel
= null;
97 DescriptionBase
<?
> descr
= element
.getInDescription();
98 descr
= CdmBase
.deproxy(descr
, DescriptionBase
.class);
101 if (descr
.isInstanceOf(TaxonDescription
.class)){
102 Taxon taxon
= CdmBase
.deproxy(descr
, TaxonDescription
.class).getTaxon();
104 mainElementLabel
= taxon
.getTitleCache();
106 }else if (descr
.isInstanceOf(SpecimenDescription
.class)){
107 SpecimenOrObservationBase
<?
> specimen
= CdmBase
.deproxy(descr
, SpecimenDescription
.class).getDescribedSpecimenOrObservation();
108 if (specimen
!= null){
109 mainElementLabel
= specimen
.getTitleCache();
111 }else if (descr
.isInstanceOf(TaxonNameDescription
.class)){
112 TaxonName name
= CdmBase
.deproxy(descr
, TaxonNameDescription
.class).getTaxonName();
114 mainElementLabel
= name
.getTitleCache();
121 if (element
instanceof TextData
) {
122 //cache = ((TextData) element).getText(language);
125 if (element
instanceof CommonTaxonName
) {
126 cache
= ((CommonTaxonName
) element
).getName();
128 if (element
instanceof TaxonInteraction
) {
129 Taxon taxon2
= ((TaxonInteraction
) element
).getTaxon2();
130 if(taxon2
!= null && taxon2
.getName() != null){
131 cache
= taxon2
.getName().getTitleCache();
133 cache
= "No taxon chosen";
137 if (element
instanceof Distribution
) {
138 Distribution distribution
= (Distribution
) element
;
140 NamedArea area
= distribution
.getArea();
142 cache
= area
.getLabel();
144 PresenceAbsenceTerm status
= distribution
.getStatus();
146 cache
+= ", no status";
148 cache
+= ", " + status
.getLabel();
152 String result
= cache
== null ?
"" : cache
;
153 if (isNotBlank(mainElementLabel
)){
154 result
= CdmUtils
.concat(" ", result
, "(" + mainElementLabel
+ ")");
160 * Returns whatever the element's title cache equivalent is,
161 * depending on its class, using the default language.
163 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
164 * @return a {@link java.lang.String} object.
166 public static String
getCache(DescriptionElementBase element
) {
167 return getCache(element
, CdmStore
.getDefaultLanguage());
171 * Set whatever the element's title cache equivalent is,
172 * depending on its class.
174 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
175 * @param value a {@link java.lang.String} object.
176 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
178 public static void setCache(DescriptionElementBase element
,
179 String value
, Language language
) {
180 if (element
instanceof TextData
) {
181 ((TextData
) element
).putText(language
, value
);
183 }else if (element
instanceof CommonTaxonName
) {
184 ((CommonTaxonName
) element
).setName(value
);
186 }else if (element
instanceof TaxonInteraction
) {
188 }else if(element
instanceof Distribution
){
189 MessagingUtils
.warn(DescriptionHelper
.class, "trying to set cache on distribution, don't know what to do at the moment.");
192 MessagingUtils
.warn(DescriptionHelper
.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
197 * Set whatever the element's title cache equivalent is,
198 * depending on its class, using the default language.
200 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
201 * @param value a {@link java.lang.String} object.
203 public static void setCache(DescriptionElementBase element
,
205 setCache(element
, value
, CdmStore
.getDefaultLanguage());
210 * <p>getObjectDescription</p>
212 * @param element a {@link java.lang.Object} object.
213 * @return a {@link java.lang.String} object.
215 public static String
getObjectDescription(Object element
) {
216 String resultString
= null;
217 if (element
instanceof IdentifiableEntity
) {
219 resultString
= ((IdentifiableEntity
) element
).getTitleCache();
220 }catch(LazyInitializationException e
){
221 String result
= "No Session to initialize title cache for IdentifiableEntity";
222 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
223 resultString
= "TODO: " + result
;
225 }else if (element
instanceof OriginalSourceBase
) {
227 OriginalSourceBase
<?
> originalSource
= (OriginalSourceBase
<?
>) element
;
228 // ISourceable sourcedObject = originalSource.getSourcedObj();
229 //due to #5743 the bidirectionality for sourced object had to be removed
230 String sourceObjectTitle
= "sourced object data not available (#5743)";
231 // if(sourcedObject instanceof IIdentifiableEntity){
232 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
233 // }else if(sourcedObject instanceof DescriptionElementBase){
234 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
236 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
239 resultString
= CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
240 }catch(LazyInitializationException e
){
241 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
242 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
243 resultString
= "TODO: " + result
;
245 }else if (element
instanceof LanguageStringBase
) {
246 resultString
= ((LanguageStringBase
) element
).getText();
247 }else if (element
instanceof DescriptionElementBase
) {
248 resultString
= getCache((DescriptionElementBase
) element
);
249 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
250 resultString
= getCache((RelationshipBase
<?
, ?
, ?
>) element
);
251 }else if (element
instanceof TypeDesignationBase
<?
>) {
252 resultString
= getCache((TypeDesignationBase
<?
>) element
);
253 }else if (element
instanceof HomotypicalGroup
) {
254 resultString
= getCache((HomotypicalGroup
) element
);
255 }else if (element
instanceof TaxonNode
) {
256 resultString
= getCache((TaxonNode
) element
);
257 }else if (element
instanceof DeterminationEvent
) {
258 resultString
= getCache((DeterminationEvent
) element
);
259 }else if (element
instanceof GatheringEvent
){
260 resultString
= getCache((GatheringEvent
) element
);
261 }else if (element
instanceof Marker
) {
262 Marker marker
= (Marker
) element
;
263 MarkerType type
= marker
.getMarkerType();
264 resultString
= (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
265 }else if (element
instanceof User
) {
266 User user
= (User
) element
;
267 resultString
= user
.getUsername();
268 }else if (element
instanceof Group
) {
269 Group group
= (Group
) element
;
270 resultString
= group
.getName();
271 }else if (element
instanceof KeyStatement
) {
272 KeyStatement keyStatement
= (KeyStatement
) element
;
273 resultString
= getCache(keyStatement
);
275 // TODO write return texts for HomotypicalGroup, etc.
276 resultString
= element
.toString();
279 if (resultString
== null){
280 resultString
= element
.toString();
285 private static String
getCache(GatheringEvent gatheringEvent
){
286 String ALTITUDE_PREFIX
= "alt. ";
287 final String METER
= "m";
292 AgentBase
<?
> collector
= CdmBase
.deproxy(gatheringEvent
.getCollector());
293 String collectorStr
= collector
== null?
null : collector
.getTitleCache();
294 result
= CdmUtils
.concat(", ", result
, collectorStr
);
297 TimePeriod gatheringPeriod
= gatheringEvent
.getTimeperiod();
298 result
= CdmUtils
.concat(", ", result
, (gatheringPeriod
== null?
null : gatheringPeriod
.toString()));
301 String strCountry
= null;
302 NamedArea country
= gatheringEvent
.getCountry();
303 Representation repCountry
= country
== null ?
null : country
.getRepresentation(Language
.DEFAULT());
304 strCountry
= repCountry
== null ?
null: repCountry
.getLabel();
305 result
= CdmUtils
.concat(", ", result
, strCountry
);
308 LanguageString locality
= gatheringEvent
.getLocality();
309 if (locality
!= null) {
310 result
= CdmUtils
.concat(", ", result
, locality
.getText());
315 if (isNotBlank(gatheringEvent
.getAbsoluteElevationText())){
316 elevationStr
= gatheringEvent
.getAbsoluteElevationText();
318 String text
= gatheringEvent
.getAbsoluteElevationText();
319 Integer min
= gatheringEvent
.getAbsoluteElevation();
320 Integer max
= gatheringEvent
.getAbsoluteElevationMax();
321 elevationStr
= DerivedUnitFacade
.distanceString(min
, max
, text
, METER
);
323 if (isNotBlank(elevationStr
)){
324 result
= CdmUtils
.concat(", " , result
, ALTITUDE_PREFIX
);
325 result
+= elevationStr
;
329 if (gatheringEvent
.getExactLocation() != null){
330 String exactLocation
= gatheringEvent
.getExactLocation().toSexagesimalString(false, false);
331 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";
355 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
358 unitStr
= unit
.getTitleCache();
359 if (isBlank(unitStr
)){
360 unitStr
= "Unlabled unit";
366 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
371 private static String
getCache(TaxonNode taxonNode
) {
373 Classification classification
= taxonNode
.getClassification();
374 if (classification
!= null){
375 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
376 result
= CdmUtils
.concat("" , result
, classificationStr
);
377 if (isBlank(result
)){
378 result
= classification
.toString();
382 TaxonNode parentNode
= taxonNode
.getParent();
383 if (parentNode
== null){
384 parentStr
= "no parent";
386 Taxon parentTaxon
= parentNode
.getTaxon();
387 if (parentTaxon
== null){
388 parentStr
= "no parent taxon";
390 TaxonName parentName
= parentTaxon
.getName();
391 if (parentName
== null){
392 parentStr
= "child of " + parentTaxon
.getTitleCache();
394 parentStr
= "child of " + parentName
.getTitleCache();
398 result
= CdmUtils
.concat(": ", result
, parentStr
);
403 private static String
getCache(TypeDesignationBase
<?
> designation
) {
404 designation
= CdmBase
.deproxy(designation
);
405 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
407 IdentifiableEntity
<?
> to
;
408 from
= designation
.getTypifiedNames();
409 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
410 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
411 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
412 to
= ((NameTypeDesignation
)designation
).getTypeName();
414 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
416 String typeLabel
= null;
418 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
419 if (typeRepr
!= null){
420 typeLabel
= typeRepr
.getAbbreviatedLabel();
422 if (isBlank(typeLabel
) && typeRepr
!= null){
423 typeLabel
= typeRepr
.getLabel();
425 if (isBlank(typeLabel
) ){
426 typeLabel
= status
.getSymbol();
428 if (isBlank(typeLabel
)){
429 typeLabel
= status
.getTitleCache();
432 if (isBlank(typeLabel
)){
435 String fromString
= "";
436 for (TaxonName name
: from
){
437 CdmUtils
.concat(",", fromString
, name
.getTitleCache());
439 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : fromString
,
440 typeLabel
, to
== null?
null : to
.getTitleCache()});
444 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
445 rel
= CdmBase
.deproxy(rel
);
446 RelationshipTermBase
<?
> type
= rel
.getType();
447 IdentifiableEntity
<?
> from
;
448 IdentifiableEntity
<?
> to
;
449 if (rel
.isInstanceOf(NameRelationship
.class)){
450 from
= ((NameRelationship
)rel
).getFromName();
451 to
= ((NameRelationship
)rel
).getToName();
452 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
453 from
= ((HybridRelationship
)rel
).getParentName();
454 to
= ((HybridRelationship
)rel
).getHybridName();
455 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
456 from
= ((TaxonRelationship
)rel
).getFromTaxon();
457 to
= ((TaxonRelationship
)rel
).getToTaxon();
460 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
461 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
462 fromMethod
.setAccessible(true);
463 toMethod
.setAccessible(true);
464 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
465 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
466 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
467 | IllegalArgumentException
| InvocationTargetException e
) {
468 throw new RuntimeException(e
);
471 String typeLabel
= null;
473 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
474 if (typeRepr
!= null){
475 typeLabel
= typeRepr
.getAbbreviatedLabel();
477 if (isBlank(typeLabel
) && typeRepr
!= null){
478 typeLabel
= typeRepr
.getLabel();
480 if (isBlank(typeLabel
) ){
481 typeLabel
= type
.getSymbol();
483 if (isBlank(typeLabel
)){
484 typeLabel
= type
.getTitleCache();
487 if (isBlank(typeLabel
)){
490 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
491 typeLabel
, to
== null?
null : to
.getTitleCache()});
496 private static String
getCache(HomotypicalGroup hg
) {
498 for (TaxonName tnb
: hg
.getTypifiedNames()){
499 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
501 if (isBlank(result
)){
502 result
= "No typified names";
507 private static String
getCache(KeyStatement ks
) {
510 result
= "KeyStatement";
516 * <p>getObjectClassname</p>
518 * @param element a {@link java.lang.Object} object.
519 * @return a {@link java.lang.String} object.
521 public static String
getObjectClassname(Object element
) {
522 return element
.getClass().getSimpleName();
526 * <p>getFeatureNodeContainerText</p>
528 * @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
529 * @return a {@link java.lang.String} object.
531 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
532 String result
= null;
533 if(element
.getFeatureNode() != null && element
.getFeatureNode().getFeature() != null){
534 result
= element
.getFeatureNode().getFeature().getLabel(CdmStore
.getDefaultLanguage());
536 return "No label set";
539 result
= element
.getFeatureNode().getFeature().getLabel();
545 * <p>getQuantitativeDataText</p>
547 * @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
548 * @return a {@link java.lang.String} object.
550 public static String
getQuantitativeDataText(QuantitativeData element
) {
551 TextData textData
= quantitativeDescriptionBuilder
.build(element
, getLanguageList());
553 return textData
.getText(CdmStore
.getDefaultLanguage());
557 * <p>getCategoricalDataText</p>
559 * @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
560 * @return a {@link java.lang.String} object.
562 public static String
getCategoricalDataText(CategoricalData element
) {
563 TextData textData
= categoricalDescriptionBuilder
.build(element
, getLanguageList());
565 return textData
.getText(CdmStore
.getDefaultLanguage());
568 private static List
<Language
> getLanguageList(){
569 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
572 private static DescriptionBuilder
<QuantitativeData
> quantitativeDescriptionBuilder
= new DefaultQuantitativeDescriptionBuilder();
573 private static DescriptionBuilder
<CategoricalData
> categoricalDescriptionBuilder
= new DefaultCategoricalDescriptionBuilder();
577 * <p>getDistributionText</p>
579 * @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
580 * @return a {@link java.lang.String} object.
582 public static String
getDistributionText(Distribution element
) {
584 String text
= "EMPTY";
586 Distribution distribution
= element
;
588 NamedArea area
= distribution
.getArea();
591 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
593 PresenceAbsenceTerm status
= distribution
.getStatus();
595 if (status
!= null) {
596 text
+= ", " + status
.getLabel();
598 text
+= ", NO STATUS";
605 * <p>getImageText</p>
607 * @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
608 * @return a {@link java.lang.String} object.
610 public static String
getImageText(Media media
) {
611 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
613 return title
.getText();
621 * <p>getElementText</p>
623 * @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
624 * @return a {@link java.lang.String} object.
626 public static String
getElementText(TextData element
) {
628 if(element
.getFeature().equals(Feature
.CITATION())){
630 for(DescriptionElementSource source
: element
.getSources()){
631 if(source
.getCitation() != null){
632 text
+= source
.getCitation().getTitleCache();
634 if(source
.getNameUsedInSource() != null){
635 text
+= " [ " + source
.getNameUsedInSource().getTitleCache() + " ]";
639 text
= "No sources provided";
642 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
643 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
644 text
= languageString
!= null ? languageString
.getText() : null;
646 return isBlank(text
) ?
"No text provided" : text
;
650 * <p>getTaxonInteractionText</p>
652 * @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
653 * @return a {@link java.lang.String} object.
655 public static String
getTaxonInteractionText(TaxonInteraction element
) {
657 Taxon taxon2
= element
.getTaxon2();
658 if(taxon2
!= null && taxon2
.getName() != null){
659 text
= taxon2
.getName().getTitleCache();
661 text
= "No taxon chosen";
668 * <p>getCommonNameText</p>
670 * @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
671 * @return a {@link java.lang.String} object.
673 public static String
getCommonNameText(CommonTaxonName commonName
) {
674 String name
= commonName
.getName();
675 if (name
== null || name
.length() == 0) {
676 name
= "No name provided";
678 Language language
= commonName
.getLanguage();
679 if (language
== null) {
680 name
+= " (No language provided)";
682 name
+= " (" + language
.getDescription() + ")";
688 * <p>getDescriptionText</p>
690 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
691 * @return a {@link java.lang.String} object.
693 public static String
getDescriptionText(DescriptionBase element
) {
694 String text
= element
.getTitleCache();
695 if (text
== null || text
.length() == 0) {
696 text
= "No label provided";
703 * <p>getIndividualsAssociationText</p>
705 * @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
706 * @return a {@link java.lang.String} object.
708 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
709 SpecimenOrObservationBase derivedUnit
= element
.getAssociatedSpecimenOrObservation();
710 if(derivedUnit
!= null){
711 return derivedUnit
.getTitleCache();
713 return "No unit chosen";
719 * @param element a {@link java.lang.Object} object.
720 * @return a {@link java.lang.String} object.
722 public static String
getLabel(Object element
){
723 String noLabelString
= "[no label]";
724 if (element
instanceof FeatureNodeContainer
){
725 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
727 else if (element
instanceof DescriptionBase
) {
728 return getDescriptionText((DescriptionBase
) element
);
730 else if(element
instanceof CategoricalData
){
731 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
732 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
733 categoricalDataText
= noLabelString
;
735 return categoricalDataText
;
737 else if (element
instanceof CommonTaxonName
) {
738 return getCommonNameText((CommonTaxonName
) element
);
740 else if (element
instanceof Distribution
) {
741 return getDistributionText((Distribution
) element
);
743 else if (element
instanceof IndividualsAssociation
) {
744 return getIndividualsAssociationText((IndividualsAssociation
) element
);
746 else if (element
instanceof QuantitativeData
) {
747 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
748 if(quantitativeDataText
==null || quantitativeDataText
.isEmpty()){
749 quantitativeDataText
= noLabelString
;
751 return quantitativeDataText
;
753 else if (element
instanceof TaxonInteraction
) {
754 return getTaxonInteractionText((TaxonInteraction
) element
);
756 else if (element
instanceof TextData
) {
757 return getElementText((TextData
) element
);
760 return element
.toString();
764 private static boolean isNotBlank(String str
){
765 return StringUtils
.isNotBlank(str
);
768 private static boolean isBlank(String str
){
769 return StringUtils
.isBlank(str
);