From fe2514515356a3c88710ecfa4c2df93fb6843920 Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Wed, 10 May 2023 11:31:41 +0200
Subject: [PATCH] Add POI type trap [VIPSUTV-404]

---
 .../logic/entity/PointOfInterestType.java     |  1 +
 .../logic/entity/PointOfInterestTypeTrap.java | 36 +++++++++++++++++++
 .../helpers/PointOfInterestFactory.java       |  9 ++---
 .../db/migration/V12__POI_type_added.sql      | 30 ++++++++++++++++
 .../vips/logic/i18n/vipslogictexts.properties |  1 +
 .../logic/i18n/vipslogictexts_bs.properties   |  1 +
 .../logic/i18n/vipslogictexts_hr.properties   |  1 +
 .../logic/i18n/vipslogictexts_nb.properties   |  1 +
 .../logic/i18n/vipslogictexts_sr.properties   |  1 +
 .../i18n/vipslogictexts_zh_CN.properties      |  1 +
 src/main/webapp/templates/poiForm.ftl         |  2 +-
 11 files changed, 77 insertions(+), 7 deletions(-)
 create mode 100644 src/main/java/no/nibio/vips/logic/entity/PointOfInterestTypeTrap.java
 create mode 100644 src/main/resources/db/migration/V12__POI_type_added.sql

