Mercurial > gemma
annotate pkg/geoserver/boot.go @ 4484:819eafe60f41
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Thu, 26 Sep 2019 12:16:23 +0200 |
parents | 69c54e2def2d |
children | 970e90d3d5eb |
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, |
4345
69c54e2def2d
Avoid unnecessary exceptions in GeoServer
Tom Gottfried <tom@intevation.de>
parents:
4342
diff
changeset
|
82 geoURL+"/rest/workspaces/"+workspaceName+".json?quietOnNotFound=true", |
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 { |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
118 err = fmt.Errorf("status code '%s' (%d)", |
386
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+ |
4345
69c54e2def2d
Avoid unnecessary exceptions in GeoServer
Tom Gottfried <tom@intevation.de>
parents:
4342
diff
changeset
|
138 "/datastores/"+datastoreName+".json?quietOnNotFound=true", |
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}, |
4285
6b415dcdaf8a
Let the geoserver expose primary keys for features.
Raimund Renkert <raimund@renkert.org>
parents:
4163
diff
changeset
|
176 {"Expose primary keys", true}, |
433
da05704e25c1
Removed templating from GeoServer startup SQL script.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
432
diff
changeset
|
177 {"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
|
178 {"Session close-up SQL", closeupSQL}, |
2990
dfeb2928232b
Let GeoServer validate database connections before use
Tom Gottfried <tom@intevation.de>
parents:
2624
diff
changeset
|
179 {"validate connections", true}, |
2624
9dbaf69c7a66
Improve geoserver config to better calculate bounding boxes
Bernhard Reiter <bernhard@intevation.de>
parents:
1466
diff
changeset
|
180 {"Estimated extends", false}, |
386
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 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
188 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
|
189 toStream(ds)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 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
|
196 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 return err |
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 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 if resp.StatusCode != http.StatusCreated { |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
201 err = fmt.Errorf("status code '%s' (%d)", |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 resp.StatusCode) |
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 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
209 func ensureFeatures() error { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
210 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
211 geoURL = config.GeoServerURL() |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
212 user = config.GeoServerUser() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
213 password = config.GeoServerPassword() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
214 auth = basicAuth(user, password) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
215 ) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
216 |
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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 } |
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
|
222 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
223 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
|
224 |
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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 } `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
|
230 } `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
|
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 |
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 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
|
234 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
|
235 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
|
236 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
|
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 } |
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 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
|
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 |
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 // 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
|
243 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
|
244 http.MethodGet, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
245 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
|
246 "/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
|
247 "/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
|
248 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 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
|
250 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
|
251 } |
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 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
|
253 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
|
254 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
|
255 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
|
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 |
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 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
|
259 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
|
260 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
|
261 // 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
|
262 // 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
|
263 // 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
|
264 // 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
|
265 // 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
|
266 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
|
267 } |
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
|
268 |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
269 var already []string |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
270 |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
271 defer func() { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
272 if len(already) > 0 { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
273 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
|
274 strings.Join(already, ", ")) |
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 }() |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
277 |
449
a74b8c2a4e75
Removed the command line option to publish tables with GeoServer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
444
diff
changeset
|
278 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
|
279 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
|
280 |
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
|
281 if hasFeature(table) { |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
282 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
|
283 continue |
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 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
286 // 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
|
287 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
|
288 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
289 // Create featuretype |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
290 ft := map[string]interface{}{ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
291 "featureType": map[string]interface{}{ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
292 "name": table, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
293 "nativeName": table, |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
294 "title": table, |
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 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
297 |
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
|
298 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
|
299 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
300 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
|
301 "/datastores/"+datastoreName+ |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
302 "/featuretypes", |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
303 toStream(ft)) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
304 if err != nil { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
305 return err |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
306 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
307 auth(req) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
308 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
|
309 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
|
310 if err != nil { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
311 return err |
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 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
314 if resp.StatusCode != http.StatusCreated { |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
315 return fmt.Errorf("status code '%s' (%d)", |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
316 http.StatusText(resp.StatusCode), |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
317 resp.StatusCode) |
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 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
321 return nil |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
322 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
323 |
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
|
324 func deleteWorkspace() error { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
325 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
326 // Should we delete our workspace first? |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
327 if !config.GeoServerClean() { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
328 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
329 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
330 |
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
|
331 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
|
332 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
333 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
|
334 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
|
335 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
|
336 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
|
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 |
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 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
|
340 http.MethodDelete, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
341 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
|
342 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 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
|
344 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
|
345 } |
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 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
|
347 _, 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
|
348 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
|
349 } |
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
|
350 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
351 type styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
352 Styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
353 Style []struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
354 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
|
355 } `json:"style"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
356 } `json:"styles"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
357 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
358 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
359 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
|
360 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
|
361 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
|
362 return true |
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 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
365 return false |
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 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
368 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
|
369 var ( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
370 geoURL = config.GeoServerURL() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
371 user = config.GeoServerUser() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
372 password = config.GeoServerPassword() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
373 auth = basicAuth(user, password) |
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 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
376 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
377 http.MethodGet, |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
378 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
|
379 nil) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
380 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
381 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
382 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
383 auth(req) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
384 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
|
385 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
386 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
387 } |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
388 defer resp.Body.Close() |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
389 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
390 // Fetch all styles |
1325
9d1f8e99743b
Removed empty if branch.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1032
diff
changeset
|
391 // 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
|
392 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
|
393 return nil |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
394 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
395 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
396 var ( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
397 stylePreprocessorsMu sync.Mutex |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
398 stylePreprocessors = map[string]func(string) (string, error){} |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
399 ) |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
400 |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
401 // RegisterStylePreprocessor stores a textual pre-processor |
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
402 // for a given style to be applied when the value of the |
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
403 // style changes. |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
404 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
|
405 stylePreprocessorsMu.Lock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
406 defer stylePreprocessorsMu.Unlock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
407 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
|
408 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
409 |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
410 // FindStylePreprocessor searches for a registed textual pre-processor |
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
411 // associated with a given style name. |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
412 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
|
413 stylePreprocessorsMu.Lock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
414 defer stylePreprocessorsMu.Unlock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
415 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
|
416 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
417 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
418 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
|
419 |
1032
4c0c4dd393de
Be more consistent with info/warn/error messages when logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
420 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
|
421 |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
422 // 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
|
423 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
|
424 if err != nil { |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
425 return err |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
426 } |
3827
6028326b88d6
go fmt'ed
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3825
diff
changeset
|
427 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
428 if processor := FindStylePreprocessor(entry.Name); processor != nil { |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
429 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
|
430 return err |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
431 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
432 } |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
433 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
434 var ( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
435 geoURL = config.GeoServerURL() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
436 user = config.GeoServerUser() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
437 password = config.GeoServerPassword() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
438 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
|
439 ) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
440 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
441 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
|
442 "/styles" |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
443 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
444 // First create style |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
445 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
446 type Style struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
447 Name string `json:"name"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
448 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
|
449 } |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
450 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
451 var styleFilename = struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
452 Style Style `json:"style"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
453 }{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
454 Style: Style{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
455 Name: entry.Name, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
456 Filename: entry.Name + ".sld", |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
457 }, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
458 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
459 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
460 if create { |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
461 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
462 http.MethodPost, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
463 styleURL, |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
464 toStream(&styleFilename)) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
465 |
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 auth(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
470 asJSON(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
471 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
|
472 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
473 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
474 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
475 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
476 if resp.StatusCode != http.StatusCreated { |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
477 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
|
478 entry.Name, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
479 http.StatusText(resp.StatusCode)) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
480 } |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
481 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
482 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
483 // Second upload data |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
484 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
485 req, err := http.NewRequest( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
486 http.MethodPut, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
487 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
|
488 strings.NewReader(data)) |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
489 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
490 return err |
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 auth(req) |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
493 if isSymbologyEncoding(data) { |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
494 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
|
495 } else { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
496 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
|
497 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
498 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
|
499 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
500 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
501 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
502 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
503 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
|
504 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
|
505 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
|
506 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
507 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
508 // 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
|
509 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
510 req, err = http.NewRequest( |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
511 http.MethodPost, |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
512 geoURL+"/rest/layers/"+ |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
513 url.PathEscape(workspaceName+":"+entry.Name)+ |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
514 "/styles?default=true", |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
515 toStream(&styleFilename)) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
516 if err != nil { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
517 return err |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
518 } |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
519 auth(req) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
520 asJSON(req) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
521 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
522 resp, err = http.DefaultClient.Do(req) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
523 if err != nil { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
524 return err |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
525 } |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
526 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
527 if resp.StatusCode != http.StatusCreated { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
528 return fmt.Errorf("cannot connect style %s with layer (%s)", |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
529 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
|
530 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
531 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
532 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
533 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
534 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
535 // 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
|
536 func isSymbologyEncoding(data string) bool { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
537 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
|
538 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
|
539 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
540 for { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
541 tok, err := decoder.Token() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
542 switch { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
543 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
|
544 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
545 case err != nil: |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
546 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
|
547 return false |
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 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
|
550 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
|
551 return true |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
552 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
553 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
554 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
555 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
556 func ensureStyles() error { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
557 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
|
558 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
559 var stls styles |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
560 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
|
561 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
562 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
563 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
564 entries := models.InternalServices.Filter( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
565 models.IntAnd( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
566 models.IntWMS, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
567 models.IntWithStyle)) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
568 |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
569 var already []string |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
570 |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
571 defer func() { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
572 if len(already) > 0 { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
573 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
|
574 strings.Join(already, ", ")) |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
575 } |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
576 }() |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
577 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
578 for i := range entries { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
579 entry := &entries[i] |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
580 if stls.hasStyle(entry.Name) { |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
581 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
|
582 continue |
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 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
|
585 return err |
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 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
588 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
589 return nil |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
590 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
591 |
1466
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
592 // 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
|
593 // 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
|
594 func PrepareGeoServer() error { |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
595 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
596 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
|
597 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
|
598 return nil |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
599 } |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
600 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
601 if config.GeoServerURL() == "" { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
602 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
|
603 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
604 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
605 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
606 for _, ensure := range []func() error{ |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
607 deleteWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
608 ensureWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
609 ensureDataStore, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
610 ensureFeatures, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
611 ensureStyles, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
612 } { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
613 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
|
614 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
|
615 } |
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
|
616 } |
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
|
617 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
618 return nil |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
619 } |