From ab387eb03cd3034a219e79bd843b454a1a609770 Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@bioforsk.no>
Date: Tue, 3 May 2016 15:28:15 +0200
Subject: [PATCH] Adding pois and DeliaRadicumFloralis model preprocessing

---
 pom.xml                                       |  2 +-
 ...dicumFloralisModelOldCropPreprocessor.java | 33 ++++++++
 ...DeliaRadicumFloralisModelPreprocessor.java | 83 +++++++++++++++++++
 ...cumFloralisModelYoungCropPreprocessor.java | 33 ++++++++
 ...> LygusRugulipennisModelPreprocessor.java} |  2 +-
 .../vips/logic/i18n/vipslogictexts.properties |  4 +
 .../logic/i18n/vipslogictexts_bs.properties   |  4 +
 .../logic/i18n/vipslogictexts_hr.properties   |  4 +
 .../logic/i18n/vipslogictexts_nb.properties   |  4 +
 .../logic/i18n/vipslogictexts_sr.properties   |  4 +
 .../formdefinitions/models/DELIARFOBO.json    | 28 +++++++
 .../formdefinitions/models/DELIARFOBS.json    | 28 +++++++
 .../formdefinitions/models/DELIARFOBY.json    | 28 +++++++
 src/main/webapp/templates/master.ftl          |  1 +
 src/main/webapp/templates/poiForm.ftl         |  2 +
 src/main/webapp/templates/poiList.ftl         |  4 +
 16 files changed, 262 insertions(+), 2 deletions(-)
 create mode 100644 src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelOldCropPreprocessor.java
 create mode 100644 src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelPreprocessor.java
 create mode 100644 src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelYoungCropPreprocessor.java
 rename src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/{LygusRuguliPennisModelPreprocessor.java => LygusRugulipennisModelPreprocessor.java} (98%)
 create mode 100644 src/main/webapp/formdefinitions/models/DELIARFOBO.json
 create mode 100644 src/main/webapp/formdefinitions/models/DELIARFOBS.json
 create mode 100644 src/main/webapp/formdefinitions/models/DELIARFOBY.json

diff --git a/pom.xml b/pom.xml
index 1dce8a8d..f5135497 100644
--- a/pom.xml
+++ b/pom.xml
@@ -141,7 +141,7 @@
   <dependency>
     <groupId>org.freemarker</groupId>
     <artifactId>freemarker</artifactId>