diff --git a/src/main/java/no/nibio/vips/logic/entity/PointOfInterestType.java b/src/main/java/no/nibio/vips/logic/entity/PointOfInterestType.java
index ee2a94eb..c1db3167 100755
--- a/src/main/java/no/nibio/vips/logic/entity/PointOfInterestType.java
+++ b/src/main/java/no/nibio/vips/logic/entity/PointOfInterestType.java
@@ -64,6 +64,7 @@ public class PointOfInterestType implements Serializable {
     public static final int POINT_OF_INTEREST_TYPE_FARM = 2;
     public static final int POINT_OF_INTEREST_TYPE_FIELD = 3;
     public static final int POINT_OF_INTEREST_TYPE_REGION = 4;
+    public static final int POINT_OF_INTEREST_TYPE_TRAP = 5;
 
     public PointOfInterestType() {
     }
diff --git a/src/main/java/no/nibio/vips/logic/entity/PointOfInterestTypeTrap.java b/src/main/java/no/nibio/vips/logic/entity/PointOfInterestTypeTrap.java
new file mode 100644
index 00000000..53e408bc
--- /dev/null
+++ b/src/main/java/no/nibio/vips/logic/entity/PointOfInterestTypeTrap.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 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.entity;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import java.io.Serializable;
+
+/**
+ * @copyright 2023 <a href="http://www.nibio.no/">NIBIO</a>
+ * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
+ */
+@Entity
+@DiscriminatorValue("5")
+@Table(name = "point_of_interest_trap")
+public class PointOfInterestTypeTrap extends PointOfInterest implements Serializable {
+
+}
diff --git a/src/main/java/no/nibio/vips/logic/entity/helpers/PointOfInterestFactory.java b/src/main/java/no/nibio/vips/logic/entity/helpers/PointOfInterestFactory.java
index 9cd70d81..8fd0467f 100644
--- a/src/main/java/no/nibio/vips/logic/entity/helpers/PointOfInterestFactory.java
+++ b/src/main/java/no/nibio/vips/logic/entity/helpers/PointOfInterestFactory.java
@@ -19,12 +19,7 @@
 
 package no.nibio.vips.logic.entity.helpers;
 
-import no.nibio.vips.logic.entity.PointOfInterest;
-import no.nibio.vips.logic.entity.PointOfInterestType;
-import no.nibio.vips.logic.entity.PointOfInterestTypeFarm;
-import no.nibio.vips.logic.entity.PointOfInterestTypeField;
-import no.nibio.vips.logic.entity.PointOfInterestTypeRegion;
-import no.nibio.vips.logic.entity.PointOfInterestWeatherStation;
+import no.nibio.vips.logic.entity.*;
 
 /**
  * @copyright 2020 <a href="http://www.nibio.no/">NIBIO</a>
@@ -42,6 +37,8 @@ public class PointOfInterestFactory {
                 return new PointOfInterestTypeField();
             case PointOfInterestType.POINT_OF_INTEREST_TYPE_REGION:
                 return new PointOfInterestTypeRegion();
+            case PointOfInterestType.POINT_OF_INTEREST_TYPE_TRAP:
+                return new PointOfInterestTypeTrap();
             default:
                 return new PointOfInterest();
         }
diff --git a/src/main/resources/db/migration/V12__POI_type_added.sql b/src/main/resources/db/migration/V12__POI_type_added.sql
new file mode 100644
index 00000000..fed77970
--- /dev/null
+++ b/src/main/resources/db/migration/V12__POI_type_added.sql
@@ -0,0 +1,30 @@
+/* 
+ * Copyright (c) 2020 NIBIO <http://www.nibio.no/>. 
+ * 
+ * This file is part of VIPSLogic.
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Affero General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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
+ *  GNU Affero General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Affero General Public License
+ *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ * 
+ */
+/**
+ * Author:  Tor-Einar Skog <tor-einar.skog@nibio.no>
+ * Created: May 10th, 2023
+ */
+
+-- Create POI type trap as entity
+CREATE TABLE public.point_of_interest_trap (
+    point_of_interest_id INTEGER REFERENCES public.point_of_interest(point_of_interest_id) PRIMARY KEY REFERENCES public.point_of_interest(point_of_interest_id)
+);
+
+INSERT INTO public.point_of_interest_type (point_of_interest_type_id, default_name)
+VALUES (5, 'Trap');
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 b97d6017..5aa15272 100755
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts.properties
@@ -1042,3 +1042,4 @@ allRoles=All roles
 allStatuses=All statuses
 LEAFBLOTCH=Leaf blotch model
 universalMessageSettingsLink_tpl=To edit your notification subscriptions, please use this link: {0}
+pointOfInterestType_5=Trap
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 f2572880..a85c1e94 100755
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_bs.properties
@@ -1035,3 +1035,4 @@ allRoles=All roles
 allStatuses=All statuses
 LEAFBLOTCH=Leaf blotch model
 universalMessageSettingsLink_tpl=To edit your VIPS notification subscriptions, please use this link: {0}
+pointOfInterestType_5=Trap
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 34aa7af5..1202bdc4 100755
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_hr.properties
@@ -1034,3 +1034,4 @@ allRoles=All roles
 allStatuses=All statuses
 LEAFBLOTCH=Leaf blotch model
 universalMessageSettingsLink_tpl=To edit your notification subscriptions, please use this link: {0}
+pointOfInterestType_5=Trap
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 dbb32157..e0ef3617 100755
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_nb.properties
@@ -1043,3 +1043,4 @@ allRoles=Alle roller
 allStatuses=Alle statuser
 LEAFBLOTCH=Bladflekksjukdomsmodell
 universalMessageSettingsLink_tpl=For � endre dine abonnement p� push-varsler fra VIPS, bruk denne lenken: {0}
+pointOfInterestType_5=Felle
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 bc87ecca..29a3b621 100755
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_sr.properties
@@ -1036,3 +1036,4 @@ allRoles=All roles
 allStatuses=All statuses
 LEAFBLOTCH=Leaf blotch model
 universalMessageSettingsLink_tpl=To edit your notification subscriptions, please use this link: {0}
+pointOfInterestType_5=Trap
diff --git a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_zh_CN.properties b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_zh_CN.properties
index 3bb3a5d8..6659caa0 100755
--- a/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_zh_CN.properties
+++ b/src/main/resources/no/nibio/vips/logic/i18n/vipslogictexts_zh_CN.properties
@@ -1029,3 +1029,4 @@ allRoles=All roles
 allStatuses=All statuses
 LEAFBLOTCH=Leaf blotch model
 universalMessageSettingsLink_tpl=To edit your notification subscriptions, please use this link: {0}
+pointOfInterestType_5=Trap
diff --git a/src/main/webapp/templates/poiForm.ftl b/src/main/webapp/templates/poiForm.ftl
index 74555332..b2d0274b 100755
--- a/src/main/webapp/templates/poiForm.ftl
+++ b/src/main/webapp/templates/poiForm.ftl
@@ -84,7 +84,7 @@
 			  <div class="form-group">
 			    <label for="pointOfInterestTypeId">${i18nBundle.pointOfInterestType}</label>
 			    <select class="form-control" name="pointOfInterestTypeId" onblur="validateField(this);">
-				<#list 0..3 as pointOfInterestTypeId>
+				<#list [0,1,2,3,5] as pointOfInterestTypeId>
                                     <#if pointOfInterestTypeId != 1>
 					<option value="${pointOfInterestTypeId}"<#if 
 								poi.pointOfInterestTypeId?has_content && pointOfInterestTypeId == poi.pointOfInterestTypeId
-- 
GitLab