Mercurial > gemma
annotate pkg/models/intservices.go @ 876:8b9bd9ccdd93 geo-style
Upload style during boot. TODO: Connect with layer.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 30 Sep 2018 19:42:16 +0200 |
parents | ad9272460ef3 |
children | 254cd247826d |
rev | line source |
---|---|
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
|
1 package models |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import ( |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
4 "context" |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 "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
|
6 "fmt" |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 "log" |
873
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
8 "net/http" |
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
|
9 "strings" |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 "sync" |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 "gemma.intevation.de/gemma/pkg/auth" |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
13 "gemma.intevation.de/gemma/pkg/config" |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 ) |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
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
|
16 type IntEntry struct { |
473
b2dea4e56ff1
/api/published (GET) returns a JSON document of the geo-services published by the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
469
diff
changeset
|
17 Name string `json:"name"` |
b2dea4e56ff1
/api/published (GET) returns a JSON document of the geo-services published by the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
469
diff
changeset
|
18 Style sql.NullString `json:"-"` // This should be done separately. |
b2dea4e56ff1
/api/published (GET) returns a JSON document of the geo-services published by the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
469
diff
changeset
|
19 WMS bool `json:"wms"` |
b2dea4e56ff1
/api/published (GET) returns a JSON document of the geo-services published by the gemma server.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
469
diff
changeset
|
20 WFS bool `json:"wfs"` |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
21 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
22 |
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
|
23 type IntServices struct { |
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
24 entries []IntEntry |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 mu sync.Mutex |
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 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
28 const ( |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
29 selectPublishedServices = `SELECT relname, style, as_wms, as_wfs |
598
4854a1e85870
Ensure published service is based on existing table
Tom Gottfried <tom@intevation.de>
parents:
501
diff
changeset
|
30 FROM sys_admin.published_services JOIN pg_class ON name = oid ORDER by relname` |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
32 updateStyleSQL = ` |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
33 UPDATE sys_admin.published_services |
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
|
34 SET style = xslt_process($1, $2, $3)::bytea |
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
|
35 WHERE name IN (SELECT oid FROM pg_class WHERE relname = $4)` |
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
|
36 ) |
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
|
37 |
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
|
38 const ( |
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
|
39 replaceNameXSLT = `<?xml version="1.0"?> |
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
|
40 <xsl:stylesheet version="1.0" |
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
|
41 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
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
|
42 xmlns:sld="http://www.opengis.net/sld" |
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
|
43 xmlns:se="http://www.opengis.net/se"> |
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
|
44 |
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
|
45 <xsl:param name="name"/> |
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
|
46 |
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
|
47 <xsl:template |
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
|
48 match="/sld:StyledLayerDescriptor/sld:NamedLayer/sld:Name/text()"> |
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
|
49 <xsl:value-of select="$name"/> |
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
|
50 </xsl:template> |
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
|
51 |
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
|
52 <xsl:template |
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
|
53 match="/sld:StyledLayerDescriptor/sld:NamedLayer/se:Name/text()"> |
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
|
54 <xsl:value-of select="$name"/> |
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
|
55 </xsl:template> |
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
|
56 |
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
|
57 <xsl:template match="@*|node()"> |
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
|
58 <xsl:copy> |
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
|
59 <xsl:apply-templates select="@*|node()"/> |
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
|
60 </xsl:copy> |
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
|
61 </xsl:template> |
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
|
62 </xsl:stylesheet>` |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
63 ) |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
64 |
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
|
65 var InternalServices = &IntServices{} |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 |
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
|
67 func UpdateInternalStyle(req *http.Request, name, style string) error { |
ad9272460ef3
Do the XSLT to adjust the layer name when updating the style column in the database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
871
diff
changeset
|
68 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
|
69 param := fmt.Sprintf("name='%s'", strings.Replace(name, ",", "", -1)) |
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
|
70 _, 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
|
71 req.Context(), updateStyleSQL, |
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
|
72 style, replaceNameXSLT, param, name) |
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
|
73 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
|
74 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
|
75 } |
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
|
76 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
|
77 }) |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
78 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
79 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 |
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
|
84 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
|
85 if err := ps.load(); err != nil { |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
86 log.Printf("error: %v\n", err) |
788c87b99bae
465:a8e217119085 removed the mutex and the lazy loading from the internal publishing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
456
diff
changeset
|
87 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
|
88 } |
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
|
89 } |
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
|
90 |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
91 if ps.has(name) { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
92 return config.GeoServerURL() + "/" + name, true |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
93 } |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
94 return "", false |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
95 } |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 |
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
|
97 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
|
98 var check func(*IntEntry) bool |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
99 switch service { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 default: |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
105 return false |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
106 } |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
107 for i := range ps.entries { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
108 if check(&ps.entries[i]) { |
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
109 return true |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
456
a8e217119085
Fixed internal proxy resolution.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
446
diff
changeset
|
112 return false |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 } |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 |
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
|
115 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
|
116 // 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
|
117 ps.entries = []IntEntry{} |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
118 return auth.RunAs("sys_admin", context.Background(), |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
119 func(conn *sql.Conn) error { |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
120 rows, err := conn.QueryContext( |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
121 context.Background(), selectPublishedServices) |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
122 if err != nil { |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 return err |
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 } |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
125 defer rows.Close() |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
126 for rows.Next() { |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
127 var entry IntEntry |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
128 if err := rows.Scan( |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
129 &entry.Name, &entry.Style, |
599
ac325d191009
Ficxed typo when scanning WMS.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
598
diff
changeset
|
130 &entry.WMS, &entry.WFS, |
501
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
131 ); err != nil { |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
132 return err |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
133 } |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
134 ps.entries = append(ps.entries, entry) |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
135 } |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
136 return rows.Err() |
c10c76c92797
Use metamorphic database connections for auth.RunAs().
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
137 }) |
441
76a76691a298
Load the configuration of the published services from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 } |
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
|
139 |
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
|
140 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
|
141 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
|
142 ps.entries = nil |
fc37e7072022
Moved some models used in controllers to to model package because they may be needed elsewhere (e.g. GeoServer config).
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
441
diff
changeset
|
143 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
|
144 } |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
145 |
474
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
146 func InternalAll(IntEntry) bool { return true } |
11d80120ed3d
Renamed published services to internal services to be more symmetrical to external services.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
473
diff
changeset
|
147 func IntWMS(entry IntEntry) bool { return entry.WMS } |
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
|
148 func IntWFS(entry IntEntry) bool { return entry.WFS } |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
149 |
871
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
150 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
|
151 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
|
152 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
153 |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
154 func IntAnd(a, b func(IntEntry) bool) func(IntEntry) bool { |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
155 return func(entry IntEntry) bool { return a(entry) && b(entry) } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
156 } |
f0b6852c14d1
More on uploading styles to gemma.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
634
diff
changeset
|
157 |
876
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
873
diff
changeset
|
158 func IntWithStyle(entry IntEntry) bool { |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
873
diff
changeset
|
159 return entry.Style.Valid |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
873
diff
changeset
|
160 } |
8b9bd9ccdd93
Upload style during boot. TODO: Connect with layer.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
873
diff
changeset
|
161 |
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 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
|
163 ps.mu.Lock() |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
164 defer ps.mu.Unlock() |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
165 if ps.entries == nil { |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
166 if err := ps.load(); err != nil { |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
167 log.Printf("error: %v\n", err) |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
168 return nil |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
169 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
170 } |
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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
176 } |
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
177 |
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
|
178 return pe |
444
c315885825e5
Publish WFS layers on GeoServer from database configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
442
diff
changeset
|
179 } |