From 71af0db50bdbe1ec60209f807e3df24d7d0255f2 Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Tue, 3 Sep 2024 10:04:37 +0200
Subject: [PATCH] Add isPrivate to POI/WeatherStation

---
 .../servlet/PointOfInterestController.java           |  4 ++++
 .../no/nibio/vips/logic/entity/PointOfInterest.java  | 11 ++++++++++-
 .../db/migration/V21__Add_POI_Property_IsPrivate.sql | 12 ++++++++++++
 src/main/webapp/formdefinitions/poiForm.json         |  5 +++++
 .../webapp/formdefinitions/weatherStationForm.json   |  5 +++++
 src/main/webapp/templates/poiForm.ftl                |  8 ++++++++
 src/main/webapp/templates/weatherstationForm.ftl     |  8 ++++++++
 7 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 src/main/resources/db/migration/V21__Add_POI_Property_IsPrivate.sql

diff --git a/src/main/java/no/nibio/vips/logic/controller/servlet/PointOfInterestController.java b/src/main/java/no/nibio/vips/logic/controller/servlet/PointOfInterestController.java
index 9f2d923e..e1a80dd7 100755
--- a/src/main/java/no/nibio/vips/logic/controller/servlet/PointOfInterestController.java
+++ b/src/main/java/no/nibio/vips/logic/controller/servlet/PointOfInterestController.java
@@ -298,6 +298,8 @@ public class PointOfInterestController extends HttpServlet {
                             {
                                 weatherStation.setIsForecastLocation(Boolean.TRUE);
                             }
+                            
+                            weatherStation.setIsPrivate(formValidation.getFormField("isPrivate").getWebValue() != null);
 
                             Double altitude = 0.0;
                             Point p2d = formValidation.getFormField("location").getValueAsPointWGS84();
@@ -657,6 +659,8 @@ public class PointOfInterestController extends HttpServlet {
                                 {
                                     poi.setIsForecastLocation(Boolean.FALSE);
                                 }
+
+                                poi.setIsPrivate(formValidation.getFormField("isPrivate").getWebValue() != null);
                                 
                                 Double altitude = 0.0;
                                 Point p2d = formValidation.getFormField("location").getValueAsPointWGS84();
diff --git a/src/main/java/no/nibio/vips/logic/entity/PointOfInterest.java b/src/main/java/no/nibio/vips/logic/entity/PointOfInterest.java
index 33aaf8a0..1994194e 100755
--- a/src/main/java/no/nibio/vips/logic/entity/PointOfInterest.java
+++ b/src/main/java/no/nibio/vips/logic/entity/PointOfInterest.java
@@ -91,8 +91,17 @@ public class PointOfInterest implements Serializable, Comparable {
     private Boolean isForecastLocation;
     private Integer pointOfInterestTypeId;
     private Date lastEditedTime;
+    private Boolean isPrivate;
    
-    
+    @Column(name = "is_private")
+    public Boolean getIsPrivate() {
+        return isPrivate;
+    }
+
+    public void setIsPrivate(Boolean isPrivate) {
+        this.isPrivate = isPrivate;
+    }
+
     // For attaching ad-hoc properties
     // e.g. Worst warning for map
     private Map<String, Object> properties;
diff --git a/src/main/resources/db/migration/V21__Add_POI_Property_IsPrivate.sql b/src/main/resources/db/migration/V21__Add_POI_Property_IsPrivate.sql
new file mode 100644
index 00000000..abc442d8
--- /dev/null
+++ b/src/main/resources/db/migration/V21__Add_POI_Property_IsPrivate.sql
@@ -0,0 +1,12 @@
+-- Adding this property when adding support for private POIs/weather datasources in VIPS
+ALTER TABLE point_of_interest
+ADD COLUMN is_private BOOLEAN DEFAULT FALSE;
+
+-- Set all POIS not owned by a superuser or admin to is_private = TRUE
+UPDATE point_of_interest 
+SET is_private=TRUE
+WHERE user_id NOT IN
+(
+	SELECT DISTINCT user_id FROM user_vips_logic_role
+	WHERE vips_logic_role_id IN (1,2)
+);
\ No newline at end of file
diff --git a/src/main/webapp/formdefinitions/poiForm.json b/src/main/webapp/formdefinitions/poiForm.json
index 6aa6e956..83a8b2f0 100755
--- a/src/main/webapp/formdefinitions/poiForm.json
+++ b/src/main/webapp/formdefinitions/poiForm.json
@@ -86,6 +86,11 @@
             "name" : "isForecastLocation",
             "dataType" : "STRING",
             "required" : false
+        },
+        {
+            "name" : "isPrivate",
+            "dataType" : "STRING",
+            "required" : false
         }
     ]
 }
