Merge branch 'release/5.44.0'
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / specimen / UnitsGatheringEvent.java
index ea5d4784208efd2308c3726b157f9ad4ebf8b92d..e099d2977e714e75d6e1819071f52e88dfa8966d 100644 (file)
@@ -6,16 +6,15 @@
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
-
 package eu.etaxonomy.cdm.io.specimen;
 
-
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 
 import eu.etaxonomy.cdm.api.service.IAgentService;
 import eu.etaxonomy.cdm.api.service.ITermService;
@@ -39,11 +38,11 @@ import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
 /**
  * @author p.kelbert
  * @since 20.10.2008
- * @version 1.0
  */
 public class UnitsGatheringEvent {
 
-    private static final Logger logger = Logger.getLogger(UnitsGatheringEvent.class);
+    private static final Logger logger = LogManager.getLogger();
+
     private static final boolean DEBUG = false;
     private final GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
 
@@ -99,7 +98,7 @@ public class UnitsGatheringEvent {
              Abcd206ImportConfigurator config) {
         this.setLocality(termService, locality, languageIso);
         Integer errorRadiusInt = null;
-        if (errorRadius != null){
+        if (StringUtils.isNotBlank(errorRadius)){
             errorRadiusInt = Integer.getInteger(errorRadius);
         }
 
@@ -187,13 +186,7 @@ public class UnitsGatheringEvent {
     }
 
     public void setDate(String date){
-        TimePeriod timeperiod = this.gatheringEvent.getTimeperiod();
-        if(timeperiod==null){
-            timeperiod = TimePeriod.NewInstance();
-            this.gatheringEvent.setTimeperiod(timeperiod);
-        }else{
             this.gatheringEvent.setTimeperiod(TimePeriodParser.parseString(date));
-        }
 
     }
 
@@ -204,15 +197,15 @@ public class UnitsGatheringEvent {
         else{
             //TODO check for unit at string end
             String pattern = "\\D";// regex for non-digits
-            if(elevationMin!=null){
+            if(StringUtils.isNotBlank(elevationMin)){
                 Integer min = Integer.parseInt(elevationMin.replaceAll(pattern, ""));
                 this.gatheringEvent.setAbsoluteElevation(min);
             }
-            if(elevationMax!=null){
+            if(StringUtils.isNotBlank(elevationMax)){
                 Integer max = Integer.parseInt(elevationMax.replaceAll(pattern, ""));
                 this.gatheringEvent.setAbsoluteElevationMax(max);
             }
-            if(elevationUnit!=null){
+            if(StringUtils.isNotBlank(elevationUnit)){
                 if(!elevationUnit.equals("m")){
                     //TODO convert if necessary
                 }
@@ -227,15 +220,15 @@ public class UnitsGatheringEvent {
         else{
             //TODO check for unit at string end
             String pattern = "\\D";// regex for non-digits
-            if(heightMin!=null){
+            if(StringUtils.isNotBlank(heightMin)){
                 Double min = Double.parseDouble(heightMin.replaceAll(pattern, ""));
                 this.gatheringEvent.setDistanceToGround(min);
             }
-            if(heightMax!=null){
+            if(StringUtils.isNotBlank(heightMax)){
                 Double max = Double.parseDouble(heightMax.replaceAll(pattern, ""));
                 this.gatheringEvent.setDistanceToGroundMax(max);
             }
-            if(heightUnit!=null){
+            if(StringUtils.isNotBlank(heightUnit)){
                 if (!heightUnit.equals("m")){
                     logger.debug("The unit " + heightUnit + " of the distance to ground is not meter.");
                 }
@@ -248,7 +241,7 @@ public class UnitsGatheringEvent {
             this.gatheringEvent.setDistanceToWaterSurfaceText(depthText);
         }
         else{
-            if (depthUnit != null && depthUnit.equals("cm")){
+            if (StringUtils.isNotBlank(depthUnit) && depthUnit.equals("cm")){
                if (depthMin != null) {
                        depthMin = depthMin/100;
                }
@@ -262,7 +255,7 @@ public class UnitsGatheringEvent {
             if(depthMax!=null){
                 this.gatheringEvent.setDistanceToWaterSurfaceMax(depthMax);
             }
-            if(depthUnit!=null){
+            if(StringUtils.isNotBlank(depthUnit)){
 
                 if (!depthUnit.equals("m")){
                     logger.debug("The unit " + depthUnit + " of the distance to ground is not meter.");
@@ -355,9 +348,6 @@ public class UnitsGatheringEvent {
         return this.gatheringEvent.getCollectingMethod();
     }
 
-    /**
-     * @param gatheringTeam
-     */
     public void setTeam(String gatheringTeam, SpecimenSynthesysExcelImportConfigurator config) {
         Team t = new Team();
         if ((gatheringTeam != null) && !gatheringTeam.isEmpty()) {