diff pkg/geoserver/reconf.go @ 4290:2de644208706

GeoServer config: Moved ReconfigureStyle function out of boot.go into reconf.go .
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 30 Aug 2019 11:30:11 +0200
parents d7152eb11d58
children 5f47eeea988d
line wrap: on
line diff
--- a/pkg/geoserver/reconf.go	Fri Aug 30 10:09:59 2019 +0200
+++ b/pkg/geoserver/reconf.go	Fri Aug 30 11:30:11 2019 +0200
@@ -20,6 +20,8 @@
 	"net/url"
 	"sync"
 	"time"
+
+	"gemma.intevation.de/gemma/pkg/models"
 )
 
 var (
@@ -82,3 +84,30 @@
 	confQueue.PushBack(fn)
 	confQueueCond.Signal()
 }
+
+// ReconfigureStyle returns a function to update a style
+// in the GeoServer to be in sync with the database.
+func ReconfigureStyle(name string) {
+	Reconfigure(func() error {
+		var stls styles
+		if err := stls.load(); err != nil {
+			return err
+		}
+
+		entries := models.InternalServices.Filter(
+			models.IntAnd(
+				models.IntWMS,
+				models.IntWithStyle,
+				models.IntByName(name)))
+
+		for i := range entries {
+			entry := &entries[i]
+			create := !stls.hasStyle(entry.Name)
+			if err := updateStyle(entry, create); err != nil {
+				return err
+			}
+		}
+
+		return nil
+	})
+}