diff pkg/models/intservices.go @ 871:f0b6852c14d1 geo-style

More on uploading styles to gemma.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 30 Sep 2018 11:49:23 +0200
parents 0c79068c46b7
children ad9272460ef3
line wrap: on
line diff
--- a/pkg/models/intservices.go	Sat Sep 29 23:33:14 2018 +0200
+++ b/pkg/models/intservices.go	Sun Sep 30 11:49:23 2018 +0200
@@ -22,11 +22,30 @@
 	mu      sync.Mutex
 }
 
-const selectPublishedServices = `SELECT relname, style, as_wms, as_wfs
+const (
+	selectPublishedServices = `SELECT relname, style, as_wms, as_wfs
 FROM sys_admin.published_services JOIN pg_class ON name = oid ORDER by relname`
 
+	updateStyleSQL = `
+UPDATE sys_admin.published_services
+SET style = $1
+WHERE name IN (SELECT oid FROM pg_class WHERE relname = $2)`
+)
+
 var InternalServices = &IntServices{}
 
+func UpdateInternalStyle(name, style string) error {
+	return auth.RunAs("sys_admin", context.Background(),
+		func(conn *sql.Conn) error {
+			_, err := conn.ExecContext(
+				context.Background(), updateStyleSQL, style, name)
+			if err == nil {
+				InternalServices.Invalidate()
+			}
+			return err
+		})
+}
+
 func (ps *IntServices) Find(name string) (string, bool) {
 	ps.mu.Lock()
 	defer ps.mu.Unlock()
@@ -97,6 +116,14 @@
 func IntWMS(entry IntEntry) bool { return entry.WMS }
 func IntWFS(entry IntEntry) bool { return entry.WFS }
 
+func IntByName(name string) func(IntEntry) bool {
+	return func(entry IntEntry) bool { return entry.Name == name }
+}
+
+func IntAnd(a, b func(IntEntry) bool) func(IntEntry) bool {
+	return func(entry IntEntry) bool { return a(entry) && b(entry) }
+}
+
 func (ps *IntServices) Filter(accept func(IntEntry) bool) []IntEntry {
 	ps.mu.Lock()
 	defer ps.mu.Unlock()