Mercurial > gemma
annotate pkg/models/intservices.go @ 4611:b5aa1eb83bb0 geoserver_sql_views
Add possibility to configure SRS for GeoServer SQL view
Automatic detection of spatial reference system for SQL views in
GeoServer does not always find the correct SRS.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 06 Sep 2019 11:58:03 +0200 |
parents | dfe9cde6a20c |
children | 443867b548b5 |
rev | line source |
---|---|
1017
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
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:
951
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:
951
diff
changeset
|
3 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
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:
951
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:
951
diff
changeset
|
6 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
9 // Software engineering by Intevation GmbH |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
10 // |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
11 // Author(s): |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
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:
951
diff
changeset
|
13 // * Tom Gottfried <tom.gottfried@intevation.de> |
a244b18cb916
Added GNU Affero General Public License.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
951
diff
changeset
|
14 |
442
fc37e7072022
Moved some models used in controllers to to model package because they may be needed elsewhere (e.g. GeoServer config).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
441
diff
changeset
|
15 package models |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import ( |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
18 "context" |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "database/sql" |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "log" |
873
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
21 "net/http" |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "sync" |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/auth" |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/config" |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 ) |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
28 const DatabaseScheme = "waterway" |
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
29 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
30 type IntEntry struct { |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
31 Schema string `json:"schema"` |
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
32 Name string `json:"name"` |
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
33 SQL *string `json:"sql"` |
4611
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
34 SRS *string `json:"srs"` |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
35 Style bool `json:"style"` |
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
36 WMS bool `json:"wms"` |
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
37 WFS bool `json:"wfs"` |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
38 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
39 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
40 type IntServices struct { |
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
41 entries []IntEntry |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 mu sync.Mutex |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
45 const ( |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
46 selectServicesSQL = ` |
4611
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
47 SELECT schema, name, |
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
48 view_def, auth_name || ':' || auth_srid, |
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
49 style IS NOT NULL, as_wms, as_wfs |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
50 FROM sys_admin.published_services |
4611
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
51 LEFT JOIN spatial_ref_sys USING (srid) |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
52 WHERE schema = $1 |
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
53 ORDER by name` |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
54 |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
55 selectStyleSQL = ` |
1288
9f7dc950ffd2
Accept only well-formed XML documents as style in database
Tom Gottfried <tom@intevation.de>
parents:
1017
diff
changeset
|
56 SELECT XMLSERIALIZE(DOCUMENT style AS text) |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
57 FROM sys_admin.published_services |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
58 WHERE name = $1 AND schema = $2` |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
60 updateStyleSQL = ` |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
61 UPDATE sys_admin.published_services |
1288
9f7dc950ffd2
Accept only well-formed XML documents as style in database
Tom Gottfried <tom@intevation.de>
parents:
1017
diff
changeset
|
62 SET style = XMLPARSE(DOCUMENT $1) |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
63 WHERE name = $2 AND schema = $3` |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
64 ) |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
65 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
66 var InternalServices = &IntServices{} |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
68 func (e *IntEntry) LoadStyle() (string, error) { |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
69 var style string |
1327
cabf4789e02b
To make golint happier made context.Context to be the first argument of auth.RunAs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1288
diff
changeset
|
70 ctx := context.Background() |
cabf4789e02b
To make golint happier made context.Context to be the first argument of auth.RunAs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1288
diff
changeset
|
71 err := auth.RunAs(ctx, "sys_admin", |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
72 func(conn *sql.Conn) error { |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
73 return conn.QueryRowContext( |
1327
cabf4789e02b
To make golint happier made context.Context to be the first argument of auth.RunAs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1288
diff
changeset
|
74 ctx, |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
75 selectStyleSQL, |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
76 e.Name, e.Schema).Scan(&style) |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
77 }) |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
78 return style, err |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
79 } |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
80 |
873
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
81 func UpdateInternalStyle(req *http.Request, name, style string) error { |
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
82 return auth.RunAsSessionUser(req, func(conn *sql.Conn) error { |
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
83 _, err := conn.ExecContext( |
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
84 req.Context(), updateStyleSQL, |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
85 style, name, DatabaseScheme) |
873
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
86 if err == nil { |
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
87 InternalServices.Invalidate() |
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
88 } |
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
89 return err |
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
90 }) |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
91 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
92 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
93 func (ps *IntServices) Find(name string) (string, bool) { |
469
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
94 ps.mu.Lock() |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
95 defer ps.mu.Unlock() |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
96 |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
97 if ps.entries == nil { |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
98 if err := ps.load(); err != nil { |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
99 log.Printf("error: %v\n", err) |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
100 return "", false |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
101 } |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
102 } |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
103 |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
104 if ps.has(name) { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
105 return config.GeoServerURL() + "/" + name, true |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
106 } |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
107 return "", false |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
108 } |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
110 func (ps *IntServices) has(service string) bool { |
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
111 var check func(*IntEntry) bool |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
112 switch service { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
113 case "wms": |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
114 check = func(e *IntEntry) bool { return e.WMS } |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
115 case "wfs": |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
116 check = func(e *IntEntry) bool { return e.WFS } |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
117 default: |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
118 return false |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
119 } |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
120 for i := range ps.entries { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
121 if check(&ps.entries[i]) { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
122 return true |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
125 return false |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
128 func (ps *IntServices) load() error { |
446
659c04feb2dc
Made use of sorted slice in external proxied services symmetric to published services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
129 // make empty slice to prevent retry if slice is empty. |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
130 ps.entries = []IntEntry{} |
1327
cabf4789e02b
To make golint happier made context.Context to be the first argument of auth.RunAs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1288
diff
changeset
|
131 ctx := context.Background() |
cabf4789e02b
To make golint happier made context.Context to be the first argument of auth.RunAs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1288
diff
changeset
|
132 return auth.RunAs(ctx, "sys_admin", |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
133 func(conn *sql.Conn) error { |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
134 rows, err := conn.QueryContext( |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
135 ctx, selectServicesSQL, DatabaseScheme) |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
136 if err != nil { |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 return err |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 } |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
139 defer rows.Close() |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
140 for rows.Next() { |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
141 var entry IntEntry |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
142 if err := rows.Scan( |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
143 &entry.Schema, &entry.Name, |
4611
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
144 &entry.SQL, &entry.SRS, &entry.Style, |
599
ac325d191009
Ficxed typo when scanning WMS.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
598
diff
changeset
|
145 &entry.WMS, &entry.WFS, |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
146 ); err != nil { |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
147 return err |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
148 } |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
149 ps.entries = append(ps.entries, entry) |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
150 } |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
151 return rows.Err() |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
152 }) |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 } |
442
fc37e7072022
Moved some models used in controllers to to model package because they may be needed elsewhere (e.g. GeoServer config).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
441
diff
changeset
|
154 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
155 func (ps *IntServices) Invalidate() { |
442
fc37e7072022
Moved some models used in controllers to to model package because they may be needed elsewhere (e.g. GeoServer config).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
441
diff
changeset
|
156 ps.mu.Lock() |
fc37e7072022
Moved some models used in controllers to to model package because they may be needed elsewhere (e.g. GeoServer config).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
441
diff
changeset
|
157 ps.entries = nil |
fc37e7072022
Moved some models used in controllers to to model package because they may be needed elsewhere (e.g. GeoServer config).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
441
diff
changeset
|
158 ps.mu.Unlock() |
fc37e7072022
Moved some models used in controllers to to model package because they may be needed elsewhere (e.g. GeoServer config).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
441
diff
changeset
|
159 } |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
160 |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
161 func InternalAll(IntEntry) bool { return true } |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
162 func IntWMS(entry IntEntry) bool { return entry.WMS } |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
163 func IntWFS(entry IntEntry) bool { return entry.WFS } |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
164 func IntSQLView(entry IntEntry) bool { return entry.SQL != nil } |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
165 func IntWithStyle(entry IntEntry) bool { return entry.Style } |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
166 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
167 func IntByName(name string) func(IntEntry) bool { |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
168 return func(entry IntEntry) bool { return entry.Name == name } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
169 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
170 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
171 func IntAnd(accept ...func(IntEntry) bool) func(IntEntry) bool { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
172 return func(entry IntEntry) bool { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
173 for _, a := range accept { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
174 if !a(entry) { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
175 return false |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
176 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
177 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
178 return true |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
179 } |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
180 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
181 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
182 func (ps *IntServices) Filter(accept func(IntEntry) bool) []IntEntry { |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
183 ps.mu.Lock() |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
184 defer ps.mu.Unlock() |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
185 if ps.entries == nil { |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
186 if err := ps.load(); err != nil { |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
187 log.Printf("error: %v\n", err) |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
188 return nil |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
189 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
190 } |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
191 pe := make([]IntEntry, 0, len(ps.entries)) |
445
37742dd72fdb
Use a sorted slice for published layers to get rid of extra sorting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
444
diff
changeset
|
192 for _, e := range ps.entries { |
37742dd72fdb
Use a sorted slice for published layers to get rid of extra sorting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
444
diff
changeset
|
193 if accept(e) { |
37742dd72fdb
Use a sorted slice for published layers to get rid of extra sorting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
444
diff
changeset
|
194 pe = append(pe, e) |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
195 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
196 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
197 |
445
37742dd72fdb
Use a sorted slice for published layers to get rid of extra sorting.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
444
diff
changeset
|
198 return pe |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
199 } |