annotate pkg/models/intservices.go @ 5688:6281c18b109f sr-v2

Finsh serializing v2 meshes.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 12 Feb 2024 02:27:41 +0100
parents 1222b777f51f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
28 // DatabaseScheme is the schema used for the data
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
29 // accessible for the waterway user.
4606
dfe9cde6a20c Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents: 1327
diff changeset
30 const DatabaseScheme = "waterway"
dfe9cde6a20c Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents: 1327
diff changeset
31
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
32 type (
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
33 // IntEntry repreents a published layer in the GeoServer.
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
34 IntEntry struct {
4995
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
35 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
36 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
37 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
38 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
39 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
40 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
41 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
42 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
43 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
44 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
45 }
444
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
46
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
47 // LayerGroup is a layer group in a published GeoServer layer.
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
48 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
49 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
50 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
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
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
53 // IntServices are the internal services published by
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
54 // the GeoServer.
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
55 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
56 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
57 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
58 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
59 }
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
60 )
441
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
871
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
62 const (
915
2ebf677fc2e1 Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 913
diff changeset
63 selectServicesSQL = `
4995
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
64 SELECT
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
65 schema,
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
66 name,
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
67 view_def,
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
68 key_column,
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
69 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
70 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
71 as_wms,
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
72 as_wfs,
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
73 wmst_attribute,
4a816ecf70de Added support for WMS-Time in configuring the GeoServer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4935
diff changeset
74 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
75 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
76 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
77 WHERE schema = $1
dfe9cde6a20c Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents: 1327
diff changeset
78 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
79
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
80 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
81 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
82 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
83 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
84
915
2ebf677fc2e1 Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 913
diff changeset
85 selectStyleSQL = `
4918
4a9a1e323e11 First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4673
diff changeset
86 SELECT style
915
2ebf677fc2e1 Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 913
diff changeset
87 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
88 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
89
871
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
90 updateStyleSQL = `
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
91 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
92 SET style = $1
4606
dfe9cde6a20c Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents: 1327
diff changeset
93 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
94 )
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
95
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
96 // InternalServices is the list of the internal services
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
97 // managed by the Gemma server.
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
98 var InternalServices = &IntServices{}
441
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
100 // LoadStyle a style for a given entry.
4918
4a9a1e323e11 First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4673
diff changeset
101 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
102 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
103 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
104 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
105 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
106 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
107 ctx,
915
2ebf677fc2e1 Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 913
diff changeset
108 selectStyleSQL,
4606
dfe9cde6a20c Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents: 1327
diff changeset
109 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
110 })
2ebf677fc2e1 Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 913
diff changeset
111 return style, err
2ebf677fc2e1 Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 913
diff changeset
112 }
2ebf677fc2e1 Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 913
diff changeset
113
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
114 // UpdateInternalStyle updates a style in the database.
4918
4a9a1e323e11 First version of geo styles in ZIP files.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4673
diff changeset
115 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
116 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
117 _, 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
118 req.Context(), updateStyleSQL,
4606
dfe9cde6a20c Reflect database model changes for SQL views in backend
Tom Gottfried <tom@intevation.de>
parents: 1327
diff changeset
119 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
120 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
121 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
122 }
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
123 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
124 })
871
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
125 }
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
126
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
127 // LayerGroups returns the list of layer groups from the database.
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
128 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
129 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
130 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
131
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 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
133 if err := ps.load(); err != nil {
5490
5f47eeea988d Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4995
diff changeset
134 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
135 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
136 }
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
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
139 // 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
140 // 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
141 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
142 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
143 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
144 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
145 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
146 }
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
147 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
148 }
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
149
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
150 // Find looks for an internal service with a given name.
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
151 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
152 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
153 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
154
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
155 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
156 if err := ps.load(); err != nil {
5490
5f47eeea988d Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4995
diff changeset
157 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
158 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
159 }
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
160 }
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
161
456
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
162 if ps.has(name) {
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
163 return config.GeoServerURL() + "/" + name, true
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
164 }
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
165 return "", false
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
166 }
441
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167
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
168 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
169 var check func(*IntEntry) bool
456
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
170 switch service {
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
171 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
172 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
173 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
174 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
175 default:
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
176 return false
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
177 }
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
178 for i := range ps.entries {
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
179 if check(&ps.entries[i]) {
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
180 return true
441
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 }
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 }
456
a8e217119085 Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 446
diff changeset
183 return false
441
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 }
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185
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
186 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
187 // 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
188 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
189 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
190 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
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 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
193 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
194 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
195 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
196 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
197 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
198 }
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 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
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 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
202 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
203 &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
204 &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
205 &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
206 &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
207 ); err != nil {
441
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 return err
76a76691a298 Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 }
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
210 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
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 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
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
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 // 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
216 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
217 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
218 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
219 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
220 }
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 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
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 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
224 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
225 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
226 return err
501
c10c76c92797 Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
227 }
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
228 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
229 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
230 } 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
231 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
232 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
233 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
234 })
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
235 }
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
236 }
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
237 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
238 }
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
239
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
240 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
241 }
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
242
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
243 // Invalidate invalidates the list on internal services.
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
244 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
245 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
246 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
247 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
248 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
249 }
444
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
250
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
251 // InternalAll passes all entries.
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
252 func InternalAll(IntEntry) bool { return true }
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
253
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
254 // IntWMS passes only WMS entries.
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
255 func IntWMS(entry IntEntry) bool { return entry.WMS }
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
256
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
257 // IntWFS passes only WFS entries.
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
258 func IntWFS(entry IntEntry) bool { return entry.WFS }
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
259
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
260 // IntSQLView passes only entries with a SQL view.
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
261 func IntSQLView(entry IntEntry) bool { return entry.SQL != nil }
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
262
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
263 // IntWithStyle passes only entries with a style.
915
2ebf677fc2e1 Load style data only on demand to not waste menory.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 913
diff changeset
264 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
265
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
266 // IntByName passes only entries with a given name.
871
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
267 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
268 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
269 }
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
270
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
271 // IntAnd filters internal entries that match all conditions.
913
876d1f5433be Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 877
diff changeset
272 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
273 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
274 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
275 if !a(entry) {
876d1f5433be Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 877
diff changeset
276 return false
876d1f5433be Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 877
diff changeset
277 }
876d1f5433be Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 877
diff changeset
278 }
876d1f5433be Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 877
diff changeset
279 return true
876d1f5433be Started with direct applying style after modification via controller. WIP.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 877
diff changeset
280 }
871
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
281 }
f0b6852c14d1 More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 634
diff changeset
282
5601
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
283 // Filter returns a list of internal services that match the
1222b777f51f Made golint finally happy.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 5490
diff changeset
284 // given condition.
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
285 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
286 ps.mu.Lock()
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
287 defer ps.mu.Unlock()
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
288 if ps.entries == nil {
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
289 if err := ps.load(); err != nil {
5490
5f47eeea988d Use own logging package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4995
diff changeset
290 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
291 return nil
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
292 }
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
293 }
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
294 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
295 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
296 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
297 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
298 }
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
299 }
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
300
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
301 return pe
444
c315885825e5 Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 442
diff changeset
302 }