Mercurial > gemma
annotate pkg/geoserver/boot.go @ 4087:1562a5fb36dc
Handle Nash-Sutcliff more tolerant for NaN/Inf values.
Due to limitation of JSON we encode these values as 0 and +/- MaxFloat64.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 25 Jul 2019 17:15:00 +0200 |
parents | 885eb90255ff |
children | 51cfa54fc5b1 |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
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:
915
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:
915
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
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:
915
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:
915
diff
changeset
|
6 // |
2624
9dbaf69c7a66
Improve geoserver config to better calculate bounding boxes
Bernhard Reiter <bernhard@intevation.de>
parents:
1466
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:
915
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
915
diff
changeset
|
13 |
868
aa8f30c1ed27
Moved GeoServer configuration to own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
559
diff
changeset
|
14 package geoserver |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
3827
6028326b88d6
go fmt'ed
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3825
diff
changeset
|
17 "bytes" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "encoding/json" |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
19 "encoding/xml" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "fmt" |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
21 "io" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "log" |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "net/http" |
868
aa8f30c1ed27
Moved GeoServer configuration to own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
559
diff
changeset
|
24 "net/url" |
417
ff26ffc18a04
Minor: Removed unnecessary byte slice conversion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
25 "strings" |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
26 "sync" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
3093
fd14f149696c
GeoServer style import: Be aware that the uploaded style could be in other encodings than UTF-8.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2990
diff
changeset
|
28 "golang.org/x/net/html/charset" |
fd14f149696c
GeoServer style import: Be aware that the uploaded style could be in other encodings than UTF-8.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2990
diff
changeset
|
29 |
414
c1047fd04a3a
Moved project specific Go packages to new pkg folder.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
398
diff
changeset
|
30 "gemma.intevation.de/gemma/pkg/config" |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
435
diff
changeset
|
31 "gemma.intevation.de/gemma/pkg/models" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 const ( |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
35 workspaceName = "gemma" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
36 datastoreName = "gemma" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
37 databaseScheme = "waterway" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
38 databaseType = "postgis" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
39 primaryKeyMetadataTbl = "waterway.gt_pk_metadata" |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
40 ) |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
41 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
42 const ( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
43 startupSQL = `SELECT public.setrole('${user,'||encode('waterway_user', 'hex')||'}')` |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
44 closeupSQL = `RESET ROLE` |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
45 ) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 func basicAuth(user, password string) func(req *http.Request) { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 return func(req *http.Request) { |
559
f827dc4f3e95
Use stdlib for basic auth instead og home brew in GeoServer config.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
49 req.SetBasicAuth(user, password) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
53 func toStream(x interface{}) io.Reader { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
54 var buf bytes.Buffer |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
55 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
56 if err := json.NewEncoder(&buf).Encode(x); err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
57 // Should not happen |
1032
4c0c4dd393de
Be more consistent with info/warn/error messages when logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
58 log.Printf("warn: bad JSON: %v\n", err) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
59 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
60 return bytes.NewReader(buf.Bytes()) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
61 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
62 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 func asJSON(req *http.Request) { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 req.Header.Set("Content-Type", "application/json") |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
67 func asContentType(req *http.Request, contentType string) { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
68 req.Header.Set("Content-Type", contentType) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
69 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
70 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 func ensureWorkspace() error { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
73 geoURL = config.GeoServerURL() |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 user = config.GeoServerUser() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 password = config.GeoServerPassword() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 auth = basicAuth(user, password) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 // Probe workspace. |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 req, err := http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 http.MethodGet, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
82 geoURL+"/rest/workspaces/"+workspaceName+".json", |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 nil) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 resp, err := http.DefaultClient.Do(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 if resp.StatusCode != http.StatusNotFound { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 log.Println("info: workspace " + workspaceName + " already exists.") |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 // Create workspace |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
99 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
100 log.Println("info: creating workspace " + workspaceName) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
101 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 const createJSON = `{"workspace":{"name":"` + workspaceName + `"}}` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
106 geoURL+"/rest/workspaces", |
417
ff26ffc18a04
Minor: Removed unnecessary byte slice conversion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
107 strings.NewReader(createJSON)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 if resp, err = http.DefaultClient.Do(req); err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 if resp.StatusCode != http.StatusCreated { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 err = fmt.Errorf("Status code '%s' (%d)", |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 resp.StatusCode) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 func ensureDataStore() error { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
128 geoURL = config.GeoServerURL() |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 user = config.GeoServerUser() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 password = config.GeoServerPassword() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 auth = basicAuth(user, password) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
134 // Probe datastore. |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 req, err := http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 http.MethodGet, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
137 geoURL+"/rest/workspaces/"+workspaceName+ |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
138 "/datastores/"+datastoreName+".json", |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 nil) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 resp, err := http.DefaultClient.Do(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 if resp.StatusCode != http.StatusNotFound { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 log.Println("info: datastore " + datastoreName + " already exists.") |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
154 // Create datastore. |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
155 log.Println("info: creating datastore " + datastoreName) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
156 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 type entry struct { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 Key interface{} `json:"@key"` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 Value interface{} `json:"$"` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 // Create datastore. |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 ds := map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 "dataStore": map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 "name": datastoreName, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 "connectionParameters": map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 "entry": []entry{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 {"host", config.DBHost()}, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 {"port", config.DBPort()}, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
170 {"database", config.DBName()}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 {"schema", databaseScheme}, |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
172 {"user", config.DBUser()}, |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
173 {"passwd", config.DBPassword()}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 {"dbtype", databaseType}, |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
175 {"Primary key metadata table", primaryKeyMetadataTbl}, |
433
da05704e25c1
Removed templating from GeoServer startup SQL script.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
432
diff
changeset
|
176 {"Session startup SQL", startupSQL}, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
177 {"Session close-up SQL", closeupSQL}, |
2990
dfeb2928232b
Let GeoServer validate database connections before use
Tom Gottfried <tom@intevation.de>
parents:
2624
diff
changeset
|
178 {"validate connections", true}, |
2624
9dbaf69c7a66
Improve geoserver config to better calculate bounding boxes
Bernhard Reiter <bernhard@intevation.de>
parents:
1466
diff
changeset
|
179 {"Estimated extends", false}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
187 geoURL+"/rest/workspaces/"+workspaceName+"/datastores", |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
188 toStream(ds)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 resp, err = http.DefaultClient.Do(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 if resp.StatusCode != http.StatusCreated { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 err = fmt.Errorf("Status code '%s' (%d)", |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 resp.StatusCode) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
208 func ensureFeatures() error { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
209 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
210 geoURL = config.GeoServerURL() |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
211 user = config.GeoServerUser() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
212 password = config.GeoServerPassword() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
213 auth = basicAuth(user, password) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
214 ) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
215 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
467
diff
changeset
|
216 tables := models.InternalServices.Filter(models.IntWFS) |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
217 if len(tables) == 0 { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
218 log.Println("info: no tables to publish") |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
219 return nil |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
220 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
221 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
222 log.Printf("info: number of tables to publish %d\n", len(tables)) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
223 |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
224 var features struct { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
225 FeatureTypes struct { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
226 FeatureType []struct { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
227 Name string `json:"name"` |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
228 } `json:"featureType"` |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
229 } `json:"featureTypes"` |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
230 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
231 |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
232 hasFeature := func(name string) bool { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
233 for _, ft := range features.FeatureTypes.FeatureType { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
234 if ft.Name == name { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
235 return true |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
236 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
237 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
238 return false |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
239 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
240 |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
241 // Fetch all featuretypes. |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
242 req, err := http.NewRequest( |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
243 http.MethodGet, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
244 geoURL+"/rest/workspaces/"+workspaceName+ |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
245 "/datastores/"+datastoreName+ |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
246 "/featuretypes.json", |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
247 nil) |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
248 if err != nil { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
249 return err |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
250 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
251 auth(req) |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
252 resp, err := http.DefaultClient.Do(req) |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
253 if err != nil { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
254 return err |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
255 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
256 |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
257 err = json.NewDecoder(resp.Body).Decode(&features) |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
258 resp.Body.Close() |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
259 if err != nil { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
260 // XXX: Quirk in the JSON return by GeoServer: |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
261 // If there are no features in the datastore |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
262 // featureType deserializes to an empty string "" |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
263 // instead of an empty array *palmface*. |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
264 // So assume there no features. |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
265 hasFeature = func(string) bool { return false } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
266 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
267 |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
268 var already []string |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
269 |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
270 defer func() { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
271 if len(already) > 0 { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
272 log.Printf("info: already having featuretypes: %s\n", |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
273 strings.Join(already, ", ")) |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
274 } |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
275 }() |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
276 |
449
a74b8c2a4e75
Removed the command line option to publish tables with GeoServer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
444
diff
changeset
|
277 for i := range tables { |
a74b8c2a4e75
Removed the command line option to publish tables with GeoServer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
444
diff
changeset
|
278 table := tables[i].Name |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
435
diff
changeset
|
279 |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
280 if hasFeature(table) { |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
281 already = append(already, table) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
282 continue |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
283 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
284 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
285 // Create featuretype. |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
286 log.Printf("info: creating featuretype %s.\n", table) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
287 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
288 // Create featuretype |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
289 ft := map[string]interface{}{ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
290 "featureType": map[string]interface{}{ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
291 "name": table, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
292 "nativeName": table, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
293 "title": table, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
294 }, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
295 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
296 |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
297 req, err := http.NewRequest( |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
298 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
299 geoURL+"/rest/workspaces/"+workspaceName+ |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
300 "/datastores/"+datastoreName+ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
301 "/featuretypes", |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
302 toStream(ft)) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
303 if err != nil { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
304 return err |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
305 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
306 auth(req) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
307 asJSON(req) |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
308 resp, err := http.DefaultClient.Do(req) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
309 if err != nil { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
310 return err |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
311 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
312 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
313 if resp.StatusCode != http.StatusCreated { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
314 return fmt.Errorf("Status code '%s' (%d)", |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
315 http.StatusText(resp.StatusCode), |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
316 resp.StatusCode) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
317 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
318 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
319 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
320 return nil |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
321 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
322 |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
323 func deleteWorkspace() error { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
324 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
325 // Should we delete our workspace first? |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
326 if !config.GeoServerClean() { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
327 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
328 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
329 |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
330 log.Println("info: delete workspace " + workspaceName) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
331 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
332 geoURL = config.GeoServerURL() |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
333 user = config.GeoServerUser() |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
334 password = config.GeoServerPassword() |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
335 auth = basicAuth(user, password) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
336 ) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
337 |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
338 req, err := http.NewRequest( |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
339 http.MethodDelete, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
340 geoURL+"/rest/workspaces/"+workspaceName+"?recurse=true", |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
341 nil) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
342 if err != nil { |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
343 return err |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
344 } |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
345 auth(req) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
346 _, err = http.DefaultClient.Do(req) |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
347 return err |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
348 } |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
349 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
350 type styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
351 Styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
352 Style []struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
353 Name string `json:"name"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
354 } `json:"style"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
355 } `json:"styles"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
356 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
357 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
358 func (s *styles) hasStyle(name string) bool { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
359 for i := range s.Styles.Style { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
360 if s.Styles.Style[i].Name == name { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
361 return true |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
362 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
363 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
364 return false |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
365 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
366 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
367 func (s *styles) load() error { |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
368 var ( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
369 geoURL = config.GeoServerURL() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
370 user = config.GeoServerUser() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
371 password = config.GeoServerPassword() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
372 auth = basicAuth(user, password) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
373 ) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
374 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
375 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
376 http.MethodGet, |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
377 geoURL+"/rest/workspaces/"+workspaceName+"/styles.json", |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
378 nil) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
379 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
380 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
381 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
382 auth(req) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
383 resp, err := http.DefaultClient.Do(req) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
384 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
385 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
386 } |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
387 defer resp.Body.Close() |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
388 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
389 // Fetch all styles |
1325
9d1f8e99743b
Removed empty if branch.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1032
diff
changeset
|
390 // XXX: Avoid error checking due to quirks with featuretypes. |
9d1f8e99743b
Removed empty if branch.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1032
diff
changeset
|
391 json.NewDecoder(resp.Body).Decode(s) |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
392 return nil |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
393 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
394 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
395 var ( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
396 stylePreprocessorsMu sync.Mutex |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
397 stylePreprocessors = map[string]func(string) (string, error){} |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
398 ) |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
399 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
400 func RegisterStylePreprocessor(name string, processor func(string) (string, error)) { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
401 stylePreprocessorsMu.Lock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
402 defer stylePreprocessorsMu.Unlock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
403 stylePreprocessors[name] = processor |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
404 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
405 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
406 func FindStylePreprocessor(name string) func(string) (string, error) { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
407 stylePreprocessorsMu.Lock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
408 defer stylePreprocessorsMu.Unlock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
409 return stylePreprocessors[name] |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
410 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
411 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
412 func updateStyle(entry *models.IntEntry, create bool) error { |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
413 |
1032
4c0c4dd393de
Be more consistent with info/warn/error messages when logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
414 log.Printf("info: creating style %s\n", entry.Name) |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
415 |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
416 // Try to load the style data. |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
417 data, err := entry.LoadStyle() |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
418 if err != nil { |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
419 return err |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
420 } |
3827
6028326b88d6
go fmt'ed
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3825
diff
changeset
|
421 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
422 if processor := FindStylePreprocessor(entry.Name); processor != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
423 if data, err = processor(data); err != nil { |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
424 return err |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
425 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
426 } |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
427 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
428 var ( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
429 geoURL = config.GeoServerURL() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
430 user = config.GeoServerUser() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
431 password = config.GeoServerPassword() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
432 auth = basicAuth(user, password) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
433 ) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
434 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
435 styleURL := geoURL + "/rest/workspaces/" + workspaceName + |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
436 "/styles" |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
437 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
438 // First create style |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
439 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
440 type Style struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
441 Name string `json:"name"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
442 Filename string `json:"filename"` |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
443 } |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
444 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
445 var styleFilename = struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
446 Style Style `json:"style"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
447 }{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
448 Style: Style{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
449 Name: entry.Name, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
450 Filename: entry.Name + ".sld", |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
451 }, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
452 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
453 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
454 if create { |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
455 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
456 http.MethodPost, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
457 styleURL, |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
458 toStream(&styleFilename)) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
459 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
460 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
461 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
462 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
463 auth(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
464 asJSON(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
465 resp, err := http.DefaultClient.Do(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
466 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
467 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
468 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
469 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
470 if resp.StatusCode != http.StatusCreated { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
471 return fmt.Errorf("Unable to create style %s (%s)", |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
472 entry.Name, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
473 http.StatusText(resp.StatusCode)) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
474 } |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
475 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
476 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
477 // Second upload data |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
478 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
479 req, err := http.NewRequest( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
480 http.MethodPut, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
481 styleURL+"/"+url.PathEscape(entry.Name), |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
482 strings.NewReader(data)) |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
483 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
484 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
485 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
486 auth(req) |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
487 if isSymbologyEncoding(data) { |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
488 asContentType(req, "application/vnd.ogc.se+xml") |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
489 } else { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
490 asContentType(req, "application/vnd.ogc.sld+xml") |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
491 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
492 resp, err := http.DefaultClient.Do(req) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
493 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
494 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
495 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
496 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
497 if resp.StatusCode != http.StatusOK { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
498 return fmt.Errorf("cannot upload style %s (%s)", |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
499 entry.Name, http.StatusText(resp.StatusCode)) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
500 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
501 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
502 // Third associate with layer |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
503 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
504 if create { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
505 req, err := http.NewRequest( |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
506 http.MethodPost, |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
507 geoURL+"/rest/layers/"+ |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
508 url.PathEscape(workspaceName+":"+entry.Name)+ |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
509 "/styles?default=true", |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
510 toStream(&styleFilename)) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
511 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
512 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
513 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
514 auth(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
515 asJSON(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
516 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
517 resp, err = http.DefaultClient.Do(req) |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
518 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
519 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
520 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
521 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
522 if resp.StatusCode != http.StatusCreated { |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
523 return fmt.Errorf("cannot connect style %s with layer (%s)", |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
524 entry.Name, http.StatusText(resp.StatusCode)) |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
525 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
526 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
527 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
528 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
529 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
530 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
531 // isSymbologyEncoding tries to figure out if its plain SLD or SE. |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
532 func isSymbologyEncoding(data string) bool { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
533 decoder := xml.NewDecoder(strings.NewReader(data)) |
3093
fd14f149696c
GeoServer style import: Be aware that the uploaded style could be in other encodings than UTF-8.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2990
diff
changeset
|
534 decoder.CharsetReader = charset.NewReaderLabel |
fd14f149696c
GeoServer style import: Be aware that the uploaded style could be in other encodings than UTF-8.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2990
diff
changeset
|
535 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
536 for { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
537 tok, err := decoder.Token() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
538 switch { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
539 case tok == nil && err == io.EOF: |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
540 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
541 case err != nil: |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
542 log.Printf("warn: invalid XML: %v\n", err) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
543 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
544 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
545 if t, ok := tok.(xml.StartElement); ok && |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
546 t.Name.Space == "http://www.opengis.net/se" { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
547 return true |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
548 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
549 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
550 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
551 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
552 func ensureStyles() error { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
553 log.Println("info: creating styles") |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
554 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
555 var stls styles |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
556 if err := stls.load(); err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
557 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
558 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
559 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
560 entries := models.InternalServices.Filter( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
561 models.IntAnd( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
562 models.IntWMS, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
563 models.IntWithStyle)) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
564 |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
565 var already []string |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
566 |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
567 defer func() { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
568 if len(already) > 0 { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
569 log.Printf("info: already having styles: %s\n", |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
570 strings.Join(already, ", ")) |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
571 } |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
572 }() |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
573 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
574 for i := range entries { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
575 entry := &entries[i] |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
576 if stls.hasStyle(entry.Name) { |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
577 already = append(already, entry.Name) |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
578 continue |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
579 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
580 if err := updateStyle(entry, true); err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
581 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
582 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
583 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
584 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
585 return nil |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
586 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
587 |
1466
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
588 // PrepareGeoServer sets up the GeoServer to work together with the gemma server. |
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
589 // It sets up a workspace, a datastore and exposes the features and styles. |
890
0a563fef64a9
Reconfiguring GeoServer is now queued async.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
878
diff
changeset
|
590 func PrepareGeoServer() error { |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
591 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
592 if config.DBUser() == "" { |
435
7d2afdc263b5
Don't panic if we have no metamorphic db user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
433
diff
changeset
|
593 log.Println("info: Need metamorphic db user to configure GeoServer") |
432
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
594 return nil |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
595 } |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
596 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
597 if config.GeoServerURL() == "" { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
598 log.Println("info: No URL to GeoServer configured") |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
599 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
600 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
601 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
602 for _, ensure := range []func() error{ |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
603 deleteWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
604 ensureWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
605 ensureDataStore, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
606 ensureFeatures, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
607 ensureStyles, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
608 } { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
609 if err := ensure(); err != nil { |
874
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
610 return err |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
611 } |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
612 } |
da526b58c9c4
Added a flag geoserver-clean to force deletion of the gemma workspace before configuring the GeoServer again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
868
diff
changeset
|
613 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
614 return nil |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
615 } |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
616 |
1466
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
617 // ReconfigureStyle returns a function to update a style |
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
618 // in the GeoServer to be in sync with the database. |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
619 func ReconfigureStyle(name string) { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
620 Reconfigure(func() error { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
621 var stls styles |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
622 if err := stls.load(); err != nil { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
623 return err |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
624 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
625 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
626 entries := models.InternalServices.Filter( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
627 models.IntAnd( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
628 models.IntWMS, |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
629 models.IntWithStyle, |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
630 models.IntByName(name))) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
631 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
632 for i := range entries { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
633 entry := &entries[i] |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
634 create := !stls.hasStyle(entry.Name) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
635 if err := updateStyle(entry, create); err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
636 return err |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
637 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
638 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
639 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
640 return nil |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
641 }) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
642 } |