Skip to content

Commit 029cd0f

Browse files
author
Jelle Dijkstra
committed
Refactored layer classification to fix tests
1 parent eb8fa3e commit 029cd0f

File tree

6 files changed

+52
-37
lines changed

6 files changed

+52
-37
lines changed

api/v3/wms_types.go

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -313,39 +313,38 @@ type AnnotatedLayer struct {
313313
func (wmsService *WMSService) GetAnnotatedLayers() []AnnotatedLayer {
314314
result := make([]AnnotatedLayer, 0)
315315

316-
topLayer := wmsService.Layer
317-
annotatedTopLayer := AnnotatedLayer{
318-
GroupName: nil,
319-
IsTopLayer: true,
320-
IsGroupLayer: topLayer.Name != nil,
321-
IsDataLayer: false,
322-
Layer: topLayer,
316+
firstLayer := AnnotatedLayer{}
317+
if wmsService.Layer.Name != nil && len(*wmsService.Layer.Name) > 0 {
318+
firstLayer = AnnotatedLayer{
319+
GroupName: nil,
320+
IsTopLayer: wmsService.Layer.IsTopLayer(),
321+
IsGroupLayer: wmsService.Layer.IsGroupLayer(),
322+
IsDataLayer: wmsService.Layer.IsDataLayer(),
323+
Layer: wmsService.Layer,
324+
}
325+
result = append(result, firstLayer)
323326
}
324-
result = append(result, annotatedTopLayer)
325327

326-
for _, topLayerChild := range topLayer.Layers {
327-
groupName := topLayer.Name
328-
isGroupLayer := topLayerChild.Layers != nil && len(topLayerChild.Layers) > 0
328+
for _, subLayer := range wmsService.Layer.Layers {
329+
groupName := wmsService.Layer.Name
330+
isGroupLayer := subLayer.IsGroupLayer()
329331
isDataLayer := !isGroupLayer
330332
result = append(result, AnnotatedLayer{
331333
GroupName: groupName,
332334
IsTopLayer: false,
333335
IsGroupLayer: isGroupLayer,
334336
IsDataLayer: isDataLayer,
335-
Layer: topLayerChild,
337+
Layer: subLayer,
336338
})
337339

338-
if len(topLayerChild.Layers) > 0 {
339-
for _, middleLayerChild := range topLayerChild.Layers {
340-
groupName = topLayerChild.Name
341-
result = append(result, AnnotatedLayer{
342-
GroupName: groupName,
343-
IsTopLayer: false,
344-
IsGroupLayer: false,
345-
IsDataLayer: true,
346-
Layer: middleLayerChild,
347-
})
348-
}
340+
for _, subSubLayer := range subLayer.Layers {
341+
result = append(result, AnnotatedLayer{
342+
GroupName: subLayer.Name,
343+
IsTopLayer: false,
344+
IsGroupLayer: false,
345+
IsDataLayer: true,
346+
Layer: subSubLayer,
347+
})
349348
}
350349
}
351350

@@ -423,8 +422,22 @@ func (layer *Layer) IsGroupLayer() bool {
423422
return len(layer.Layers) > 0
424423
}
425424

426-
func (layer *Layer) IsTopLayer(service *WMSService) bool {
427-
return layer.Name == service.Layer.Name
425+
// IsTopLayer - a layer is a toplayer if and only if it has sublayers that are group layers.
426+
// In other words the layer is level 1 in a 3 level hierarchy.
427+
func (layer *Layer) IsTopLayer() bool {
428+
if layer.IsGroupLayer() {
429+
for _, childLayer := range layer.Layers {
430+
if childLayer.IsGroupLayer() {
431+
return true
432+
}
433+
}
434+
}
435+
436+
return false
437+
}
438+
439+
func (layer *Layer) IsVisible() bool {
440+
return layer.Visible == nil || *layer.Visible
428441
}
429442

430443
func (layer *Layer) hasBoundingBoxForCRS(crs string) bool {

config/crd/bases/pdok.nl_wfs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ spec:
456456
horizontalPodAutoscalerPatch:
457457
description: |-
458458
HorizontalPodAutoscalerPatch - copy of autoscalingv2.HorizontalPodAutoscalerSpec without ScaleTargetRef
459-
To that v3 CRD end up with an empty scaleTargetRef when marshalling. This can be removed when we're done with converting CRDs.
459+
This way we don't have to specify the scaleTargetRef field in the CRD.
460460
properties:
461461
behavior:
462462
description: |-

internal/controller/capabilitiesgenerator/capabilities_generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ func TestGetInputForWFS(t *testing.T) {
558558
Title: "some Service title",
559559
Abstract: "some \"Service\" abstract",
560560
Keywords: []string{"service-keyword-1", "service-keyword-2", "infoFeatureAccessService"},
561-
AccessConstraints: "http://creativecommons.org/publicdomain/zero/1.0/deed.nl",
561+
AccessConstraints: smoothoperatorutils.Pointer("http://creativecommons.org/publicdomain/zero/1.0/deed.nl"),
562562
Inspire: &pdoknlv3.Inspire{
563563
ServiceMetadataURL: pdoknlv3.MetadataURL{
564564
CSW: &pdoknlv3.Metadata{

internal/controller/capabilitiesgenerator/mapper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoper
4646
ServiceIdentification: wfs200.ServiceIdentification{
4747
Title: mapperutils.EscapeQuotes(wfs.Spec.Service.Title),
4848
Abstract: mapperutils.EscapeQuotes(wfs.Spec.Service.Abstract),
49-
AccessConstraints: wfs.Spec.Service.AccessConstraints,
49+
AccessConstraints: *wfs.Spec.Service.AccessConstraints,
5050
Keywords: &wsc110.Keywords{
5151
Keyword: wfs.Spec.Service.Keywords,
5252
},
@@ -221,8 +221,8 @@ func MapWMSToCapabilitiesGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoper
221221
maxHeight := 4000
222222

223223
accessContraints := wms.Spec.Service.AccessConstraints
224-
if accessContraints == "" {
225-
accessContraints = "https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
224+
if accessContraints == nil || *accessContraints == "" {
225+
accessContraints = smoothoperatorutils.Pointer("https://creativecommons.org/publicdomain/zero/1.0/deed.nl")
226226
}
227227

228228
config := capabilitiesgenerator.Config{
@@ -245,7 +245,7 @@ func MapWMSToCapabilitiesGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoper
245245
OnlineResource: wms130.OnlineResource{Href: &hostBaseURL},
246246
ContactInformation: getContactInformation(ownerInfo),
247247
Fees: fees,
248-
AccessConstraints: &accessContraints,
248+
AccessConstraints: accessContraints,
249249
LayerLimit: nil,
250250
MaxWidth: &maxWidth,
251251
MaxHeight: &maxHeight,

internal/controller/mapfilegenerator/mapfile_generator_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestGetConfigForWFS(t *testing.T) {
130130
Title: "some Service title",
131131
Abstract: "some \"Service\" abstract",
132132
Keywords: []string{"service-keyword-1", "service-keyword-2", "infoFeatureAccessService"},
133-
AccessConstraints: "http://creativecommons.org/publicdomain/zero/1.0/deed.nl",
133+
AccessConstraints: smoothoperatorutils.Pointer("http://creativecommons.org/publicdomain/zero/1.0/deed.nl"),
134134
Bbox: &pdoknlv3.Bbox{
135135
DefaultCRS: shared_model.BBox{
136136
MinX: "0.0",
@@ -317,6 +317,7 @@ func TestGetConfigForWMSWithGroupLayersAndTopGroupLayer(t *testing.T) {
317317
inputStruct, err := MapWMSToMapfileGeneratorInput(&wms, ownerInfo)
318318
assert.NoError(t, err)
319319
expected := WMSInput{}
320+
assert.NoError(t, err)
320321
err = json.Unmarshal([]byte(WMSGroupAndToplayerConfig), &expected)
321322
assert.NoError(t, err)
322323

internal/controller/mapfilegenerator/mapper.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func MapWMSToMapfileGeneratorInput(wms *pdoknlv3.WMS, _ *smoothoperatorv1.OwnerI
118118
service := wms.Spec.Service
119119

120120
accessConstraints := service.AccessConstraints
121-
if accessConstraints == "" {
122-
accessConstraints = "https://creativecommons.org/publicdomain/zero/1.0/deed.nl"
121+
if accessConstraints == nil || *accessConstraints == "" {
122+
accessConstraints = smoothoperatorutils.Pointer("https://creativecommons.org/publicdomain/zero/1.0/deed.nl")
123123
}
124124

125125
datasetOwner := ""
@@ -183,7 +183,7 @@ func MapWMSToMapfileGeneratorInput(wms *pdoknlv3.WMS, _ *smoothoperatorv1.OwnerI
183183
DataEPSG: service.DataEPSG,
184184
EPSGList: epsgs,
185185
},
186-
AccessConstraints: accessConstraints,
186+
AccessConstraints: *accessConstraints,
187187
Layers: []WMSLayer{},
188188
GroupLayers: []GroupLayer{},
189189
Symbols: getSymbols(wms),
@@ -199,7 +199,7 @@ func MapWMSToMapfileGeneratorInput(wms *pdoknlv3.WMS, _ *smoothoperatorv1.OwnerI
199199
if annotatedLayer.IsDataLayer {
200200
layer := getWMSLayer(annotatedLayer.Layer, extent, wms)
201201
result.Layers = append(result.Layers, layer)
202-
} else if annotatedLayer.IsGroupLayer && *annotatedLayer.Layer.Visible {
202+
} else if annotatedLayer.IsGroupLayer && !annotatedLayer.IsTopLayer {
203203
groupLayer := GroupLayer{
204204
Name: *annotatedLayer.Layer.Name,
205205
Title: smoothoperatorutils.PointerVal(annotatedLayer.Layer.Title, ""),
@@ -222,7 +222,8 @@ func getWMSLayer(serviceLayer pdoknlv3.Layer, serviceExtent string, wms *pdoknlv
222222

223223
groupName := ""
224224
parent := serviceLayer.GetParent(&wms.Spec.Service.Layer)
225-
if parent.IsGroupLayer() && parent.Name != nil && *parent.Visible {
225+
// If the layer falls directly under the toplayer, the groupname is omitted
226+
if !parent.IsTopLayer() && parent.IsGroupLayer() && parent.Name != nil && parent.IsVisible() {
226227
groupName = *parent.Name
227228
}
228229

0 commit comments

Comments
 (0)