Mercurial > gemma
annotate pkg/models/intservices.go @ 4935:c64dba002726 fairway-marks-import
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 16 Feb 2020 15:16:22 +0100 |
parents | 4a9a1e323e11 |
children | 4a816ecf70de |
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 |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
30 type ( |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
31 IntEntry struct { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
32 Schema string `json:"schema"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
33 Name string `json:"name"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
34 SQL *string `json:"sql"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
35 KeyColumn *string `json:"keycolumn"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
36 SRS *string `json:"srs"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
37 Style bool `json:"style"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
38 WMS bool `json:"wms"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
39 WFS bool `json:"wfs"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
40 } |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
41 |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
42 LayerGroup struct { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
43 Name string `json:"name"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
44 Layers []string `json:"layers"` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
45 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
46 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
47 IntServices struct { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
48 mu sync.Mutex |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
49 entries []IntEntry |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
50 layerGroups []LayerGroup |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
51 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
52 ) |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
54 const ( |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
55 selectServicesSQL = ` |
4611
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
56 SELECT schema, name, |
4673
443867b548b5
Fix identifiers in layers generated from SQL views
Tom Gottfried <tom@intevation.de>
parents:
4611
diff
changeset
|
57 view_def, key_column, auth_name || ':' || auth_srid, |
4611
b5aa1eb83bb0
Add possibility to configure SRS for GeoServer SQL view
Tom Gottfried <tom@intevation.de>
parents:
4606
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 WHERE schema = $1 |
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
62 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
|
63 |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
64 selectGroupedLayersSQL = ` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
65 SELECT group_name, name |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
66 FROM sys_admin.grouped_layers |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
67 ORDER BY group_name, ord` |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
68 |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
69 selectStyleSQL = ` |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
70 SELECT style |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
71 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
|
72 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
|
73 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
74 updateStyleSQL = ` |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
75 UPDATE sys_admin.published_services |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
76 SET style = $1 |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
77 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
|
78 ) |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
79 |
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
|
80 var InternalServices = &IntServices{} |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
82 func (e *IntEntry) LoadStyle() ([]byte, error) { |
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
83 var style []byte |
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
|
84 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
|
85 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
|
86 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
|
87 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
|
88 ctx, |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
89 selectStyleSQL, |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
90 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
|
91 }) |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
92 return style, err |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
93 } |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
94 |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
95 func UpdateInternalStyle(req *http.Request, name string, style []byte) error { |
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
|
96 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
|
97 _, 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
|
98 req.Context(), updateStyleSQL, |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 } |
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
|
103 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
|
104 }) |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
105 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
106 |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
107 func (ps *IntServices) LayerGroups() []LayerGroup { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
108 ps.mu.Lock() |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
109 defer ps.mu.Unlock() |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
110 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
111 if ps.entries == nil { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
112 if err := ps.load(); err != nil { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
113 log.Printf("error: %v\n", err) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
114 return nil |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
115 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
116 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
117 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
118 // To avoid races we simple make a deep copy. |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
119 // As we don't have such many of them it light weight enough for now. |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
120 groups := make([]LayerGroup, len(ps.layerGroups)) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
121 for i := range groups { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
122 layers := make([]string, len(ps.layerGroups[i].Layers)) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
123 copy(layers, ps.layerGroups[i].Layers) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
124 groups[i] = LayerGroup{Name: ps.layerGroups[i].Name, Layers: layers} |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
125 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
126 return groups |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
127 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
128 |
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
|
129 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
|
130 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
|
131 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
|
132 |
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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 } |
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
|
138 } |
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
|
139 |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
140 if ps.has(name) { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
141 return config.GeoServerURL() + "/" + name, true |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
142 } |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
143 return "", false |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
144 } |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 |
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
|
146 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
|
147 var check func(*IntEntry) bool |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
148 switch service { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 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
|
153 default: |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
154 return false |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
155 } |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
156 for i := range ps.entries { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
157 if check(&ps.entries[i]) { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
158 return true |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 } |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
161 return false |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 |
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
|
164 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
|
165 // 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
|
166 ps.entries = []IntEntry{} |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
167 ps.layerGroups = []LayerGroup{} |
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
|
168 ctx := context.Background() |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
169 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
170 // Load the internal layers. |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
171 entries := func(conn *sql.Conn) error { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
172 rows, err := conn.QueryContext( |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
173 ctx, selectServicesSQL, DatabaseScheme) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
174 if err != nil { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
175 return err |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
176 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
177 defer rows.Close() |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
178 for rows.Next() { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
179 var entry IntEntry |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
180 if err := rows.Scan( |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
181 &entry.Schema, &entry.Name, |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
182 &entry.SQL, &entry.KeyColumn, &entry.SRS, &entry.Style, |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
183 &entry.WMS, &entry.WFS, |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
184 ); err != nil { |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 return err |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 } |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
187 ps.entries = append(ps.entries, entry) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
188 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
189 return rows.Err() |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
190 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
191 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
192 // Load the layer groups. |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
193 groups := func(conn *sql.Conn) error { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
194 rows, err := conn.QueryContext(ctx, selectGroupedLayersSQL) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
195 if err != nil { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
196 return err |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
197 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
198 defer rows.Close() |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
199 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
200 for rows.Next() { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
201 var group, layer string |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
202 if err := rows.Scan(&group, &layer); err != nil { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
203 return err |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
204 } |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
205 if n := len(ps.layerGroups); n > 0 && ps.layerGroups[n-1].Name == group { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
206 ps.layerGroups[n-1].Layers = append(ps.layerGroups[n-1].Layers, layer) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
207 } else { |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
208 ps.layerGroups = append(ps.layerGroups, LayerGroup{ |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
209 Name: group, |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
210 Layers: []string{layer}, |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
211 }) |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
212 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
213 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
214 return rows.Err() |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
215 } |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
216 |
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
217 return auth.RunAllAs(ctx, "sys_admin", entries, groups) |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 } |
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
|
219 |
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
|
220 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
|
221 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
|
222 ps.entries = nil |
4935
c64dba002726
Load and prepare data models for layer groups. TODO: Feed config to GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4918
diff
changeset
|
223 ps.layerGroups = nil |
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
|
224 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
|
225 } |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
226 |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
233 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
|
234 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
|
235 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
236 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 if !a(entry) { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
241 return false |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
242 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
243 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
244 return true |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
245 } |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
246 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
247 |
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
|
248 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
|
249 ps.mu.Lock() |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
250 defer ps.mu.Unlock() |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
251 if ps.entries == nil { |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
252 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
|
253 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
|
254 return nil |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
255 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
256 } |
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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
262 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
263 |
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
|
264 return pe |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
265 } |