Skip to content

Commit d1bf092

Browse files
author
Jelle Dijkstra
committed
Improved capabilities generator
1 parent fbc6e42 commit d1bf092

File tree

12 files changed

+152
-191
lines changed

12 files changed

+152
-191
lines changed

cmd/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const (
5555
defaultMultitoolImage = "acrpdokprodman.azurecr.io/pdok/docker-multitool:0.9.4"
5656
defaultMapfileGeneratorImage = "acrpdokprodman.azurecr.io/pdok/mapfile-generator:1.9.5"
5757
defaultMapserverImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/mapserver:8.4.0-4-nl"
58-
defaultCapabilitiesGeneratorImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/ogc-capabilities-generator:1.0.0-beta7"
58+
defaultCapabilitiesGeneratorImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/ogc-capabilities-generator:1.0.0-beta8"
5959
defaultFeatureinfoGeneratorImage = "acrpdokprodman.azurecr.io/mirror/docker.io/pdok/featureinfo-generator:1.4.0-beta1"
6060
defaultOgcWebserviceProxyImage = "acrpdokprodman.azurecr.io/pdok/ogc-webservice-proxy:0.1.8"
6161
defaultApacheExporterImage = "acrpdokprodman.azurecr.io/mirror/docker.io/lusotycoon/apache-exporter:v0.7.0"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/onsi/ginkgo/v2 v2.22.2
1212
github.com/onsi/gomega v1.36.2
1313
github.com/pdok/featureinfo-generator v1.4.0-beta1
14-
github.com/pdok/ogc-capabilities-generator v1.0.0-beta7
14+
github.com/pdok/ogc-capabilities-generator v1.0.0-beta8
1515
github.com/pdok/ogc-specifications v1.0.0-beta9
1616
github.com/pdok/smooth-operator v0.1.1
1717
github.com/peterbourgon/ff v1.7.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR
151151
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
152152
github.com/pdok/featureinfo-generator v1.4.0-beta1 h1:ZZO5OtK7yW5ozXFrl1OaxKl0MK3XF5YGFh2692JZVN8=
153153
github.com/pdok/featureinfo-generator v1.4.0-beta1/go.mod h1:02Ryu7ZRkeha8SCfS6VYWCdKYZh0llskrfFgp6xRCjk=
154-
github.com/pdok/ogc-capabilities-generator v1.0.0-beta7 h1:w0dP2RQX0KEEovrq57NCM1w+Hlizg9mQlgdRBEqKX2g=
155-
github.com/pdok/ogc-capabilities-generator v1.0.0-beta7/go.mod h1:slk89sAgmWU5NCIKwGyciQWnm0RHmwhJYQ431E2CwSk=
154+
github.com/pdok/ogc-capabilities-generator v1.0.0-beta8 h1:8UAv64fArp8wjpwuRIzjjpr5aGLtEhBS7vbi0l5gMao=
155+
github.com/pdok/ogc-capabilities-generator v1.0.0-beta8/go.mod h1:2yUZlJikf5gGH6S33FszUiI9+j85gpIINfAFsCF/eNk=
156156
github.com/pdok/ogc-specifications v1.0.0-beta9 h1:VrdggKg4d2tSway/deztAfZTviXKX0AftfUuZTXx5j8=
157157
github.com/pdok/ogc-specifications v1.0.0-beta9/go.mod h1:YDngwkwrWOfc5MYnEYseiv97K1Y9bZXlVzwi/8EaIl8=
158158
github.com/pdok/smooth-operator v0.1.1 h1:rmsup4HmzJsxt4ZT9GWfj498dKLRfDhyuILeEkjju/A=

internal/controller/blobdownload/blob_download_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package blobdownload
22

33
import (
4-
"github.com/google/go-cmp/cmp"
54
"strings"
65
"testing"
76

7+
"github.com/google/go-cmp/cmp"
8+
89
v3 "github.com/pdok/mapserver-operator/api/v3"
910
smoothoperatorutils "github.com/pdok/smooth-operator/pkg/util"
1011
)

internal/controller/capabilitiesgenerator/default_bboxes.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package capabilitiesgenerator
22

33
import "github.com/pdok/ogc-specifications/pkg/wms130"
44

5+
// TODO Bounding boxes and default CRSes in this file are not used at the moment but are kept so we can use them again later
6+
7+
//nolint:unused
58
var defaultWMSBoundingBox = wms130.EXGeographicBoundingBox{
69
WestBoundLongitude: 2.52713,
710
EastBoundLongitude: 7.37403,
811
SouthBoundLatitude: 50.2129,
912
NorthBoundLatitude: 55.7212,
1013
}
1114

15+
//nolint:unused
1216
func getDefaultWMSCRSes() []wms130.CRS {
1317
return []wms130.CRS{{
1418
Namespace: "EPSG",
@@ -40,9 +44,10 @@ func getDefaultWMSCRSes() []wms130.CRS {
4044
}}
4145
}
4246

47+
//nolint:unused
4348
func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
4449
return []*wms130.LayerBoundingBox{
45-
&wms130.LayerBoundingBox{
50+
{
4651
CRS: "EPSG:28992",
4752
Minx: -25000,
4853
Miny: 250000,
@@ -51,7 +56,7 @@ func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
5156
Resx: 0,
5257
Resy: 0,
5358
},
54-
&wms130.LayerBoundingBox{
59+
{
5560
CRS: "EPSG:25831",
5661
Minx: -470271,
5762
Miny: 5.56231e+06,
@@ -60,7 +65,7 @@ func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
6065
Resx: 0,
6166
Resy: 0,
6267
},
63-
&wms130.LayerBoundingBox{
68+
{
6469
CRS: "EPSG:25832",
6570
Minx: 62461.6,
6671
Miny: 5.56555e+06,
@@ -69,7 +74,7 @@ func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
6974
Resx: 0,
7075
Resy: 0,
7176
},
72-
&wms130.LayerBoundingBox{
77+
{
7378
CRS: "EPSG:3034",
7479
Minx: 2.61336e+06,
7580
Miny: 3.509e+06,
@@ -78,7 +83,7 @@ func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
7883
Resx: 0,
7984
Resy: 0,
8085
},
81-
&wms130.LayerBoundingBox{
86+
{
8287
CRS: "EPSG:3035",
8388
Minx: 3.01676e+06,
8489
Miny: 3.81264e+06,
@@ -87,7 +92,7 @@ func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
8792
Resx: 0,
8893
Resy: 0,
8994
},
90-
&wms130.LayerBoundingBox{
95+
{
9196
CRS: "EPSG:3857",
9297
Minx: 281318,
9398
Miny: 6.48322e+06,
@@ -96,7 +101,7 @@ func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
96101
Resx: 0,
97102
Resy: 0,
98103
},
99-
&wms130.LayerBoundingBox{
104+
{
100105
CRS: "EPSG:4258",
101106
Minx: 50.2129,
102107
Miny: 2.52713,
@@ -105,7 +110,7 @@ func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
105110
Resx: 0,
106111
Resy: 0,
107112
},
108-
&wms130.LayerBoundingBox{
113+
{
109114
CRS: "EPSG:4326",
110115
Minx: 50.2129,
111116
Miny: 2.52713,
@@ -114,7 +119,7 @@ func getDefaultWMSLayerBoundingBoxes() []*wms130.LayerBoundingBox {
114119
Resx: 0,
115120
Resy: 0,
116121
},
117-
&wms130.LayerBoundingBox{
122+
{
118123
CRS: "CRS:84",
119124
Minx: 2.52713,
120125
Miny: 50.2129,

internal/controller/capabilitiesgenerator/mapper.go

Lines changed: 52 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package capabilitiesgenerator
22

33
import (
44
"fmt"
5+
"slices"
56
"strconv"
67
"strings"
78

@@ -221,8 +222,6 @@ func MapWMSToCapabilitiesGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoper
221222

222223
abstract := mapperutils.EscapeQuotes(wms.Spec.Service.Abstract)
223224

224-
maxWidth := 4000
225-
maxHeight := 4000
226225
serviceVersion := mapperutils.GetLabelValueByKey(wms.ObjectMeta.Labels, "service-version")
227226
if serviceVersion == nil {
228227
serviceVersion = mapperutils.GetLabelValueByKey(wms.ObjectMeta.Labels, "pdok.nl/service-version")
@@ -251,8 +250,8 @@ func MapWMSToCapabilitiesGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoper
251250
Fees: smoothoperatorutils.Pointer("NONE"),
252251
AccessConstraints: &wms.Spec.Service.AccessConstraints,
253252
OptionalConstraints: &wms130.OptionalConstraints{
254-
MaxWidth: maxWidth,
255-
MaxHeight: maxHeight,
253+
MaxWidth: int(smoothoperatorutils.PointerVal(wms.Spec.Service.MaxSize, 4000)),
254+
MaxHeight: int(smoothoperatorutils.PointerVal(wms.Spec.Service.MaxSize, 4000)),
256255
},
257256
},
258257
Capabilities: wms130.Capabilities{
@@ -377,60 +376,63 @@ func getDcpType(url string, fillPost bool) *wms130.DCPType {
377376
}
378377

379378
func getLayers(wms *pdoknlv3.WMS, canonicalURL string) []wms130.Layer {
380-
result := make([]wms130.Layer, 0)
381-
referenceLayer := wms.Spec.Service.Layer
382-
383-
var authorityURL *wms130.AuthorityURL
384-
var identifier *wms130.Identifier
379+
return []wms130.Layer{
380+
mapLayer(wms.Spec.Service.Layer, canonicalURL, nil, nil, nil),
381+
}
382+
}
385383

386-
if referenceLayer.Authority != nil {
384+
func mapLayer(layer pdoknlv3.Layer, canonicalURL string, authorityURL *wms130.AuthorityURL, identifier *wms130.Identifier, parentStyleNames []string) wms130.Layer {
385+
if layer.Authority != nil {
387386
authorityURL = &wms130.AuthorityURL{
388-
Name: referenceLayer.Authority.Name,
387+
Name: layer.Authority.Name,
389388
OnlineResource: wms130.OnlineResource{
390389
Xlink: smoothoperatorutils.Pointer(XLinkURL),
391390
Type: nil,
392-
Href: &referenceLayer.Authority.URL,
391+
Href: &layer.Authority.URL,
393392
},
394393
}
395394
identifier = &wms130.Identifier{
396-
Authority: referenceLayer.Authority.Name,
397-
Value: referenceLayer.Authority.SpatialDatasetIdentifier,
395+
Authority: layer.Authority.Name,
396+
Value: layer.Authority.SpatialDatasetIdentifier,
398397
}
399398
}
400-
topLayer := getTopLayer(wms, referenceLayer, authorityURL, identifier)
401-
402-
for _, layer := range referenceLayer.Layers {
403-
nestedLayer := getNestedLayer(layer, authorityURL, canonicalURL)
404399

405-
topLayer.Layer = append(topLayer.Layer, &nestedLayer)
400+
l := wms130.Layer{
401+
Queryable: smoothoperatorutils.Pointer(1),
402+
Opaque: nil,
403+
Name: layer.Name,
404+
Title: mapperutils.EscapeQuotes(smoothoperatorutils.PointerVal(layer.Title, "")),
405+
Abstract: smoothoperatorutils.Pointer(mapperutils.EscapeQuotes(smoothoperatorutils.PointerVal(layer.Abstract, ""))),
406+
KeywordList: &wms130.Keywords{Keyword: layer.Keywords},
407+
//CRS: defaultCrs,
408+
//EXGeographicBoundingBox: &defaultBoundingBox,
409+
//BoundingBox: allDefaultBoundingBoxes,
410+
Dimension: nil,
411+
Attribution: nil,
412+
AuthorityURL: authorityURL,
413+
Identifier: identifier,
414+
DataURL: nil,
415+
FeatureListURL: nil,
416+
Style: getLayerStyles(layer, canonicalURL, parentStyleNames),
417+
Layer: []*wms130.Layer{},
406418
}
407419

408-
result = append(result, topLayer)
409-
return result
410-
}
411-
412-
func getNestedLayer(layer pdoknlv3.Layer, authorityURL *wms130.AuthorityURL, canonicalURL string) wms130.Layer {
413-
var minScaleDenom *float64
414-
var maxScaleDenom *float64
415-
var innerIdentifier *wms130.Identifier
416-
metadataUrls := make([]*wms130.MetadataURL, 0)
417-
418420
if layer.MinScaleDenominator != nil {
419421
float, err := strconv.ParseFloat(*layer.MinScaleDenominator, 64)
420422
if err == nil {
421-
minScaleDenom = &float
423+
l.MinScaleDenominator = &float
422424
}
423425
}
424426

425427
if layer.MaxScaleDenominator != nil {
426428
float, err := strconv.ParseFloat(*layer.MaxScaleDenominator, 64)
427429
if err == nil {
428-
maxScaleDenom = &float
430+
l.MaxScaleDenominator = &float
429431
}
430432
}
431433

432434
if layer.DatasetMetadataURL != nil {
433-
metadataUrls = append(metadataUrls, &wms130.MetadataURL{
435+
l.MetadataURL = append(l.MetadataURL, &wms130.MetadataURL{
434436
Type: smoothoperatorutils.Pointer("TC211"),
435437
Format: smoothoperatorutils.Pointer("text/plain"),
436438
OnlineResource: wms130.OnlineResource{
@@ -441,46 +443,26 @@ func getNestedLayer(layer pdoknlv3.Layer, authorityURL *wms130.AuthorityURL, can
441443
})
442444
}
443445

444-
if layer.Authority != nil {
445-
authorityURL = &wms130.AuthorityURL{
446-
Name: layer.Authority.Name,
447-
OnlineResource: wms130.OnlineResource{
448-
Xlink: smoothoperatorutils.Pointer(XLinkURL),
449-
Type: nil,
450-
Href: &layer.Authority.URL,
451-
},
452-
}
453-
innerIdentifier = &wms130.Identifier{
454-
Authority: layer.Authority.Name,
455-
Value: layer.Authority.SpatialDatasetIdentifier,
456-
}
446+
layerStyleNames := []string{}
447+
for _, s := range l.Style {
448+
layerStyleNames = append(layerStyleNames, s.Name)
457449
}
458450

459-
nestedLayer := wms130.Layer{
460-
Queryable: smoothoperatorutils.Pointer(1),
461-
Opaque: nil,
462-
Name: layer.Name,
463-
Title: smoothoperatorutils.PointerVal(layer.Title, ""),
464-
Abstract: layer.Abstract,
465-
KeywordList: &wms130.Keywords{
466-
Keyword: layer.Keywords,
467-
},
468-
//CRS: defaultCrs,
469-
//EXGeographicBoundingBox: &defaultBoundingBox,
470-
//BoundingBox: allDefaultBoundingBoxes,
471-
Dimension: nil,
472-
Attribution: nil,
473-
AuthorityURL: authorityURL,
474-
Identifier: innerIdentifier,
475-
MetadataURL: metadataUrls,
476-
DataURL: nil,
477-
FeatureListURL: nil,
478-
Style: []*wms130.Style{},
479-
MinScaleDenominator: minScaleDenom,
480-
MaxScaleDenominator: maxScaleDenom,
481-
Layer: nil,
451+
// Map sublayers
452+
for _, sublayer := range layer.Layers {
453+
mapped := mapLayer(sublayer, canonicalURL, authorityURL, identifier, append(parentStyleNames, layerStyleNames...))
454+
l.Layer = append(l.Layer, &mapped)
482455
}
456+
457+
return l
458+
}
459+
460+
func getLayerStyles(layer pdoknlv3.Layer, canonicalURL string, parentStyleNames []string) (styles []*wms130.Style) {
483461
for _, style := range layer.Styles {
462+
if slices.Contains(parentStyleNames, style.Name) {
463+
continue
464+
}
465+
484466
newStyle := wms130.Style{
485467
Name: style.Name,
486468
Title: smoothoperatorutils.PointerVal(style.Title, ""),
@@ -497,38 +479,7 @@ func getNestedLayer(layer pdoknlv3.Layer, authorityURL *wms130.AuthorityURL, can
497479
},
498480
StyleSheetURL: nil,
499481
}
500-
nestedLayer.Style = append(nestedLayer.Style, &newStyle)
501-
}
502-
return nestedLayer
503-
}
504-
505-
func getTopLayer(wms *pdoknlv3.WMS, referenceLayer pdoknlv3.Layer, authorityURL *wms130.AuthorityURL, identifier *wms130.Identifier) wms130.Layer {
506-
title := referenceLayer.Title
507-
if title != nil {
508-
title = smoothoperatorutils.Pointer(mapperutils.EscapeQuotes(*referenceLayer.Title))
509-
} else {
510-
title = smoothoperatorutils.Pointer("")
511-
}
512-
return wms130.Layer{
513-
Queryable: smoothoperatorutils.Pointer(1),
514-
Opaque: nil,
515-
Name: nil,
516-
Title: *title,
517-
Abstract: smoothoperatorutils.Pointer(mapperutils.EscapeQuotes(wms.Spec.Service.Abstract)),
518-
KeywordList: &wms130.Keywords{Keyword: referenceLayer.Keywords},
519-
//CRS: defaultCrs,
520-
//EXGeographicBoundingBox: &defaultBoundingBox,
521-
//BoundingBox: allDefaultBoundingBoxes,
522-
Dimension: nil,
523-
Attribution: nil,
524-
AuthorityURL: authorityURL,
525-
Identifier: identifier,
526-
MetadataURL: nil,
527-
DataURL: nil,
528-
FeatureListURL: nil,
529-
Style: nil,
530-
MinScaleDenominator: nil,
531-
MaxScaleDenominator: nil,
532-
Layer: []*wms130.Layer{},
482+
styles = append(styles, &newStyle)
533483
}
484+
return
534485
}

internal/controller/legendgenerator/legend_generator_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package legendgenerator
22

33
import (
4-
"github.com/google/go-cmp/cmp"
54
"os"
65
"testing"
76

7+
"github.com/google/go-cmp/cmp"
8+
89
"github.com/pdok/mapserver-operator/api/v2beta1"
910
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
1011
"github.com/stretchr/testify/assert"

0 commit comments

Comments
 (0)