Mercurial > gemma
annotate pkg/geoserver/boot.go @ 5311:72d3b8321ed0 zpg-exception
Fixed broken migration which erased the style of the modified GeoServer view.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 02 Jun 2021 16:55:00 +0200 |
parents | 5df1eff5e445 |
children | 345515bc4548 |
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 ( |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
17 "archive/zip" |
3827
6028326b88d6
go fmt'ed
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3825
diff
changeset
|
18 "bytes" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "encoding/json" |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
20 "encoding/xml" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "fmt" |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
22 "io" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "log" |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "net/http" |
868
aa8f30c1ed27
Moved GeoServer configuration to own package.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
559
diff
changeset
|
25 "net/url" |
417
ff26ffc18a04
Minor: Removed unnecessary byte slice conversion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
26 "strings" |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
27 "sync" |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
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
|
29 "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
|
30 |
414
c1047fd04a3a
Moved project specific Go packages to new pkg folder.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
398
diff
changeset
|
31 "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
|
32 "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
|
33 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 const ( |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
36 workspaceName = "gemma" |
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
37 datastoreName = "gemma" |
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 |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
63 // XXX: Creating SQL views with JSON via GeoServer REST-API fails |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
64 // Begin code for handling with XML instead |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
65 func toXMLStream(x interface{}) io.Reader { |
4609 | 66 buf := bytes.NewBufferString(xml.Header) |
67 if err := xml.NewEncoder(buf).Encode(x); err != nil { | |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
68 // Should not happen |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
69 log.Printf("warn: bad XML: %v\n", err) |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
70 } |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
71 return bytes.NewReader(buf.Bytes()) |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
72 } |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
73 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 func asJSON(req *http.Request) { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 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
|
76 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
78 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
|
79 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
|
80 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
81 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 func ensureWorkspace() error { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
84 geoURL = config.GeoServerURL() |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 user = config.GeoServerUser() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 password = config.GeoServerPassword() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 auth = basicAuth(user, password) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 // Probe workspace. |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 req, err := http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 http.MethodGet, |
4345
69c54e2def2d
Avoid unnecessary exceptions in GeoServer
Tom Gottfried <tom@intevation.de>
parents:
4342
diff
changeset
|
93 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
|
94 nil) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 return err |
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 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 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
|
100 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
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 if resp.StatusCode != http.StatusNotFound { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 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
|
106 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 // Create workspace |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
110 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
111 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
|
112 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 const createJSON = `{"workspace":{"name":"` + workspaceName + `"}}` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
117 geoURL+"/rest/workspaces", |
417
ff26ffc18a04
Minor: Removed unnecessary byte slice conversion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
118 strings.NewReader(createJSON)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 return err |
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 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 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
|
125 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 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
|
129 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
|
130 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 resp.StatusCode) |
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 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 func ensureDataStore() error { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
139 geoURL = config.GeoServerURL() |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 user = config.GeoServerUser() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 password = config.GeoServerPassword() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 auth = basicAuth(user, password) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
145 // Probe datastore. |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 req, err := http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 http.MethodGet, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
148 geoURL+"/rest/workspaces/"+workspaceName+ |
4345
69c54e2def2d
Avoid unnecessary exceptions in GeoServer
Tom Gottfried <tom@intevation.de>
parents:
4342
diff
changeset
|
149 "/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
|
150 nil) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 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
|
156 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 if resp.StatusCode != http.StatusNotFound { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 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
|
162 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
165 // Create datastore. |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
166 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
|
167 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 type entry struct { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 Key interface{} `json:"@key"` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 Value interface{} `json:"$"` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 // Create datastore. |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 ds := map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 "dataStore": map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 "name": datastoreName, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 "connectionParameters": map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 "entry": []entry{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 {"host", config.DBHost()}, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 {"port", config.DBPort()}, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
181 {"database", config.DBName()}, |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
182 {"schema", models.DatabaseScheme}, |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
183 {"user", config.DBUser()}, |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
184 {"passwd", config.DBPassword()}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 {"dbtype", databaseType}, |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
186 {"Primary key metadata table", primaryKeyMetadataTbl}, |
4285
6b415dcdaf8a
Let the geoserver expose primary keys for features.
Raimund Renkert <raimund@renkert.org>
parents:
4163
diff
changeset
|
187 {"Expose primary keys", true}, |
4624
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
4614
diff
changeset
|
188 {"Session startup SQL", |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
4614
diff
changeset
|
189 config.GeoServerStartupSQL() + ";" + startupSQL}, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
190 {"Session close-up SQL", closeupSQL}, |
2990
dfeb2928232b
Let GeoServer validate database connections before use
Tom Gottfried <tom@intevation.de>
parents:
2624
diff
changeset
|
191 {"validate connections", true}, |
2624
9dbaf69c7a66
Improve geoserver config to better calculate bounding boxes
Bernhard Reiter <bernhard@intevation.de>
parents:
1466
diff
changeset
|
192 {"Estimated extends", false}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
200 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
|
201 toStream(ds)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 return err |
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 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 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
|
208 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 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
|
213 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
|
214 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 resp.StatusCode) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
221 func ensureFeatures() error { |
4936
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
222 tables := models.InternalServices.Filter(models.IntWFS) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
223 if len(tables) == 0 { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
224 log.Println("info: no tables to publish") |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
225 return nil |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
226 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
227 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
228 log.Printf("info: number of tables to publish %d\n", len(tables)) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
229 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
230 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
231 geoURL = config.GeoServerURL() |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
232 user = config.GeoServerUser() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
233 password = config.GeoServerPassword() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
234 auth = basicAuth(user, password) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
235 ) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
236 |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
237 datastoreURL := geoURL + "/rest/workspaces/" + workspaceName + |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
238 "/datastores/" + datastoreName |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
239 |
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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 } `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
|
245 } `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
|
246 } |
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 |
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 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
|
249 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
|
250 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
|
251 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
|
252 } |
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 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
254 return 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
|
255 } |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
256 |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
257 // 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
|
258 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
|
259 http.MethodGet, |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
260 datastoreURL+"/featuretypes.json", |
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
|
261 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
|
262 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
|
263 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
|
264 } |
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 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
|
266 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
|
267 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
|
268 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
|
269 } |
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
|
270 |
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
|
271 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
|
272 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
|
273 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
|
274 // 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
|
275 // 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
|
276 // 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
|
277 // 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
|
278 // 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
|
279 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
|
280 } |
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 |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
282 var already []string |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
283 |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
284 defer func() { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
285 if len(already) > 0 { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
286 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
|
287 strings.Join(already, ", ")) |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
288 } |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
289 }() |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
290 |
449
a74b8c2a4e75
Removed the command line option to publish tables with GeoServer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
444
diff
changeset
|
291 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
|
292 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
|
293 |
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
|
294 if hasFeature(table) { |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
295 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
|
296 continue |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
297 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
298 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
299 // 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
|
300 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
|
301 |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
302 var req *http.Request |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
303 |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
304 ft := map[string]interface{}{ |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
305 "name": table, |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
306 "nativeName": table, |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
307 "title": table, |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
308 } |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
309 if srs := tables[i].SRS; srs != nil { |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
310 ft["srs"] = *srs |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
311 } |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
312 |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
313 var entries []map[string]interface{} |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
314 |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
315 if models.IntSQLView(tables[i]) { |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
316 vt := map[string]interface{}{ |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
317 "name": table, |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
318 "sql": *tables[i].SQL, |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
319 } |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
320 if kc := tables[i].KeyColumn; kc != nil { |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
321 vt["keyColumn"] = *kc |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
322 } |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
323 entry := map[string]interface{}{ |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
324 "@key": "JDBC_VIRTUAL_TABLE", |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
325 "virtualTable": vt, |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
326 } |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
327 entries = append(entries, entry) |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
328 } |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
329 |
4995
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4988
diff
changeset
|
330 if attr := tables[i].WMSTAttribute; attr != nil { |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
331 di := map[string]interface{}{ |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
332 "enabled": true, |
4995
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4988
diff
changeset
|
333 "attribute": *attr, |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
334 "presentation": "CONTINUOUS_INTERVAL", |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
335 "units": "ISO8601", |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
336 "nearestMatchEnabled": false, |
5000
2b577e1c5b95
Cosmetics: sharpen type knife a bit.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4999
diff
changeset
|
337 "defaultValue": map[string]string{ |
4999
bfaf7621d0ad
Set default value for time dimension on published services
Tom Gottfried <tom@intevation.de>
parents:
4995
diff
changeset
|
338 "strategy": "FIXED", |
bfaf7621d0ad
Set default value for time dimension on published services
Tom Gottfried <tom@intevation.de>
parents:
4995
diff
changeset
|
339 "referenceValue": "PT1M/PRESENT", |
bfaf7621d0ad
Set default value for time dimension on published services
Tom Gottfried <tom@intevation.de>
parents:
4995
diff
changeset
|
340 }, |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
341 } |
4995
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4988
diff
changeset
|
342 if endAttr := tables[i].WMSTEndAttribute; endAttr != nil { |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4988
diff
changeset
|
343 di["endAttribute"] = *endAttr |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4988
diff
changeset
|
344 } |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
345 entry := map[string]interface{}{ |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
346 "@key": "time", |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
347 "dimensionInfo": di, |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
348 } |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
349 entries = append(entries, entry) |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
350 } |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
351 |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
352 if len(entries) > 0 { |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
353 ft["metadata"] = map[string]interface{}{ |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
354 "entry": entries, |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
355 } |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
356 } |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
357 |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
358 doc := map[string]interface{}{ |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
359 "featureType": ft, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
360 } |
4988
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
361 |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
362 req, err = http.NewRequest( |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
363 http.MethodPost, |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
364 datastoreURL+"/featuretypes", |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
365 toStream(doc)) |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
366 if err != nil { |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
367 return err |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
368 } |
61eb65394a13
Only use JSON path when configure feature layers with Geoserver REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4937
diff
changeset
|
369 asJSON(req) |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
370 auth(req) |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
371 |
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
|
372 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
|
373 if err != nil { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
374 return err |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
375 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
376 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
377 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
|
378 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
|
379 http.StatusText(resp.StatusCode), |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
380 resp.StatusCode) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
381 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
382 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
383 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
384 return nil |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
385 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
386 |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
387 func ensureLayerGroups() error { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
388 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
389 groups := models.InternalServices.LayerGroups() |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
390 if len(groups) == 0 { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
391 log.Println("info: no groups layers to publish") |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
392 return nil |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
393 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
394 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
395 log.Printf("info: number of layer groups to publish %d\n", len(groups)) |
4936
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
396 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
397 var ( |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
398 geoURL = config.GeoServerURL() |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
399 user = config.GeoServerUser() |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
400 password = config.GeoServerPassword() |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
401 auth = basicAuth(user, password) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
402 ) |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
403 |
4936
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
404 type layerGroups struct { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
405 LayerGroups struct { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
406 LayerGroup []struct { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
407 Name string `json:"name"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
408 } `json:"layerGroup"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
409 } `json:"layerGroups"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
410 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
411 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
412 var lg layerGroups |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
413 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
414 hasLayerGroup := func(name string) bool { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
415 for i := range lg.LayerGroups.LayerGroup { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
416 if lg.LayerGroups.LayerGroup[i].Name == name { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
417 return true |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
418 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
419 } |
4936
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
420 return false |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
421 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
422 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
423 layerGroupsURL := geoURL + "/rest/workspaces/" + workspaceName + |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
424 "/layergroups" |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
425 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
426 // Fetch all layer groups. |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
427 req, err := http.NewRequest( |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
428 http.MethodGet, |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
429 layerGroupsURL+".json", |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
430 nil) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
431 if err != nil { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
432 return err |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
433 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
434 auth(req) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
435 resp, err := http.DefaultClient.Do(req) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
436 if err != nil { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
437 return err |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
438 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
439 |
5262
5df1eff5e445
Made staticcheck a little happier.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5000
diff
changeset
|
440 // XXX: ignore the error |
5df1eff5e445
Made staticcheck a little happier.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
5000
diff
changeset
|
441 _ = json.NewDecoder(resp.Body).Decode(&lg) |
4936
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
442 resp.Body.Close() |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
443 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
444 var already []string |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
445 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
446 defer func() { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
447 if len(already) > 0 { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
448 log.Printf("info: already having layer groups: %s\n", |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
449 strings.Join(already, ", ")) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
450 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
451 }() |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
452 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
453 for i := range groups { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
454 if hasLayerGroup(groups[i].Name) { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
455 already = append(already, groups[i].Name) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
456 continue |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
457 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
458 |
4937
40da1b8aba01
Made logging a bit more symmetric when cleating layer groups with GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4936
diff
changeset
|
459 log.Printf("info: creating layer group %s.\n", groups[i].Name) |
40da1b8aba01
Made logging a bit more symmetric when cleating layer groups with GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4936
diff
changeset
|
460 |
4936
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
461 type ( |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
462 Layers struct { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
463 Layer []string `xml:"layer"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
464 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
465 Styles struct { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
466 Style []string `xml:"style"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
467 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
468 LayerGroup struct { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
469 XMLName xml.Name `xml:"layerGroup"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
470 Name string `xml:"name"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
471 Title string `xml:"title"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
472 Layers Layers `xml:"layers"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
473 Styles Styles `xml:"styles"` |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
474 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
475 ) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
476 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
477 lgr := LayerGroup{ |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
478 Name: groups[i].Name, |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
479 Title: groups[i].Name, |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
480 Layers: Layers{ |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
481 Layer: groups[i].Layers, |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
482 }, |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
483 Styles: Styles{ |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
484 Style: groups[i].Layers, |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
485 }, |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
486 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
487 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
488 req, err = http.NewRequest( |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
489 http.MethodPost, |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
490 layerGroupsURL+".xml", |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
491 toXMLStream(&lgr)) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
492 if err != nil { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
493 return err |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
494 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
495 asContentType(req, "text/xml") |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
496 auth(req) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
497 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
498 resp, err := http.DefaultClient.Do(req) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
499 if err != nil { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
500 return err |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
501 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
502 |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
503 if resp.StatusCode != http.StatusCreated { |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
504 return fmt.Errorf("status code '%s' (%d)", |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
505 http.StatusText(resp.StatusCode), |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
506 resp.StatusCode) |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
507 } |
21a48e2d2260
Create group layers in GeoServer via REST calls.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
508 } |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
509 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
510 return nil |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
511 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
512 |
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
|
513 func deleteWorkspace() error { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
514 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
515 // Should we delete our workspace first? |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
516 if !config.GeoServerClean() { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
517 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
518 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
519 |
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
|
520 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
|
521 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
522 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
|
523 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
|
524 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
|
525 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
|
526 ) |
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
|
527 |
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
|
528 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
|
529 http.MethodDelete, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
530 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
|
531 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
|
532 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
|
533 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
|
534 } |
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
|
535 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
|
536 _, 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
|
537 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
|
538 } |
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
|
539 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
540 type styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
541 Styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
542 Style []struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
543 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
|
544 } `json:"style"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
545 } `json:"styles"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
546 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
547 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
548 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
|
549 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
|
550 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
|
551 return true |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
552 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
553 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
554 return false |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
555 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
556 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
557 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
|
558 var ( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
559 geoURL = config.GeoServerURL() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
560 user = config.GeoServerUser() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
561 password = config.GeoServerPassword() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
562 auth = basicAuth(user, password) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
563 ) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
564 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
565 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
566 http.MethodGet, |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
567 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
|
568 nil) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
569 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
570 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
571 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
572 auth(req) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
573 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
|
574 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
575 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
576 } |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
577 defer resp.Body.Close() |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
578 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
579 // Fetch all styles |
1325
9d1f8e99743b
Removed empty if branch.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1032
diff
changeset
|
580 // 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
|
581 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
|
582 return nil |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
583 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
584 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
585 var ( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
586 stylePreprocessorsMu sync.Mutex |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
587 stylePreprocessors = map[string]func(string) (string, error){} |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
588 ) |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
589 |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
590 // 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
|
591 // 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
|
592 // style changes. |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
593 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
|
594 stylePreprocessorsMu.Lock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
595 defer stylePreprocessorsMu.Unlock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
596 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
|
597 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
598 |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
599 // 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
|
600 // associated with a given style name. |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
601 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
|
602 stylePreprocessorsMu.Lock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
603 defer stylePreprocessorsMu.Unlock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
604 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
|
605 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
606 |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
607 func isZip(data []byte) bool { |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
608 if len(data) == 0 { |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
609 return false |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
610 } |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
611 _, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
612 return err == nil |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
613 } |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
614 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
615 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
|
616 |
1032
4c0c4dd393de
Be more consistent with info/warn/error messages when logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
617 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
|
618 |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
619 // Try to load the style data. |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
620 binary, err := entry.LoadStyle() |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
621 if err != nil { |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
622 return err |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
623 } |
3827
6028326b88d6
go fmt'ed
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3825
diff
changeset
|
624 |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
625 zip := isZip(binary) |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
626 |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
627 if !zip { // We only support templating for plain XML styles. |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
628 if processor := FindStylePreprocessor(entry.Name); processor != nil { |
4932
2b46e7c51511
Bring back 5017:6129f7bb5b77 as it does not breaks style upload.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4928
diff
changeset
|
629 data, err := processor(string(binary)) |
2b46e7c51511
Bring back 5017:6129f7bb5b77 as it does not breaks style upload.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4928
diff
changeset
|
630 if err != nil { |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
631 return err |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
632 } |
4932
2b46e7c51511
Bring back 5017:6129f7bb5b77 as it does not breaks style upload.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4928
diff
changeset
|
633 binary = []byte(data) |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
634 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
635 } |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
636 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
637 var ( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
638 geoURL = config.GeoServerURL() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
639 user = config.GeoServerUser() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
640 password = config.GeoServerPassword() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
641 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
|
642 ) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
643 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
644 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
|
645 "/styles" |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
646 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
647 // First create style |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
648 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
649 type Style struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
650 Name string `json:"name"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
651 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
|
652 } |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
653 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
654 var styleFilename = struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
655 Style Style `json:"style"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
656 }{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
657 Style: Style{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
658 Name: entry.Name, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
659 Filename: entry.Name + ".sld", |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
660 }, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
661 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
662 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
663 if create { |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
664 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
665 http.MethodPost, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
666 styleURL, |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
667 toStream(&styleFilename)) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
668 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
669 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
670 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
671 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
672 auth(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
673 asJSON(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
674 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
|
675 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
676 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
677 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
678 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
679 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
|
680 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
|
681 entry.Name, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
682 http.StatusText(resp.StatusCode)) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
683 } |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
684 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
685 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
686 // Second upload data |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
687 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
688 req, err := http.NewRequest( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
689 http.MethodPut, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
690 styleURL+"/"+url.PathEscape(entry.Name), |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
691 bytes.NewReader(binary)) |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
692 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
693 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
694 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
695 auth(req) |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
696 switch { |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
697 case zip: |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
698 asContentType(req, "application/zip") |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
699 case isSymbologyEncoding(binary): |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
700 asContentType(req, "application/vnd.ogc.se+xml") |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
701 default: |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
702 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
|
703 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
704 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
|
705 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
706 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
707 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
708 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
709 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
|
710 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
|
711 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
|
712 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
713 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
714 // 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
|
715 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
716 req, err = http.NewRequest( |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
717 http.MethodPost, |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
718 geoURL+"/rest/layers/"+ |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
719 url.PathEscape(workspaceName+":"+entry.Name)+ |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
720 "/styles?default=true", |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
721 toStream(&styleFilename)) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
722 if err != nil { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
723 return err |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
724 } |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
725 auth(req) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
726 asJSON(req) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
727 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
728 resp, err = http.DefaultClient.Do(req) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
729 if err != nil { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
730 return err |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
731 } |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
732 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
733 if resp.StatusCode != http.StatusCreated { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
734 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
|
735 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
|
736 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
737 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
738 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
739 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
740 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
741 // isSymbologyEncoding tries to figure out if its plain SLD or SE. |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
742 func isSymbologyEncoding(data []byte) bool { |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
743 decoder := xml.NewDecoder(bytes.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
|
744 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
|
745 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
746 for { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
747 tok, err := decoder.Token() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
748 switch { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
749 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
|
750 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
751 case err != nil: |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
752 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
|
753 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
754 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
755 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
|
756 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
|
757 return true |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
758 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
759 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
760 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
761 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
762 func ensureStyles() error { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
763 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
|
764 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
765 var stls styles |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
766 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
|
767 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
768 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
769 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
770 entries := models.InternalServices.Filter( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
771 models.IntAnd( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
772 models.IntWMS, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
773 models.IntWithStyle)) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
774 |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
775 var already []string |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
776 |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
777 defer func() { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
778 if len(already) > 0 { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
779 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
|
780 strings.Join(already, ", ")) |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
781 } |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
782 }() |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
783 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
784 for i := range entries { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
785 entry := &entries[i] |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
786 if stls.hasStyle(entry.Name) { |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
787 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
|
788 continue |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
789 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
790 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
|
791 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
792 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
793 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
794 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
795 return nil |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
796 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
797 |
1466
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
798 // 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
|
799 // 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
|
800 func PrepareGeoServer() error { |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
801 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
802 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
|
803 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
|
804 return nil |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
805 } |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
806 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
807 if config.GeoServerURL() == "" { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
808 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
|
809 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
810 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
811 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
812 for _, ensure := range []func() error{ |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
813 deleteWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
814 ensureWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
815 ensureDataStore, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
816 ensureFeatures, |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4932
diff
changeset
|
817 ensureLayerGroups, |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
818 ensureStyles, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
819 } { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
820 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
|
821 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
|
822 } |
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
|
823 } |
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
|
824 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
825 return nil |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
826 } |