-    <version>2.3.21</version>
+    <version>2.3.24-incubating</version>
   </dependency>
   <dependency>
 	<groupId>it.sauronsoftware.cron4j</groupId>
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelOldCropPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelOldCropPreprocessor.java
new file mode 100644
index 00000000..3009d229
--- /dev/null
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelOldCropPreprocessor.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2016 NIBIO <http://www.nibio.no/>. 
+ * 
+ * This file is part of VIPSLogic.
+ * VIPSLogic is free software: you can redistribute it and/or modify
+ * it under the terms of the NIBIO Open Source License as published by 
+ * NIBIO, either version 1 of the License, or (at your option) any
+ * later version.
+ * 
+ * VIPSLogic is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * NIBIO Open Source License for more details.
+ * 
+ * You should have received a copy of the NIBIO Open Source License
+ * along with VIPSLogic.  If not, see <http://www.nibio.no/licenses/>.
+ * 
+ */
+
+package no.nibio.vips.logic.scheduling.model.preprocessor;
+
+/**
+ * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
+ * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
+ */
+public class DeliaRadicumFloralisModelOldCropPreprocessor extends DeliaRadicumFloralisModelPreprocessor{
+
+    @Override
+    public String getModelId()
+    {
+        return "DELIARFOBO";
+    }
+}
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelPreprocessor.java
new file mode 100644
index 00000000..b37b952a
--- /dev/null
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelPreprocessor.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2016 NIBIO <http://www.nibio.no/>. 
+ * 
+ * This file is part of VIPSLogic.
+ * VIPSLogic is free software: you can redistribute it and/or modify
+ * it under the terms of the NIBIO Open Source License as published by 
+ * NIBIO, either version 1 of the License, or (at your option) any
+ * later version.
+ * 
+ * VIPSLogic is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * NIBIO Open Source License for more details.
+ * 
+ * You should have received a copy of the NIBIO Open Source License
+ * along with VIPSLogic.  If not, see <http://www.nibio.no/licenses/>.
+ * 
+ */
+
+package no.nibio.vips.logic.scheduling.model.preprocessor;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+import no.nibio.vips.entity.ModelConfiguration;
+import no.nibio.vips.logic.entity.ForecastConfiguration;
+import no.nibio.vips.logic.entity.Organism;
+import no.nibio.vips.logic.entity.PointOfInterest;
+import no.nibio.vips.logic.scheduling.model.ModelRunPreprocessor;
+import no.nibio.vips.logic.scheduling.model.PreprocessorException;
+import no.nibio.vips.logic.util.SessionControllerGetter;
+import no.nibio.vips.logic.util.SystemTime;
+import no.nibio.vips.observation.Observation;
+import no.nibio.vips.util.WeatherUtil;
+
+/**
+ * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
+ * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
+ */
+public class DeliaRadicumFloralisModelPreprocessor extends ModelRunPreprocessor{
+    public final static String START_DATE_GROWTH = "START_DATE_GROWTH";
+
+    @Override
+    public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) throws PreprocessorException {
+        ModelConfiguration config = null;
+        try
+        {
+            PointOfInterest location = configuration.getLocationPointOfInterestId();
+            config = new ModelConfiguration();
+            String tzID = configuration.getVipsLogicUserId().getOrganizationId().getDefaultTimeZone();
+            TimeZone timeZone = TimeZone.getTimeZone(tzID);
+            config.setConfigParameter("timeZone", tzID);
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+            format.setTimeZone(timeZone);
+
+            Date startDateGrowth = format.parse(configuration.getForecastModelConfigurationValue(this.getModelId() + "_" + START_DATE_GROWTH));
+            config.setConfigParameter("startDateGrowth", configuration.getForecastModelConfigurationValue(this.getModelId() + "_" + START_DATE_GROWTH));
+            WeatherUtil wUtil = new WeatherUtil();
+            Date endDateCalculation = wUtil.normalizeToExactDate(SystemTime.getSystemTime(),timeZone);
+            config.setConfigParameter("endDateCalculation", format.format(endDateCalculation));
+
+            Organism organism = SessionControllerGetter.getOrganismBean().getOrganismByLatinName("Delia floralis/radicum");
+            List<Observation> pestObservations = SessionControllerGetter.getObservationBean().getObservations(organism.getOrganismId(), location.getPointOfInterestId(),startDateGrowth,SystemTime.getSystemTime());
+
+            config.setConfigParameter("pestObservations", pestObservations);
+            config.setModelId(this.getModelId());
+        }
+        catch(ParseException | NullPointerException ex)
+        {
+            throw new PreprocessorException(ex.getMessage());
+        }
+        return config;
+    }
+
+    @Override
+    public String getModelId() {
+        return "DELIARFOBS";
+    }
+
+}
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelYoungCropPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelYoungCropPreprocessor.java
new file mode 100644
index 00000000..32b7f920
--- /dev/null
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/DeliaRadicumFloralisModelYoungCropPreprocessor.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2016 NIBIO <http://www.nibio.no/>. 
+ * 
+ * This file is part of VIPSLogic.
+ * VIPSLogic is free software: you can redistribute it and/or modify
+ * it under the terms of the NIBIO Open Source License as published by 
+ * NIBIO, either version 1 of the License, or (at your option) any
+ * later version.
+ * 
+ * VIPSLogic is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * NIBIO Open Source License for more details.
+ * 
+ * You should have received a copy of the NIBIO Open Source License
+ * along with VIPSLogic.  If not, see <http://www.nibio.no/licenses/>.
+ * 
+ */
+
+package no.nibio.vips.logic.scheduling.model.preprocessor;
+
+/**
+ * @copyright 2016 <a href="http://www.nibio.no/">NIBIO</a>
+ * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
+ */
+public class DeliaRadicumFloralisModelYoungCropPreprocessor extends DeliaRadicumFloralisModelPreprocessor{
+
+    @Override
+    public String getModelId()
+    {
+        return "DELIARFOBY";
+    }
+}
diff --git a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LygusRuguliPennisModelPreprocessor.java b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LygusRugulipennisModelPreprocessor.java
similarity index 98%
rename from src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LygusRuguliPennisModelPreprocessor.java
rename to src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LygusRugulipennisModelPreprocessor.java
index c9687fcc..fd181268 100644
--- a/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LygusRuguliPennisModelPreprocessor.java
+++ b/src/main/java/no/nibio/vips/logic/scheduling/model/preprocessor/LygusRugulipennisModelPreprocessor.java
@@ -41,7 +41,7 @@ import no.nibio.vips.util.weather.WeatherDataSourceUtil;
  * @copyright 2015 <a href="http://www.nibio.no/">NIBIO</a>
  * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
  */
