* 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.List;
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;
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
import eu.etaxonomy.cdm.io.specimen.excel.in.SpecimenSynthesysExcelImportConfigurator;
import eu.etaxonomy.cdm.io.taxonx2013.TaxonXImportConfigurator;
import eu.etaxonomy.cdm.model.agent.Team;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.common.Annotation;
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.common.TimePeriod;
import eu.etaxonomy.cdm.model.location.Point;
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;
+import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
/**
* @author p.kelbert
- * @created 20.10.2008
- * @version 1.0
+ * @since 20.10.2008
*/
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();
* @param collectorNames
*/
public UnitsGatheringEvent(ITermService termService, String locality, String languageIso, Double longitude,
- Double latitude, String elevationText, String elevationMin, String elevationMax, String elevationUnit,
+ Double latitude, String errorRadius, String elevationText, String elevationMin, String elevationMax, String elevationUnit,
String date, String gatheringNotes, String gatheringMethod, ReferenceSystem referenceSystem,
Abcd206ImportConfigurator config) {
this.setLocality(termService, locality, languageIso);
- this.setCoordinates(longitude, latitude, referenceSystem);
+ Integer errorRadiusInt = null;
+ if (StringUtils.isNotBlank(errorRadius)){
+ errorRadiusInt = Integer.getInteger(errorRadius);
+ }
+
+ this.setCoordinates(longitude, latitude, referenceSystem, errorRadiusInt);
this.setDate(date);
this.setNotes(gatheringNotes);
this.setElevation(elevationText, elevationMin, elevationMax, elevationUnit);
* @param langageIso
*/
public void setLocality(ITermService termService, String locality, String languageIso){
+
LanguageString loc = null;
- List<LanguageString> languages = termService.getAllLanguageStrings(0, 0);
- boolean locFound=false;
- if ((languageIso == null) || (termService.getLanguageByIso(languageIso) == null)){
- // if (languageIso != null && termService.getLanguageByIso(languageIso) == null ){
- // logger.info("unknown iso used for the locality: "+languageIso);
- // }
- for (LanguageString ls:languages){
- if (ls == null) {
- continue;
- }
- ls = HibernateProxyHelper.deproxy(ls, LanguageString.class);
- if (ls.getText() == null){
- continue;
- }
- if (ls.getText().equalsIgnoreCase(locality)){
- loc=ls;
- locFound=true;
- // System.out.println("REUSE LOCALITY");
- }
- }
- if (!locFound){
- loc = LanguageString.NewInstance(locality, Language.DEFAULT());
- termService.saveLanguageData(loc);
- languages.add(loc);
- }
+ if (languageIso == null){
+ loc = LanguageString.NewInstance(locality, Language.DEFAULT());
}else{
- for (LanguageString ls:languages){
- if (ls.getText().equalsIgnoreCase(locality) && ls.getLanguage().equals(termService.getLanguageByIso(languageIso))){
- loc=ls;
- locFound=true;
- // System.out.println("REUSE LOCALITY");
- }
- }
- if (!locFound) {
- loc = LanguageString.NewInstance(locality, termService.getLanguageByIso(languageIso));
- termService.saveLanguageData(loc);
- languages.add(loc);
- }
+ loc = LanguageString.NewInstance(locality, termService.getLanguageByIso(languageIso));
}
+
+
if (loc == null){logger.warn("PROBLEM LOCALITY");}
this.gatheringEvent.setLocality(loc);
}
* @param: latitude
*/
public void setCoordinates(Double longitude, Double latitude){
- setCoordinates(longitude, latitude, null);
+ setCoordinates(longitude, latitude, null, null);
}
- public void setCoordinates(Double longitude, Double latitude, ReferenceSystem referenceSystem){
+ public void setCoordinates(Double longitude, Double latitude, ReferenceSystem referenceSystem, Integer errorRadius){
//create coordinates point
if((longitude == null) || (latitude == null)){
return;
if (latitude != 0.0) {
coordinates.setLatitude(latitude);
}
+ if (errorRadius != null && errorRadius != 0) {
+ coordinates.setErrorRadius(errorRadius);
+ }
coordinates.setReferenceSystem(referenceSystem);
this.gatheringEvent.setExactLocation(coordinates);
}
public void setDate(String date){
- TimePeriod timeperiod = this.gatheringEvent.getTimeperiod();
- if(timeperiod==null){
- timeperiod = TimePeriod.NewInstance();
- this.gatheringEvent.setTimeperiod(timeperiod);
- }
- timeperiod.setFreeText(date);
+ this.gatheringEvent.setTimeperiod(TimePeriodParser.parseString(date));
+
}
public void setElevation(String elevationText, String elevationMin, String elevationMax, String elevationUnit){
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
}
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.");
}
this.gatheringEvent.setDistanceToWaterSurfaceText(depthText);
}
else{
-
+ if (StringUtils.isNotBlank(depthUnit) && depthUnit.equals("cm")){
+ if (depthMin != null) {
+ depthMin = depthMin/100;
+ }
+ if (depthMax != null) {
+ depthMax = depthMax/100;
+ }
+ }
if(depthMin!=null){
this.gatheringEvent.setDistanceToWaterSurface(depthMin);
}
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.");
}
return this.gatheringEvent.getCollectingMethod();
}
- /**
- * @param gatheringTeam
- */
public void setTeam(String gatheringTeam, SpecimenSynthesysExcelImportConfigurator config) {
Team t = new Team();
if ((gatheringTeam != null) && !gatheringTeam.isEmpty()) {