Mercurial > gemma
annotate pkg/geoserver/boot.go @ 4931:e41d42be0e13 fairway-marks-import
One more callback to avoid code duplication more consequently
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 14 Feb 2020 19:34:08 +0100 |
parents | be3815792bc4 |
children | 2b46e7c51511 |
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 |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
74 type ftXML struct { |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
75 XMLName xml.Name `xml:"featureType"` |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
76 Name string `xml:"name"` |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
77 Title string `xml:"title"` |
4611
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4609
diff
changeset
|
78 SRS *string `xml:"srs,omitempty"` |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
79 Metadata ftMetadata |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
80 } |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
81 |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
82 type ftMetadata struct { |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
83 XMLName xml.Name `xml:"metadata"` |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
84 Entry ftMetadataEntry |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
85 } |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
86 |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
87 type ftMetadataEntry struct { |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
88 XMLName xml.Name `xml:"entry"` |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
89 Key string `xml:"key,attr"` |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
90 VirtTable ftVirtTable |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
91 } |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
92 |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
93 type ftVirtTable struct { |
4673
443867b548b5
Fix identifiers in layers generated from SQL views
Tom Gottfried <tom@intevation.de>
parents:
4624
diff
changeset
|
94 XMLName xml.Name `xml:"virtualTable"` |
443867b548b5
Fix identifiers in layers generated from SQL views
Tom Gottfried <tom@intevation.de>
parents:
4624
diff
changeset
|
95 Name string `xml:"name"` |
443867b548b5
Fix identifiers in layers generated from SQL views
Tom Gottfried <tom@intevation.de>
parents:
4624
diff
changeset
|
96 SQL string `xml:"sql"` |
443867b548b5
Fix identifiers in layers generated from SQL views
Tom Gottfried <tom@intevation.de>
parents:
4624
diff
changeset
|
97 KeyColumn *string `xml:"keyColumn,omitempty"` |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
98 } // End code for handling with XML |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
99 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 func asJSON(req *http.Request) { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 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
|
102 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
104 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
|
105 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
|
106 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
107 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 func ensureWorkspace() error { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
110 geoURL = config.GeoServerURL() |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 user = config.GeoServerUser() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 password = config.GeoServerPassword() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 auth = basicAuth(user, password) |
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 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 // Probe workspace. |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 req, err := http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 http.MethodGet, |
4345
69c54e2def2d
Avoid unnecessary exceptions in GeoServer
Tom Gottfried <tom@intevation.de>
parents:
4342
diff
changeset
|
119 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
|
120 nil) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 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
|
126 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 if resp.StatusCode != http.StatusNotFound { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 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
|
132 return nil |
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 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 // Create workspace |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
136 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
137 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
|
138 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 const createJSON = `{"workspace":{"name":"` + workspaceName + `"}}` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
143 geoURL+"/rest/workspaces", |
417
ff26ffc18a04
Minor: Removed unnecessary byte slice conversion.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
414
diff
changeset
|
144 strings.NewReader(createJSON)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 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
|
151 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 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
|
155 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
|
156 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 resp.StatusCode) |
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 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 func ensureDataStore() error { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
165 geoURL = config.GeoServerURL() |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 user = config.GeoServerUser() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 password = config.GeoServerPassword() |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 auth = basicAuth(user, password) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 ) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
171 // Probe datastore. |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 req, err := http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 http.MethodGet, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
174 geoURL+"/rest/workspaces/"+workspaceName+ |
4345
69c54e2def2d
Avoid unnecessary exceptions in GeoServer
Tom Gottfried <tom@intevation.de>
parents:
4342
diff
changeset
|
175 "/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
|
176 nil) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 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
|
182 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 if resp.StatusCode != http.StatusNotFound { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 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
|
188 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
191 // Create datastore. |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
192 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
|
193 |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 type entry struct { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 Key interface{} `json:"@key"` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 Value interface{} `json:"$"` |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 // Create datastore. |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 ds := map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 "dataStore": map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 "name": datastoreName, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 "connectionParameters": map[string]interface{}{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 "entry": []entry{ |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 {"host", config.DBHost()}, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 {"port", config.DBPort()}, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
207 {"database", config.DBName()}, |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
208 {"schema", models.DatabaseScheme}, |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
209 {"user", config.DBUser()}, |
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
210 {"passwd", config.DBPassword()}, |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 {"dbtype", databaseType}, |
1446
1e19184472bf
Add configuration of primary key metadata used by geoserver.
Sascha Wilde <wilde@intevation.de>
parents:
1325
diff
changeset
|
212 {"Primary key metadata table", primaryKeyMetadataTbl}, |
4285
6b415dcdaf8a
Let the geoserver expose primary keys for features.
Raimund Renkert <raimund@renkert.org>
parents:
4163
diff
changeset
|
213 {"Expose primary keys", true}, |
4624
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
4614
diff
changeset
|
214 {"Session startup SQL", |
209b10f7bb2c
Add config for GeoServer database session startup SQL
Tom Gottfried <tom@intevation.de>
parents:
4614
diff
changeset
|
215 config.GeoServerStartupSQL() + ";" + startupSQL}, |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
216 {"Session close-up SQL", closeupSQL}, |
2990
dfeb2928232b
Let GeoServer validate database connections before use
Tom Gottfried <tom@intevation.de>
parents:
2624
diff
changeset
|
217 {"validate connections", true}, |
2624
9dbaf69c7a66
Improve geoserver config to better calculate bounding boxes
Bernhard Reiter <bernhard@intevation.de>
parents:
1466
diff
changeset
|
218 {"Estimated extends", false}, |
386
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 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 }, |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 req, err = http.NewRequest( |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 http.MethodPost, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
226 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
|
227 toStream(ds)) |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 auth(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 asJSON(req) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 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
|
234 if err != nil { |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 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
|
239 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
|
240 http.StatusText(resp.StatusCode), |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 resp.StatusCode) |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 return err |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
247 func ensureFeatures() error { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
248 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
249 geoURL = config.GeoServerURL() |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
250 user = config.GeoServerUser() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
251 password = config.GeoServerPassword() |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
252 auth = basicAuth(user, password) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
253 ) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
254 |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
255 datastoreURL := geoURL + "/rest/workspaces/" + workspaceName + |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
256 "/datastores/" + datastoreName |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
257 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
467
diff
changeset
|
258 tables := models.InternalServices.Filter(models.IntWFS) |
398
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
259 if len(tables) == 0 { |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
260 log.Println("info: no tables to publish") |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
261 return nil |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
262 } |
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 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
264 log.Printf("info: number of tables to publish %d\n", len(tables)) |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
265 |
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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 } `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
|
271 } `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
|
272 } |
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 |
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 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
|
275 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
|
276 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
|
277 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
|
278 } |
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 } |
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 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
|
281 } |
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
|
282 |
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
|
283 // 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
|
284 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
|
285 http.MethodGet, |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
286 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
|
287 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
|
288 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
|
289 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
|
290 } |
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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 } |
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
|
296 |
0b8921797064
To reduce the number of REST calls to the GeoServer when publishing gemma tables
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
395
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 // 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
|
301 // 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
|
302 // 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
|
303 // 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
|
304 // 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
|
305 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
|
306 } |
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
|
307 |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
308 var already []string |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
309 |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
310 defer func() { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
311 if len(already) > 0 { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
312 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
|
313 strings.Join(already, ", ")) |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
314 } |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
315 }() |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
316 |
449
a74b8c2a4e75
Removed the command line option to publish tables with GeoServer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
444
diff
changeset
|
317 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
|
318 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
|
319 |
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
|
320 if hasFeature(table) { |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
321 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
|
322 continue |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
323 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
324 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
325 // 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
|
326 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
|
327 |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
328 var req *http.Request |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
329 if models.IntSQLView(tables[i]) { |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
330 // 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
|
331 // 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
|
332 ft := ftXML{ |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
333 Name: table, |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
334 Title: table, |
4611
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4609
diff
changeset
|
335 SRS: tables[i].SRS, |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
336 Metadata: ftMetadata{ |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
337 Entry: ftMetadataEntry{ |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
338 Key: "JDBC_VIRTUAL_TABLE", |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
339 VirtTable: ftVirtTable{ |
4673
443867b548b5
Fix identifiers in layers generated from SQL views
Tom Gottfried <tom@intevation.de>
parents:
4624
diff
changeset
|
340 Name: table, |
443867b548b5
Fix identifiers in layers generated from SQL views
Tom Gottfried <tom@intevation.de>
parents:
4624
diff
changeset
|
341 SQL: *tables[i].SQL, |
443867b548b5
Fix identifiers in layers generated from SQL views
Tom Gottfried <tom@intevation.de>
parents:
4624
diff
changeset
|
342 KeyColumn: tables[i].KeyColumn}}}} |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
343 |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
344 req, err = http.NewRequest( |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
345 http.MethodPost, |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
346 datastoreURL+"/featuretypes", |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
347 toXMLStream(ft)) |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
348 if err != nil { |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
349 return err |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
350 } |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
351 asContentType(req, "text/xml") |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
352 // End code for handling with XML instead |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
353 } else { |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
354 ft := map[string]interface{}{ |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
355 "featureType": map[string]interface{}{ |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
356 "name": table, |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
357 "nativeName": table, |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
358 "title": table, |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
359 }, |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
360 } |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
361 |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
362 req, err = http.NewRequest( |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
363 http.MethodPost, |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
364 datastoreURL+"/featuretypes", |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
365 toStream(ft)) |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
366 if err != nil { |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
367 return err |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
368 } |
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
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 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
371 auth(req) |
4607
064b6c46ea6c
Create SQL views in GeoServer from appropriate configuration
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
372 |
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
|
373 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
|
374 if err != nil { |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
375 return err |
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 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
378 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
|
379 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
|
380 http.StatusText(resp.StatusCode), |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
381 resp.StatusCode) |
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 |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
385 return nil |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
386 } |
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
387 |
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
|
388 func deleteWorkspace() error { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
389 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
390 // Should we delete our workspace first? |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
391 if !config.GeoServerClean() { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
392 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
393 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
394 |
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
|
395 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
|
396 var ( |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 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
|
401 ) |
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
|
402 |
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
|
403 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
|
404 http.MethodDelete, |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 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
|
409 } |
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
|
410 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
|
411 _, 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
|
412 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
|
413 } |
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
|
414 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
415 type styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
416 Styles struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
417 Style []struct { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
418 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
|
419 } `json:"style"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
420 } `json:"styles"` |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
421 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
422 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 return true |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
427 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
428 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
429 return false |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
430 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
431 |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
432 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
|
433 var ( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
434 geoURL = config.GeoServerURL() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
435 user = config.GeoServerUser() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
436 password = config.GeoServerPassword() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
437 auth = basicAuth(user, password) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
438 ) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
439 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
440 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
441 http.MethodGet, |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
442 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
|
443 nil) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
444 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
445 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
446 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
447 auth(req) |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
448 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
|
449 if err != nil { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
450 return err |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
451 } |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
452 defer resp.Body.Close() |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
453 |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
454 // Fetch all styles |
1325
9d1f8e99743b
Removed empty if branch.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1032
diff
changeset
|
455 // 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
|
456 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
|
457 return nil |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
458 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
459 |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
460 var ( |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
461 stylePreprocessorsMu sync.Mutex |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
462 stylePreprocessors = map[string]func(string) (string, error){} |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
463 ) |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
464 |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
465 // 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
|
466 // 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
|
467 // style changes. |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
468 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
|
469 stylePreprocessorsMu.Lock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
470 defer stylePreprocessorsMu.Unlock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
471 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
|
472 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
473 |
4163
51cfa54fc5b1
Made 'golint' and 'staticcheck' happy with geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3828
diff
changeset
|
474 // 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
|
475 // associated with a given style name. |
3828
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
476 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
|
477 stylePreprocessorsMu.Lock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
478 defer stylePreprocessorsMu.Unlock() |
885eb90255ff
Cleanup templating of styles [WIP].
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3827
diff
changeset
|
479 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
|
480 } |
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
481 |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
482 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
|
483 if len(data) == 0 { |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
484 return false |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
485 } |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
486 _, 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
|
487 return err == nil |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
488 } |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
489 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
490 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
|
491 |
1032
4c0c4dd393de
Be more consistent with info/warn/error messages when logging.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1017
diff
changeset
|
492 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
|
493 |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
494 // 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
|
495 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
|
496 if err != nil { |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
497 return err |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
498 } |
3827
6028326b88d6
go fmt'ed
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3825
diff
changeset
|
499 |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
500 zip := isZip(binary) |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
501 |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
502 if !zip { // We only support templating for plain XML styles. |
4928
be3815792bc4
Backed out changeset 6129f7bb5b77
Tom Gottfried <tom@intevation.de>
parents:
4921
diff
changeset
|
503 data := string(binary) |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
504 if processor := FindStylePreprocessor(entry.Name); processor != nil { |
4928
be3815792bc4
Backed out changeset 6129f7bb5b77
Tom Gottfried <tom@intevation.de>
parents:
4921
diff
changeset
|
505 if data, err = processor(data); err != nil { |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
506 return err |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
507 } |
3825
36129677ff24
fetch data for sld template from data base and interpolate colors (WIP)
Markus Kottlaender <markus@intevation.de>
parents:
3306
diff
changeset
|
508 } |
4928
be3815792bc4
Backed out changeset 6129f7bb5b77
Tom Gottfried <tom@intevation.de>
parents:
4921
diff
changeset
|
509 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
|
510 } |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
914
diff
changeset
|
511 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
512 var ( |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
513 geoURL = config.GeoServerURL() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
514 user = config.GeoServerUser() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
515 password = config.GeoServerPassword() |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
516 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
|
517 ) |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
518 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
519 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
|
520 "/styles" |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
890
diff
changeset
|
521 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
522 // First create style |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
523 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
524 type Style struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
525 Name string `json:"name"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
526 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
|
527 } |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
528 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
529 var styleFilename = struct { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
530 Style Style `json:"style"` |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
531 }{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
532 Style: Style{ |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
533 Name: entry.Name, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
534 Filename: entry.Name + ".sld", |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
535 }, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
536 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
537 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
538 if create { |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
539 req, err := http.NewRequest( |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
540 http.MethodPost, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
541 styleURL, |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
542 toStream(&styleFilename)) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
543 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
544 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
545 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
546 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
547 auth(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
548 asJSON(req) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
549 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
|
550 if err != nil { |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
551 return err |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
552 } |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
553 |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
554 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
|
555 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
|
556 entry.Name, |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
557 http.StatusText(resp.StatusCode)) |
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
558 } |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
559 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
560 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
561 // Second upload data |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
562 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
563 req, err := http.NewRequest( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
564 http.MethodPut, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
565 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
|
566 bytes.NewReader(binary)) |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
567 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
568 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
569 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
570 auth(req) |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
571 switch { |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
572 case zip: |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
573 asContentType(req, "application/zip") |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
574 case isSymbologyEncoding(binary): |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
575 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
|
576 default: |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
577 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
|
578 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
579 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
|
580 if err != nil { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
581 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
582 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
583 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 } |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
588 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
589 // 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
|
590 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
591 req, err = http.NewRequest( |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
592 http.MethodPost, |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
593 geoURL+"/rest/layers/"+ |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
594 url.PathEscape(workspaceName+":"+entry.Name)+ |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
595 "/styles?default=true", |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
596 toStream(&styleFilename)) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
597 if err != nil { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
598 return err |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
599 } |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
600 auth(req) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
601 asJSON(req) |
878
495fc3264265
Connect uploaded styles with layers during GeoServer boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
602 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
603 resp, err = http.DefaultClient.Do(req) |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
604 if err != nil { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
605 return err |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
606 } |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
607 |
4342
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
608 if resp.StatusCode != http.StatusCreated { |
6a1fef54d49f
Always associate style with layer
Tom Gottfried <tom@intevation.de>
parents:
4290
diff
changeset
|
609 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
|
610 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
|
611 } |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
612 |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
613 return nil |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
614 } |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
615 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
616 // 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
|
617 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
|
618 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
|
619 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
|
620 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
621 for { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
622 tok, err := decoder.Token() |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
623 switch { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
624 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
|
625 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
626 case err != nil: |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
627 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
|
628 return false |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
629 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
630 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
|
631 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
|
632 return true |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
633 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
634 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
635 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
875
diff
changeset
|
636 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
637 func ensureStyles() error { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
638 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
|
639 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
640 var stls styles |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
641 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
|
642 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
643 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
644 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
645 entries := models.InternalServices.Filter( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
646 models.IntAnd( |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
647 models.IntWMS, |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
648 models.IntWithStyle)) |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
649 |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
650 var already []string |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
651 |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
652 defer func() { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
653 if len(already) > 0 { |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
654 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
|
655 strings.Join(already, ", ")) |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
656 } |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
657 }() |
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
658 |
914
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
659 for i := range entries { |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
660 entry := &entries[i] |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
661 if stls.hasStyle(entry.Name) { |
3306
bf5ab7a069e2
More compact logging of GeoServer booting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3093
diff
changeset
|
662 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
|
663 continue |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
664 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
665 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
|
666 return err |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
667 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
668 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
669 |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
670 return nil |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
671 } |
4bf3a3a20ce1
Finished direct updating when style is uploaded via controller.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
672 |
1466
d7152eb11d58
Added api doc strings for the geoserver package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1446
diff
changeset
|
673 // 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
|
674 // 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
|
675 func PrepareGeoServer() error { |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
676 |
517
7e45aaec7081
Consolidate configuration parameters.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
477
diff
changeset
|
677 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
|
678 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
|
679 return nil |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
680 } |
5f5b3ca0c9fe
Fixed wrong SQL startup script for GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
681 |
395
272ed64a5053
Create feature layers in GeoServer via REST API.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
386
diff
changeset
|
682 if config.GeoServerURL() == "" { |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
683 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
|
684 return nil |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
685 } |
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
686 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
687 for _, ensure := range []func() error{ |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
688 deleteWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
689 ensureWorkspace, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
690 ensureDataStore, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
691 ensureFeatures, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
692 ensureStyles, |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
693 } { |
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
694 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
|
695 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
|
696 } |
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
|
697 } |
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
|
698 |
875
371c756f0370
Code simplification in geoserver boot configuration.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
874
diff
changeset
|
699 return nil |
386
999f4f83a072
Configure GeoServer via REST-API. TODO: Configure layers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
700 } |