diff --git a/src/main/webapp/formdefinitions/weatherStationForm.json b/src/main/webapp/formdefinitions/weatherStationForm.json
index c4540a52..3b0af8f3 100755
--- a/src/main/webapp/formdefinitions/weatherStationForm.json
+++ b/src/main/webapp/formdefinitions/weatherStationForm.json
@@ -87,6 +87,11 @@
             "dataType" : "STRING",
             "fieldType" : "MULTIPLE_MAP",
             "required" : false
+        },
+        {
+            "name" : "isPrivate",
+            "dataType" : "STRING",
+            "required" : false
         }
         
     ]
diff --git a/src/main/webapp/templates/poiForm.ftl b/src/main/webapp/templates/poiForm.ftl
index 58fe8f49..7e728784 100755
--- a/src/main/webapp/templates/poiForm.ftl
+++ b/src/main/webapp/templates/poiForm.ftl
@@ -81,6 +81,14 @@
 			    <input type="text" class="form-control" name="name" placeholder="${i18nBundle.name}" value="${(poi.name)!""}" onblur="validateField(this); checkPoiNameAvailability(this);"/>
 			    <span class="help-block" id="${formId}_name_validation"></span>
 			  </div>
+              <div class="form-group">
+			  	<div class="checkbox">
+					<label>
+						<input type="checkbox" name="isPrivate"<#if poi.isPrivate?has_content && poi.isPrivate == true> checked="checked"<#else></#if>/>
+					</label>
+					${i18nBundle.isPrivate}
+			  	</div>
+			  </div>
 			  <div class="form-group">
 			    <label for="pointOfInterestTypeId">${i18nBundle.pointOfInterestType}</label>
 			    <select class="form-control" name="pointOfInterestTypeId" onblur="validateField(this);">
diff --git a/src/main/webapp/templates/weatherstationForm.ftl b/src/main/webapp/templates/weatherstationForm.ftl
index cb0a0afd..07089514 100755
--- a/src/main/webapp/templates/weatherstationForm.ftl
+++ b/src/main/webapp/templates/weatherstationForm.ftl
@@ -71,6 +71,14 @@
 					  </label>
 				  </div>
 			  </div>
+			  <div class="form-group">
+			  	<div class="checkbox">
+					<label>
+						<input type="checkbox" name="isPrivate"<#if weatherStation.isPrivate?has_content && weatherStation.isPrivate == true> checked="checked"<#else></#if>/>
+					</label>
+					${i18nBundle.isPrivate}
+			  	</div>
+			  </div>
 			  <div class="form-group">
 			    <label for="location">${i18nBundle.location} (<a href="http://en.wikipedia.org/wiki/World_Geodetic_System#A_new_World_Geodetic_System:_WGS_84" target="new">WGS84</a>: ${i18nBundle.longitude},${i18nBundle.latitude})</label>
 			    <input type="text" class="form-control" id="location" name="location" placeholder="${i18nBundle.location}" value="${(weatherStation.longitude?c)!""},${(weatherStation.latitude?c)!""}" onblur="validateField(this);" onchange="if(validateField(this)){updateMarkerPosition();}" />
-- 
GitLab