Mercurial > gemma
annotate pkg/controllers/system.go @ 5520:05db984d3db1
Improve performance of bottleneck area calculation
Avoid buffer calculations by replacing them with simple distance comparisons
and calculate the boundary of the result geometry only once per iteration.
In some edge cases with very large numbers of iterations, this reduced
the runtime of a bottleneck import by a factor of more than twenty.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 21 Oct 2021 19:50:39 +0200 |
parents | 5f47eeea988d |
children | 31973f6f5cca |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
2 // without warranty, see README.md and license for details. |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
6 // |
4236
27ed6f709195
Remove unused systemconf.feature_colours from backend
Bernhard Reiter <bernhard@intevation.de>
parents:
4232
diff
changeset
|
7 // Copyright (C) 2018, 2019 by via donau |
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
12 // * Sascha Wilde <sascha.wilde@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
854
diff
changeset
|
13 |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
14 package controllers |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
15 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
16 import ( |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
17 "bytes" |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
18 "context" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
20 "fmt" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
21 "io/ioutil" |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
22 "net/http" |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
23 "regexp" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
24 "strings" |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
25 "sync" |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
26 "time" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
27 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
28 "github.com/gorilla/mux" |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
29 |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
30 "gemma.intevation.de/gemma/pkg/auth" |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
31 "gemma.intevation.de/gemma/pkg/common" |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
32 "gemma.intevation.de/gemma/pkg/config" |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
33 "gemma.intevation.de/gemma/pkg/geoserver" |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
34 "gemma.intevation.de/gemma/pkg/imports" |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
35 "gemma.intevation.de/gemma/pkg/log" |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
36 "gemma.intevation.de/gemma/pkg/models" |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
37 |
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
38 mw "gemma.intevation.de/gemma/pkg/middleware" |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
39 ) |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
40 |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
41 const ( |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
42 getSettingsSQL = ` |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
43 SELECT config_key, config_val |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
44 FROM sys_admin.system_config` |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
45 |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
46 getConfigSQL = ` |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
47 SELECT config_val |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
48 FROM sys_admin.system_config |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
49 WHERE config_key = $1` |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
50 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
51 updateSettingSQL = ` |
3630
2467e619cf67
Fixed more SQL typos.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3629
diff
changeset
|
52 INSERT INTO sys_admin.system_config (config_key, config_val) |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
53 VALUES ($1, $2) |
3629
1825a1bc9fb1
Fixed typo in SQL statement.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3628
diff
changeset
|
54 ON CONFLICT (config_key) DO UPDATE SET config_val = $2` |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
55 |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
56 deleteSoundingDiffsSQL = ` |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
57 DELETE FROM caching.sounding_differences` |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
58 ) |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
59 |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
60 // System status end points |
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
61 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
62 func showSystemLog(req *http.Request) (jr mw.JSONResult, err error) { |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
63 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
64 serviceName := mux.Vars(req)["service"] |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
65 fileName := mux.Vars(req)["file"] |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
66 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
67 // The following check is currently most likely unnecessary as I wasn't |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
68 // able to inject a verbatim '/' via the middleware, but better be on |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
69 // the safe site... |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
70 if strings.Contains(fileName, "/") { |
4506
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4248
diff
changeset
|
71 err = mw.JSONError{ |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4248
diff
changeset
|
72 Code: http.StatusBadRequest, |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4248
diff
changeset
|
73 Message: "error: no slashes allowed in file name", |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4248
diff
changeset
|
74 } |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
75 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
76 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
77 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
78 var path string |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
79 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
80 switch serviceName { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
81 case "apache2", "postgresql": |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
82 path = "/var/log/" + serviceName + "/" + fileName |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
83 default: |
4506
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4248
diff
changeset
|
84 err = mw.JSONError{ |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4248
diff
changeset
|
85 Code: http.StatusBadRequest, |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4248
diff
changeset
|
86 Message: "error: invalid service: " + serviceName, |
e020e6e34ad7
Made 'go vet' happy again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4248
diff
changeset
|
87 } |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
88 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
89 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
90 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
91 var txt []byte |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
92 |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
93 if txt, err = ioutil.ReadFile(path); err != nil { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
94 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
95 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
96 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
97 jr = mw.JSONResult{ |
722
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
98 Result: struct { |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
99 Path string `json:"path"` |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
100 Content string `json:"content"` |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
101 }{path, string(txt)}, |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
102 } |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
103 return |
815f5e2ed974
Added simple endpoint to view system logs.
Sascha Wilde <wilde@intevation.de>
parents:
diff
changeset
|
104 } |
840
0f61bfc21041
Added end point to get style (colour) information for feature.
Sascha Wilde <wilde@intevation.de>
parents:
722
diff
changeset
|
105 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
106 func getSystemConfig(req *http.Request) (jr mw.JSONResult, err error) { |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
107 |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
108 cfg := config.PublishedConfig() |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
109 if cfg == "" { |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
110 jr = mw.JSONResult{Result: strings.NewReader("{}")} |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
111 return |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
112 } |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
113 |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
114 var data []byte |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
115 if data, err = ioutil.ReadFile(cfg); err != nil { |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
116 return |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
117 } |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
118 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
119 jr = mw.JSONResult{Result: bytes.NewReader(data)} |
3104
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
120 return |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
121 } |
19fc84a98479
Added "published-config" field to configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
122 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
123 func getSystemSettings(req *http.Request) (jr mw.JSONResult, err error) { |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
124 |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
125 var rows *sql.Rows |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
126 if rows, err = mw.JSONConn(req).QueryContext(req.Context(), getSettingsSQL); err != nil { |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
127 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
128 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
129 defer rows.Close() |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
130 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
131 settings := map[string]string{} |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
132 |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
133 for rows.Next() { |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
134 var key, val string |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
135 if err = rows.Scan(&key, &val); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
136 return |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
137 } |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
138 settings[key] = val |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
139 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
140 if err = rows.Err(); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
141 return |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
142 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
143 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
144 jr = mw.JSONResult{Result: settings} |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
145 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
146 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
147 |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
148 type reconfFunc func(sql.NullString, string) (func(*http.Request), error) |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
149 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
150 var ( |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
151 reconfigureFuncsMu sync.Mutex |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
152 reconfigureFuncs = map[string]reconfFunc{} |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
153 ) |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
154 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
155 func registerReconfigureFunc(key string, fn reconfFunc) { |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
156 reconfigureFuncsMu.Lock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
157 defer reconfigureFuncsMu.Unlock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
158 reconfigureFuncs[key] = fn |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
159 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
160 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
161 func reconfigureFunc(key string) reconfFunc { |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
162 reconfigureFuncsMu.Lock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
163 defer reconfigureFuncsMu.Unlock() |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
164 return reconfigureFuncs[key] |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
165 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
166 |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
167 var validColorRe = regexp.MustCompile(`#[[:xdigit:]]{6}`) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
168 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
169 func reconfigureWMSLayer( |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
170 old sql.NullString, curr, |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
171 which string, |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
172 ) (func(*http.Request), error) { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
173 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
174 if !validColorRe.MatchString(curr) { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
175 return nil, fmt.Errorf("'%v' is not a valid color", curr) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
176 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
177 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
178 if !old.Valid || old.String != strings.ToLower(curr) { |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
179 return func(*http.Request) { geoserver.ReconfigureStyle(which) }, nil |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
180 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
181 |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
182 return nil, nil |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
183 } |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
184 |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
185 func reconfigureClassBreaks( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
186 old sql.NullString, curr, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
187 which string, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
188 recalc func(*http.Request), |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
189 ) (func(*http.Request), error) { |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
190 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
191 // If new values are broken, don't proceed. |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
192 currCVs, err := models.ParseColorValues(curr) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
193 if err != nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
194 return nil, err |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
195 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
196 |
5423
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
197 styles := strings.Split(which, ",") |
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
198 |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
199 doBoth := func(req *http.Request) { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
200 log.Infof("trigger re-calculation of %s.", which) |
5423
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
201 for _, style := range styles { |
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
202 geoserver.ReconfigureStyle(style) |
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
203 } |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
204 recalc(req) |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
205 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
206 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
207 if !old.Valid { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
208 return doBoth, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
209 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
210 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
211 oldCVs, err := models.ParseColorValues(old.String) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
212 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
213 log.Warnf("old config value is broken: %v\n", err) |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
214 return doBoth, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
215 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
216 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
217 if len(currCVs) != len(oldCVs) { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
218 return doBoth, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
219 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
220 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
221 colorChanged := false |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
222 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
223 for i := range currCVs { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
224 if currCVs[i].Value != oldCVs[i].Value { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
225 return doBoth, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
226 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
227 if currCVs[i].Color != oldCVs[i].Color { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
228 colorChanged = true |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
229 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
230 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
231 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
232 // Only the color changed -> no expensive recalc needed. |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
233 if colorChanged { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
234 log.Infof("only colors changed.") |
5423
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
235 return func(*http.Request) { |
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
236 for _, style := range styles { |
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
237 geoserver.ReconfigureStyle(style) |
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
238 } |
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
239 }, nil |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
240 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
241 |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
242 return nil, nil |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
243 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
244 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
245 func init() { |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
246 registerReconfigureFunc("morphology_classbreaks", |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
247 func(old sql.NullString, curr string) (func(*http.Request), error) { |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
248 return reconfigureClassBreaks( |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
249 old, curr, |
5423
24156a964eaa
[WIP] Add support for scan marking points in geoserver.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4584
diff
changeset
|
250 "sounding_results_areas_geoserver,sounding_results_marking_points_geoserver", |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
251 func(req *http.Request) { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
252 if s, ok := auth.GetSession(req); ok { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
253 triggerSoundingResultsContoursRecalc(s.User, curr) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
254 } |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
255 }) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
256 }) |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
257 registerReconfigureFunc("morphology_classbreaks_compare", |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
258 func(old sql.NullString, curr string) (func(*http.Request), error) { |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
259 return reconfigureClassBreaks( |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
260 old, curr, |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
261 "sounding_differences", |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
262 func(*http.Request) { go deleteSoundingDiffs() }) |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
263 }) |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
264 |
4248
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
265 reconf := func(which string) func(sql.NullString, string) (func(*http.Request), error) { |
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
266 return func(old sql.NullString, curr string) (func(*http.Request), error) { |
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
267 return reconfigureWMSLayer(old, curr, which) |
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
268 } |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
269 } |
4248
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
270 |
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
271 dm := reconf("distance_marks_geoserver") |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
272 registerReconfigureFunc("distance_marks_fill", dm) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
273 registerReconfigureFunc("distance_marks_stroke", dm) |
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
274 |
4248
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
275 dma := reconf("distance_marks_ashore_geoserver") |
4247
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4244
diff
changeset
|
276 registerReconfigureFunc("distance_marks_ashore_fill", dma) |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4244
diff
changeset
|
277 registerReconfigureFunc("distance_marks_ashore_stroke", dma) |
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4244
diff
changeset
|
278 |
4248
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
279 registerReconfigureFunc("waterway_area_stroke", reconf("waterway_area")) |
b83668bef692
Simplified WMS reconfiguration call if registered key was found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4247
diff
changeset
|
280 registerReconfigureFunc("waterway_axis_stroke", reconf("waterway_axis")) |
4247
152b9eb5ca47
styles-config: implement styling of WMS-Layers
Fadi Abbud <fadi.abbud@intevation.de>
parents:
4244
diff
changeset
|
281 |
4232
8aff98c84a5a
Example how to style distance_marks WMS layer with templating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4214
diff
changeset
|
282 // TODO: Add more layers. |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
283 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
284 |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
285 func triggerSoundingResultsContoursRecalc(who, breaks string) { |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
286 var serialized string |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
287 job := &imports.IsoRefresh{ClassBreaks: breaks} |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
288 serialized, err := common.ToJSONString(job) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
289 if err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
290 log.Errorf("%v\n", err) |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
291 return |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
292 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
293 var jobID int64 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
294 if jobID, err = imports.AddJob( |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
295 imports.ISRJobKind, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
296 time.Time{}, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
297 nil, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
298 nil, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
299 who, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
300 false, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
301 serialized, |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
302 ); err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
303 log.Errorf("%v\n", err) |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
304 return |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
305 } |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
306 log.Infof( |
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
307 "recalculate sounding results contours in job %d.\n", |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
308 jobID) |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
309 |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
310 } |
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
311 |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
312 func deleteSoundingDiffs() { |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
313 // TODO: Better do that in import queue? |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
314 ctx := context.Background() |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
315 |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
316 if err := auth.RunAs(ctx, "sys_admin", |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
317 func(conn *sql.Conn) error { |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
318 _, err := conn.ExecContext(ctx, deleteSoundingDiffsSQL) |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
319 return err |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
320 }, |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
321 ); err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5423
diff
changeset
|
322 log.Errorf("cleaning sounding diffs cache failed: %v\n", err) |
3929
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
323 } |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
324 } |
45be361f2d48
If the settings for sounding diffs are changed in a way that they need recalculation, flush the cache.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3854
diff
changeset
|
325 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
326 func setSystemSettings(req *http.Request) (jr mw.JSONResult, err error) { |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
327 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
328 settings := mw.JSONInput(req).(*map[string]string) |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
329 |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
330 ctx := req.Context() |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
331 var tx *sql.Tx |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
332 if tx, err = mw.JSONConn(req).BeginTx(ctx, nil); err != nil { |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
333 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
334 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
335 defer tx.Rollback() |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
336 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
337 var setStmt *sql.Stmt |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
338 if setStmt, err = tx.PrepareContext(ctx, updateSettingSQL); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
339 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
340 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
341 defer setStmt.Close() |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
342 var getStmt *sql.Stmt |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
343 if getStmt, err = tx.PrepareContext(ctx, getConfigSQL); err != nil { |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
344 return |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
345 } |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
346 defer getStmt.Close() |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
347 |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
348 reconfigure := map[string]func(*http.Request){} |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
349 |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
350 for key, value := range *settings { |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
351 var old sql.NullString |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
352 err = getStmt.QueryRowContext(ctx, key).Scan(&old) |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
353 switch { |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
354 case err == sql.ErrNoRows: |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
355 old.Valid, err = false, nil |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
356 case err != nil: |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
357 return |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
358 } |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
359 |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
360 if cmp := reconfigureFunc(key); cmp != nil { |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
361 var fn func(*http.Request) |
3854
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
362 if fn, err = cmp(old, value); err != nil { |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
363 return |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
364 } |
3fcc4e11fc00
Validate the config values of the morpho classes when saving. Also don't trigger the expensive re-calculation of the contour lines if only the colors changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3834
diff
changeset
|
365 if fn != nil { |
3834
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
366 reconfigure[key] = fn |
d68c6be758b6
Only trigger the reconfiguation functions if the values have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3833
diff
changeset
|
367 } |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
368 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
369 |
3630
2467e619cf67
Fixed more SQL typos.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3629
diff
changeset
|
370 if _, err = setStmt.ExecContext(ctx, key, value); err != nil { |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
371 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
372 } |
3628
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
373 } |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
374 |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
375 if err = tx.Commit(); err != nil { |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
376 return |
6693be57b7a2
Re-worked the Go part a little bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3625
diff
changeset
|
377 } |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
378 |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
379 for _, fn := range reconfigure { |
4214
49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3929
diff
changeset
|
380 fn(req) |
3833
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
381 } |
70a881045efd
Trigger reconfiguration of GeoServer if the system settings were written.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3630
diff
changeset
|
382 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
383 jr = mw.JSONResult{ |
3625
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
384 Code: http.StatusCreated, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
385 Result: struct { |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
386 Result string `json:"result"` |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
387 }{"success"}, |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
388 } |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
389 return |
a688a478e35f
implemented configuration backend and frontend
Markus Kottlaender <markus@intevation.de>
parents:
3108
diff
changeset
|
390 } |