-public class LygusRuguliPennisModelPreprocessor extends ModelRunPreprocessor {
+public class LygusRugulipennisModelPreprocessor extends ModelRunPreprocessor {
 
     @Override
     public ModelConfiguration getModelConfiguration(ForecastConfiguration configuration) throws PreprocessorException {
diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties
index a3a575ba..dd975590 100644
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties
@@ -397,3 +397,7 @@ pointOfInterestType=Point of Interest Type
 poiStored=Poi was stored
 pointOfInterestType_0=General
 noMapDataEntered=No map data entered
+DELIARFOBS=Delia radicum/floralis observation model
+DELIARFOBY=Delia radicum/floralis observation model for young crops
+DELIARFOBO=Delia radicum/floralis observation model for old crops
+startDateGrowth=Start date for growth
diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties
index 5547c896..163839cc 100644
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties
@@ -397,3 +397,7 @@ pointOfInterestType=Point of Interest Type
 poiStored=Poi was stored
 pointOfInterestType_0=General
 noMapDataEntered=No map data entered
+DELIARFOBS=Delia radicum/floralis observation model
+DELIARFOBY=Delia radicum/floralis observation model for young crops
+DELIARFOBO=Delia radicum/floralis observation model for old crops
+startDateGrowth=Start date for growth
diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties
index bc21fc56..ccc78a3a 100644
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties
@@ -396,3 +396,7 @@ pointOfInterestType=Point of Interest Type
 poiStored=Poi was stored
 pointOfInterestType_0=General
 noMapDataEntered=No map data entered
+DELIARFOBS=Delia radicum/floralis observation model
+DELIARFOBY=Delia radicum/floralis observation model for young crops
+DELIARFOBO=Delia radicum/floralis observation model for old crops
+startDateGrowth=Start date for growth
diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties
index aa1b4047..a93dec75 100644
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties
@@ -397,3 +397,7 @@ pointOfInterestType=Stedstype
 poiStored=Stedet ble lagret
 pointOfInterestType_0=Generelt
 noMapDataEntered=Kartdata ikke registrert
+DELIARFOBS=Liten og stor k\u00e5lflue - observasjonsmodell
+DELIARFOBY=Liten og stor k\u00e5lflue - observasjonsmodell i nyplantede felt
+DELIARFOBO=Liten og stor k\u00e5lflue - observasjonsmodell i felt eldre enn 4 uker
+startDateGrowth=Dato for vekststart
diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties
index fae40f7b..17140369 100644
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties
@@ -397,3 +397,7 @@ pointOfInterestType=Point of Interest Type
 poiStored=Poi was stored
 pointOfInterestType_0=General
 noMapDataEntered=No map data entered
+DELIARFOBS=Delia radicum/floralis observation model
+DELIARFOBY=Delia radicum/floralis observation model for young crops
+DELIARFOBO=Delia radicum/floralis observation model for old crops
+startDateGrowth=Start date for growth
diff --git a/src/main/webapp/formdefinitions/models/DELIARFOBO.json b/src/main/webapp/formdefinitions/models/DELIARFOBO.json
new file mode 100644
index 00000000..1403be2e
--- /dev/null
+++ b/src/main/webapp/formdefinitions/models/DELIARFOBO.json
@@ -0,0 +1,28 @@
+{
+    "_licenseNote": [
+        "Copyright (c) 2016 NIBIO <http://www.nibio.no/>. ",
+        "",
+        "This file is part of VIPSLogic. ",
+        "VIPSLogic is free software: you can redistribute it and/or modify ",
+        "it under the terms of the NIBIO Open Source License as published by ",
+        "NIBIO, either version 1 of the License, or (at your option) any ",
+        "later version. ",
+        "",
+        "VIPSLogic is distributed in the hope that it will be useful, ",
+        "but WITHOUT ANY WARRANTY; without even the implied warranty of ",
+        "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the ",
+        "NIBIO Open Source License for more details. ",
+        "",
+        "You should have received a copy of the NIBIO Open Source License ",
+        "along with VIPSLogic.  If not, see <http://www.nibio.no/licenses/>. "
+    ],
+    "_comment" : "Structure of the specific fields for DELIARFOBS",
+    "fields": [
+        {
+            "name" : "startDateGrowth",
+            "dataType" : "DATE",
+            "dateFormat" : "yyyy-MM-dd",
+            "required" : true
+        }
+    ]
+}
diff --git a/src/main/webapp/formdefinitions/models/DELIARFOBS.json b/src/main/webapp/formdefinitions/models/DELIARFOBS.json
new file mode 100644
index 00000000..1403be2e
--- /dev/null
+++ b/src/main/webapp/formdefinitions/models/DELIARFOBS.json
@@ -0,0 +1,28 @@
+{
+    "_licenseNote": [
+        "Copyright (c) 2016 NIBIO <http://www.nibio.no/>. ",
+        "",
+        "This file is part of VIPSLogic. ",
+        "VIPSLogic is free software: you can redistribute it and/or modify ",
+        "it under the terms of the NIBIO Open Source License as published by ",
+        "NIBIO, either version 1 of the License, or (at your option) any ",
+        "later version. ",
+        "",
+        "VIPSLogic is distributed in the hope that it will be useful, ",
+        "but WITHOUT ANY WARRANTY; without even the implied warranty of ",
+        "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the ",
+        "NIBIO Open Source License for more details. ",
+        "",
+        "You should have received a copy of the NIBIO Open Source License ",
+        "along with VIPSLogic.  If not, see <http://www.nibio.no/licenses/>. "
+    ],
+    "_comment" : "Structure of the specific fields for DELIARFOBS",
+    "fields": [
+        {
+            "name" : "startDateGrowth",
+            "dataType" : "DATE",
+            "dateFormat" : "yyyy-MM-dd",
+            "required" : true
+        }
+    ]
+}
diff --git a/src/main/webapp/formdefinitions/models/DELIARFOBY.json b/src/main/webapp/formdefinitions/models/DELIARFOBY.json
new file mode 100644
index 00000000..1403be2e
--- /dev/null
+++ b/src/main/webapp/formdefinitions/models/DELIARFOBY.json
@@ -0,0 +1,28 @@
+{
+    "_licenseNote": [
+        "Copyright (c) 2016 NIBIO <http://www.nibio.no/>. ",
+        "",
+        "This file is part of VIPSLogic. ",
+        "VIPSLogic is free software: you can redistribute it and/or modify ",
+        "it under the terms of the NIBIO Open Source License as published by ",
+        "NIBIO, either version 1 of the License, or (at your option) any ",
+        "later version. ",
+        "",
+        "VIPSLogic is distributed in the hope that it will be useful, ",
+        "but WITHOUT ANY WARRANTY; without even the implied warranty of ",
+        "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the ",
+        "NIBIO Open Source License for more details. ",
+        "",
+        "You should have received a copy of the NIBIO Open Source License ",
+        "along with VIPSLogic.  If not, see <http://www.nibio.no/licenses/>. "
+    ],
+    "_comment" : "Structure of the specific fields for DELIARFOBS",
+    "fields": [
+        {
+            "name" : "startDateGrowth",
+            "dataType" : "DATE",
+            "dateFormat" : "yyyy-MM-dd",
+            "required" : true
+        }
+    ]
+}
diff --git a/src/main/webapp/templates/master.ftl b/src/main/webapp/templates/master.ftl
index 030bbc2d..dc8892e2 100644
--- a/src/main/webapp/templates/master.ftl
+++ b/src/main/webapp/templates/master.ftl
@@ -55,6 +55,7 @@
 		  <#else>
 		  	<li><a href="/user?action=viewUser&userId=${user.userId}">${i18nBundle.myAccount}</a></li>
 		  </#if>
+		  <li><a href="/poi">${i18nBundle.pois}</a></li>
 		  <#if user.isOrganizationAdmin() || user.isSuperUser() || user.isMessageAuthor()>
 		  	<li><a href="/message">${i18nBundle.messages}</a></li>
 		  </#if>
diff --git a/src/main/webapp/templates/poiForm.ftl b/src/main/webapp/templates/poiForm.ftl
index f385d9d5..0e10b8f0 100644
--- a/src/main/webapp/templates/poiForm.ftl
+++ b/src/main/webapp/templates/poiForm.ftl
@@ -122,6 +122,7 @@
 			     <span class="help-block" id="${formId}_countryCode_validation"></span>
 			  </div>
 			  <fieldset>
+			  <#if user.isSuperUser() || user.isOrganizationAdmin()>
 			<h3>${i18nBundle.externalResources}</h3>
 			<#if poi.pointOfInterestExternalResourceSet?has_content>
 				<#list poi.pointOfInterestExternalResourceSet as poiExternalResource>
@@ -139,6 +140,7 @@
 			 </#list>
 			 
 			</fieldset>
+			</#if>
 			  <#if user.isSuperUser()>
 			  <div class="form-group">
 			    <label for="userId">${i18nBundle.vipsLogicUserId}</label>
diff --git a/src/main/webapp/templates/poiList.ftl b/src/main/webapp/templates/poiList.ftl
index d2901b7c..593d3b1f 100644
--- a/src/main/webapp/templates/poiList.ftl
+++ b/src/main/webapp/templates/poiList.ftl
@@ -35,6 +35,10 @@
 			var organizationId = selectList.options[selectList.selectedIndex].value;
 			window.location="/poi?organizationId=" + organizationId;
 		}
+		
+		var userPoiIds = [
+			<#list pois?sort_by("name") as poi>${poi.pointOfInterestId}<#sep>,</#list>
+			]; 
 	</script>
 </#macro>
 <#macro page_contents>
-- 
GitLab