Mercurial > gemma
annotate pkg/models/intservices.go @ 5520:05db984d3db1
Improve performance of bottleneck area calculation
Avoid buffer calculations by replacing them with simple distance comparisons
and calculate the boundary of the result geometry only once per iteration.
In some edge cases with very large numbers of iterations, this reduced
the runtime of a bottleneck import by a factor of more than twenty.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 21 Oct 2021 19:50:39 +0200 |
parents | 5f47eeea988d |
children | 1222b777f51f |
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" |
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
|
20 "net/http" |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "sync" |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "gemma.intevation.de/gemma/pkg/auth" |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/config" |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4995
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/log" |
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 { |
4995
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
32 Schema string `json:"schema"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
33 Name string `json:"name"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
34 SQL *string `json:"sql"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
35 KeyColumn *string `json:"keycolumn"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
36 SRS *string `json:"srs"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
37 Style bool `json:"style"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
38 WMS bool `json:"wms"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
39 WFS bool `json:"wfs"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
40 WMSTAttribute *string `json:"wmst-attribute"` |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
41 WMSTEndAttribute *string `json:"wmst-end-attribute"` |
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 } |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
43 |
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
|
44 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
|
45 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
|
46 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
|
47 } |
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 |
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 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
|
50 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
|
51 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
|
52 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
|
53 } |
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
|
54 ) |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
56 const ( |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
57 selectServicesSQL = ` |
4995
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
58 SELECT |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
59 schema, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
60 name, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
61 view_def, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
62 key_column, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
63 auth_name || ':' || auth_srid, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
64 style IS NOT NULL, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
65 as_wms, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
66 as_wfs, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
67 wmst_attribute, |
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
68 wmst_end_attribute |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
69 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
|
70 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
|
71 WHERE schema = $1 |
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
72 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
|
73 |
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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
79 selectStyleSQL = ` |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
80 SELECT style |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
81 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
|
82 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
|
83 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
84 updateStyleSQL = ` |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
85 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
|
86 SET style = $1 |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
87 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
|
88 ) |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
89 |
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
|
90 var InternalServices = &IntServices{} |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 ctx, |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
99 selectStyleSQL, |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
100 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
|
101 }) |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
102 return style, err |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
103 } |
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
104 |
4918
4a9a1e323e11
First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4673
diff
changeset
|
105 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
|
106 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
|
107 _, 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
|
108 req.Context(), updateStyleSQL, |
4606
dfe9cde6a20c
Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents:
1327
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 } |
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
|
113 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
|
114 }) |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
115 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
116 |
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
|
117 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
|
118 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
|
119 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
|
120 |
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 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
|
122 if err := ps.load(); err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4995
diff
changeset
|
123 log.Errorf("%v\n", err) |
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
|
124 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
|
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 } |
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 // 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
|
129 // 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 } |
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
|
136 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
|
137 } |
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
|
138 |
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
|
139 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
|
140 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
|
141 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
|
142 |
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
|
143 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
|
144 if err := ps.load(); err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4995
diff
changeset
|
145 log.Errorf("%v\n", err) |
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
|
146 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
|
147 } |
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
|
148 } |
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
|
149 |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
150 if ps.has(name) { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
151 return config.GeoServerURL() + "/" + name, true |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
152 } |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
153 return "", false |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
154 } |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 |
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
|
156 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
|
157 var check func(*IntEntry) bool |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
158 switch service { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 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
|
163 default: |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
164 return false |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
165 } |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
166 for i := range ps.entries { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
167 if check(&ps.entries[i]) { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
168 return true |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 } |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
171 return false |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 |
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
|
174 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
|
175 // 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
|
176 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
|
177 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
|
178 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
|
179 |
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 // 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 } |
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 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
|
188 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
|
189 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
|
190 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
|
191 &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
|
192 &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
|
193 &entry.WMS, &entry.WFS, |
4995
4a816ecf70de
Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4935
diff
changeset
|
194 &entry.WMSTAttribute, &entry.WMSTEndAttribute, |
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
|
195 ); err != nil { |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 return err |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 } |
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
|
198 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
|
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 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
|
201 } |
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 |
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 // 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 } |
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 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
|
210 |
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 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
|
212 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
|
213 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
|
214 return err |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
215 } |
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
|
216 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
|
217 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
|
218 } 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
|
219 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
|
220 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
|
221 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
|
222 }) |
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 } |
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
|
224 } |
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
|
225 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
|
226 } |
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
|
227 |
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
|
228 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
|
229 } |
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
|
230 |
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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 } |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
237 |
915
2ebf677fc2e1
Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
913
diff
changeset
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
244 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
|
245 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
|
246 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
247 |
913
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
248 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
|
249 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
|
250 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
|
251 if !a(entry) { |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
252 return false |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
253 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
254 } |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
255 return true |
876d1f5433be
Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
877
diff
changeset
|
256 } |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
257 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
258 |
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
|
259 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
|
260 ps.mu.Lock() |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
261 defer ps.mu.Unlock() |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
262 if ps.entries == nil { |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
263 if err := ps.load(); err != nil { |
5490
5f47eeea988d
Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4995
diff
changeset
|
264 log.Errorf("%v\n", err) |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
265 return nil |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
266 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
267 } |
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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
273 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
274 |
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
|
275 return pe |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
276 } |