X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/6683588710e09130f3e99183bfcc5719474b0406..7cda107ce11940b64749ee7f5a8fc065f96ffab0:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DescriptionHelper.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DescriptionHelper.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DescriptionHelper.java index fff58b292..b54b5d8a4 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DescriptionHelper.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DescriptionHelper.java @@ -18,10 +18,12 @@ import java.util.Set; import org.apache.commons.lang.StringUtils; import org.hibernate.LazyInitializationException; +import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; import eu.etaxonomy.cdm.api.service.DefaultCategoricalDescriptionBuilder; import eu.etaxonomy.cdm.api.service.DefaultQuantitativeDescriptionBuilder; import eu.etaxonomy.cdm.api.service.DescriptionBuilder; import eu.etaxonomy.cdm.common.CdmUtils; +import eu.etaxonomy.cdm.model.agent.AgentBase; import eu.etaxonomy.cdm.model.common.CdmBase; import eu.etaxonomy.cdm.model.common.Group; import eu.etaxonomy.cdm.model.common.IdentifiableEntity; @@ -34,6 +36,7 @@ import eu.etaxonomy.cdm.model.common.OriginalSourceBase; import eu.etaxonomy.cdm.model.common.RelationshipBase; import eu.etaxonomy.cdm.model.common.RelationshipTermBase; import eu.etaxonomy.cdm.model.common.Representation; +import eu.etaxonomy.cdm.model.common.TimePeriod; import eu.etaxonomy.cdm.model.common.User; import eu.etaxonomy.cdm.model.description.CategoricalData; import eu.etaxonomy.cdm.model.description.CommonTaxonName; @@ -62,6 +65,7 @@ import eu.etaxonomy.cdm.model.name.TaxonName; import eu.etaxonomy.cdm.model.name.TypeDesignationBase; import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase; import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent; +import eu.etaxonomy.cdm.model.occurrence.GatheringEvent; import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; import eu.etaxonomy.cdm.model.taxon.Classification; import eu.etaxonomy.cdm.model.taxon.Taxon; @@ -75,7 +79,6 @@ import eu.etaxonomy.taxeditor.store.CdmStore; * * @author p.ciardelli * @author n.hoffmann - * @created 02.04.2009 */ public class DescriptionHelper { @@ -147,7 +150,7 @@ public class DescriptionHelper { } } String result = cache == null ? "" : cache; - if (StringUtils.isNotBlank(mainElementLabel)){ + if (isNotBlank(mainElementLabel)){ result = CdmUtils.concat(" ", result, "(" + mainElementLabel + ")"); } return result; @@ -253,6 +256,8 @@ public class DescriptionHelper { resultString = getCache((TaxonNode) element); }else if (element instanceof DeterminationEvent) { resultString = getCache((DeterminationEvent) element); + }else if (element instanceof GatheringEvent){ + resultString = getCache((GatheringEvent) element); }else if (element instanceof Marker) { Marker marker = (Marker) element; MarkerType type = marker.getMarkerType(); @@ -276,6 +281,58 @@ public class DescriptionHelper { } return resultString; } + + private static String getCache(GatheringEvent gatheringEvent){ + String ALTITUDE_PREFIX = "alt. "; + final String METER = "m"; + + String result = ""; + + //collector + AgentBase collector = CdmBase.deproxy(gatheringEvent.getCollector()); + String collectorStr = collector == null? null : collector.getTitleCache(); + result = CdmUtils.concat(", ", result, collectorStr); + + //gathering period + TimePeriod gatheringPeriod = gatheringEvent.getTimeperiod(); + result = CdmUtils.concat(", ", result, (gatheringPeriod == null? null : gatheringPeriod.toString())); + + //country + String strCountry = null; + NamedArea country = gatheringEvent.getCountry(); + Representation repCountry = country == null ? null : country.getRepresentation(Language.DEFAULT()); + strCountry = repCountry == null ? null: repCountry.getLabel(); + result = CdmUtils.concat(", ", result, strCountry); + + //locality + LanguageString locality = gatheringEvent.getLocality(); + if (locality != null) { + result = CdmUtils.concat(", ", result, locality.getText()); + } + + //elevation + String elevationStr; + if (isNotBlank(gatheringEvent.getAbsoluteElevationText())){ + elevationStr = gatheringEvent.getAbsoluteElevationText(); + }else{ + String text = gatheringEvent.getAbsoluteElevationText(); + Integer min = gatheringEvent.getAbsoluteElevation(); + Integer max = gatheringEvent.getAbsoluteElevationMax(); + elevationStr = DerivedUnitFacade.distanceString(min, max, text, METER); + } + if (isNotBlank(elevationStr)){ + result = CdmUtils.concat(", " , result, ALTITUDE_PREFIX); + result += elevationStr; + } + + //exact locality + if (gatheringEvent.getExactLocation() != null){ + String exactLocation = gatheringEvent.getExactLocation().toSexagesimalString(false, false); + result = CdmUtils.concat(", ", result, exactLocation); + } + + return result; + } private static String getCache(DeterminationEvent detEvent) { @@ -286,10 +343,10 @@ public class DescriptionHelper { if (taxonName != null){ taxonStr = taxonName.getTitleCache(); } - if (StringUtils.isBlank(taxonStr) && taxon != null){ + if (isBlank(taxonStr) && taxon != null){ taxonStr = taxon.getTitleCache(); } - if (StringUtils.isBlank(taxonStr)){ + if (isBlank(taxonStr)){ taxonStr = "no or unlabled taxon"; } @@ -299,7 +356,7 @@ public class DescriptionHelper { String unitStr; if (unit != null){ unitStr = unit.getTitleCache(); - if (StringUtils.isBlank(unitStr)){ + if (isBlank(unitStr)){ unitStr = "Unlabled unit"; } }else{ @@ -317,7 +374,7 @@ public class DescriptionHelper { if (classification != null){ String classificationStr = classification.getName() == null ? "" : classification.getName().getText(); result = CdmUtils.concat("" , result, classificationStr); - if (StringUtils.isBlank(result)){ + if (isBlank(result)){ result = classification.toString(); } } @@ -362,17 +419,17 @@ public class DescriptionHelper { if (typeRepr != null){ typeLabel = typeRepr.getAbbreviatedLabel(); } - if (StringUtils.isBlank(typeLabel) && typeRepr != null){ + if (isBlank(typeLabel) && typeRepr != null){ typeLabel = typeRepr.getLabel(); } - if (StringUtils.isBlank(typeLabel) ){ + if (isBlank(typeLabel) ){ typeLabel = status.getSymbol(); } - if (StringUtils.isBlank(typeLabel)){ + if (isBlank(typeLabel)){ typeLabel = status.getTitleCache(); } } - if (StringUtils.isBlank(typeLabel)){ + if (isBlank(typeLabel)){ typeLabel = "->"; } String fromString = ""; @@ -417,17 +474,17 @@ public class DescriptionHelper { if (typeRepr != null){ typeLabel = typeRepr.getAbbreviatedLabel(); } - if (StringUtils.isBlank(typeLabel) && typeRepr != null){ + if (isBlank(typeLabel) && typeRepr != null){ typeLabel = typeRepr.getLabel(); } - if (StringUtils.isBlank(typeLabel) ){ + if (isBlank(typeLabel) ){ typeLabel = type.getSymbol(); } - if (StringUtils.isBlank(typeLabel)){ + if (isBlank(typeLabel)){ typeLabel = type.getTitleCache(); } } - if (StringUtils.isBlank(typeLabel)){ + if (isBlank(typeLabel)){ typeLabel = "->"; } String result = CdmUtils.concat(" ", new String[]{from == null ? null : from.getTitleCache(), @@ -441,7 +498,7 @@ public class DescriptionHelper { for (TaxonName tnb : hg.getTypifiedNames()){ result = CdmUtils.concat(", ", result, tnb.getTitleCache()); } - if (StringUtils.isBlank(result)){ + if (isBlank(result)){ result = "No typified names"; } return result; @@ -578,7 +635,7 @@ public class DescriptionHelper { text += " [ " + source.getNameUsedInSource().getTitleCache() + " ]"; } } - if(CdmUtils.isEmpty(text)){ + if(isBlank(text)){ text = "No sources provided"; } }else{ @@ -586,7 +643,7 @@ public class DescriptionHelper { LanguageString languageString = element.getPreferredLanguageString(languages); text = languageString != null ? languageString.getText() : null; } - return CdmUtils.isEmpty(text) ? "No text provided" : text; + return isBlank(text) ? "No text provided" : text; } /** @@ -703,4 +760,12 @@ public class DescriptionHelper { return element.toString(); } } + + private static boolean isNotBlank(String str){ + return StringUtils.isNotBlank(str); + } + + private static boolean isBlank(String str){ + return StringUtils.isBlank(str); + } }