diff --git a/src/main/java/no/nibio/vips/logic/modules/roughage/RoughageService.java b/src/main/java/no/nibio/vips/logic/modules/roughage/RoughageService.java index bc4d9511ac2f49cfc1cb3d86939fe78d6747709a..d0af049bd7be820e6a86ffdc3532d01ba9b9a264 100755 --- a/src/main/java/no/nibio/vips/logic/modules/roughage/RoughageService.java +++ b/src/main/java/no/nibio/vips/logic/modules/roughage/RoughageService.java @@ -104,6 +104,7 @@ public class RoughageService { @QueryParam("wateringAffectsNormalData") String wateringAffectsNormalData, @QueryParam("firstHarvest") String firstHarvestStr, @QueryParam("secondHarvest") String secondHarvestStr, + @QueryParam("firstPossibleGrowthStartDate") String firstPossibleGrowthStartDateStr, @QueryParam("soilType") Integer soilType, @QueryParam("cloverShare") Integer cloverShare, @QueryParam("userWeatherScenarios") String useWeatherScenarios, @@ -119,21 +120,23 @@ public class RoughageService { TimeZone timeZone = TimeZone.getTimeZone(timeZoneStr); Date firstHarvest = parseUtil.parseISODate(firstHarvestStr, timeZone); Date secondHarvest = secondHarvestStr != null ? parseUtil.parseISODate(secondHarvestStr, timeZone) : null; - // Calculating start and end date of weather data retrieval - // Start is April 1st - Calendar cal = Calendar.getInstance(timeZone); - cal.setTime(firstHarvest); - cal.set(Calendar.MONTH, Calendar.MARCH); - cal.set(Calendar.DATE, 1); + // Calculating start and end date of weather data retrieval + // Start is March 1st unless specified otherwise + Date firstPossibleGrowthStartDate = firstPossibleGrowthStartDateStr != null ? parseUtil.parseISODate(firstPossibleGrowthStartDateStr, timeZone) : null; WeatherUtil wUtil = new WeatherUtil(); - Date marchFirst = wUtil.normalizeToExactDate(cal.getTime(), timeZone); - + Calendar cal = Calendar.getInstance(timeZone); + if(firstPossibleGrowthStartDate == null) { + cal.setTime(firstHarvest); + cal.set(Calendar.MONTH, Calendar.MARCH); + cal.set(Calendar.DATE, 1); + firstPossibleGrowthStartDate = wUtil.normalizeToExactDate(cal.getTime(), timeZone); + } // End date for weather data depends on season // We try September 30th. If that's in the future, // We add 10 days to today Date dateOfLastWeatherData; - cal.setTime(marchFirst); + cal.setTime(firstPossibleGrowthStartDate); cal.set(Calendar.MONTH, Calendar.SEPTEMBER); cal.set(Calendar.DATE, 30); Date endOfSeptember = cal.getTime(); @@ -164,7 +167,7 @@ public class RoughageService { WeatherElements.SOIL_TEMPERATURE_10CM_MEAN, WeatherElements.POTENTIAL_EVAPORATION }, - marchFirst, + firstPossibleGrowthStartDate, dateOfLastWeatherData ); } catch (WeatherDataSourceException ex) { @@ -367,9 +370,10 @@ public class RoughageService { config.setConfigParameter("observations", observations); config.setConfigParameter("timeZone", timeZone.getID()); config.setConfigParameter("firstHarvest", firstHarvest); + config.setConfigParameter("firstPossibleGrowthStartDate", firstPossibleGrowthStartDate); config.setConfigParameter("soilType", soilType); config.setConfigParameter("cloverShare", cloverShare); - + // Optional parameters if(secondHarvest != null) { @@ -426,7 +430,7 @@ public class RoughageService { WeatherElements.SOIL_TEMPERATURE_10CM_MEAN, WeatherElements.POTENTIAL_EVAPORATION }, - marchFirst, + firstPossibleGrowthStartDate, //dateOfLastWeatherData latestObsDate );