Skip to content

Commit 85f8de4

Browse files
author
Jelle Dijkstra
committed
Fixed capabilities generator
2 parents 2b1089a + 0f2242f commit 85f8de4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2723
-948
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ FROM docker.io/golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

6+
COPY --from=repos ./smooth-operator /smooth-operator
7+
68
WORKDIR /workspace
79
# Copy the Go Modules manifests
810
COPY go.mod go.mod

api/v2beta1/wms_conversion.go

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -267,54 +267,73 @@ func (v2Service WMSService) GetTopLayer() (*WMSLayer, error) {
267267
return nil, errors.New("unable to detect the toplayer of this WMS service")
268268
}
269269

270-
func (v2Service WMSService) GetChildLayers(parent WMSLayer) ([]WMSLayer, error) {
271-
children := make([]WMSLayer, 0)
272-
270+
// MapLayersToV3
271+
func (v2Service WMSService) MapLayersToV3() pdoknlv3.Layer {
272+
// Creates map of Groups: layers in that group
273+
// and a list of all layers without a group
274+
groupedLayers := map[string][]pdoknlv3.Layer{}
275+
var notGroupedLayers []pdoknlv3.Layer
273276
for _, layer := range v2Service.Layers {
274-
if layer.Group != nil && *layer.Group == parent.Name {
275-
children = append(children, layer)
277+
if layer.Group == nil {
278+
notGroupedLayers = append(notGroupedLayers, layer.MapToV3(v2Service))
279+
} else {
280+
groupedLayers[*layer.Group] = append(groupedLayers[*layer.Group], layer.MapToV3(v2Service))
276281
}
277282
}
278283

279-
if len(children) == 0 {
280-
return children, errors.New("no child layers found")
284+
// if a topLayer is defined in the v2 it be the only layer without a group
285+
// and there are other layers that have the topLayer as their group
286+
// so if there is exactly 1 layer without a group
287+
// and the name of that layer exist as a key in the map of Groups: layer in that group
288+
// then that layer must be the topLayer
289+
var topLayer *pdoknlv3.Layer
290+
if len(notGroupedLayers) == 1 {
291+
_, ok := groupedLayers[*notGroupedLayers[0].Name]
292+
if ok {
293+
topLayer = &notGroupedLayers[0]
294+
}
281295
}
282296

283-
return children, nil
284-
}
285-
286-
// MapLayersToV3
287-
func (v2Service WMSService) MapLayersToV3() pdoknlv3.Layer {
288-
topLayer, err := v2Service.GetTopLayer()
289-
if err != nil {
290-
panic(err)
291-
}
297+
var middleLayers []pdoknlv3.Layer
292298

293-
var layer pdoknlv3.Layer
299+
// if the topLayer is not defined in the v2 layers
300+
// it needs to be created with defaults from the service
301+
// and in this case the middleLayers are all layers without a group
294302
if topLayer == nil {
295-
layer = pdoknlv3.Layer{
296-
Name: "wms",
303+
topLayer = &pdoknlv3.Layer{
297304
Title: &v2Service.Title,
298305
Abstract: &v2Service.Abstract,
299306
Keywords: v2Service.Keywords,
300307
Layers: &[]pdoknlv3.Layer{},
301308
}
302309

303-
var childLayersV3 []pdoknlv3.Layer
304-
for _, childLayer := range v2Service.Layers {
305-
childLayersV3 = append(childLayersV3, childLayer.MapToV3(v2Service))
310+
// adding the bottom layers to the middle layers they are grouped by
311+
for _, layer := range notGroupedLayers {
312+
bottomLayers := groupedLayers[*layer.Name]
313+
layer.Layers = &bottomLayers
314+
middleLayers = append(middleLayers, layer)
306315
}
307-
layer.Layers = &childLayersV3
308-
} else {
309-
layer = topLayer.MapToV3(v2Service)
310316
}
311317

312-
return layer
318+
// if the topLayer is defined in the v2 layers
319+
// meaning the topLayer has a name at this point
320+
// then the middleLayers are all layers that had the topLayer name as their group
321+
// and the bottomLayers are all layers that had a middleLayer as a group
322+
if topLayer.Name != nil {
323+
for _, layer := range groupedLayers[*topLayer.Name] {
324+
bottomLayers := groupedLayers[*layer.Name]
325+
layer.Layers = &bottomLayers
326+
middleLayers = append(middleLayers, layer)
327+
}
328+
}
329+
topLayer.Layers = &middleLayers
330+
331+
return *topLayer
313332
}
314333

315334
func (v2Layer WMSLayer) MapToV3(v2Service WMSService) pdoknlv3.Layer {
316335
layer := pdoknlv3.Layer{
317-
Name: v2Layer.Name,
336+
Name: &v2Layer.Name,
318337
Title: v2Layer.Title,
319338
Abstract: v2Layer.Abstract,
320339
Keywords: v2Layer.Keywords,
@@ -382,17 +401,6 @@ func (v2Layer WMSLayer) MapToV3(v2Service WMSService) pdoknlv3.Layer {
382401

383402
if v2Layer.Data != nil {
384403
layer.Data = Pointer(ConvertV2DataToV3(*v2Layer.Data))
385-
} else {
386-
childLayersV2, err := v2Service.GetChildLayers(v2Layer)
387-
if err != nil {
388-
panic(err)
389-
}
390-
391-
var childLayersV3 []pdoknlv3.Layer
392-
for _, childLayer := range childLayersV2 {
393-
childLayersV3 = append(childLayersV3, childLayer.MapToV3(v2Service))
394-
}
395-
layer.Layers = &childLayersV3
396404
}
397405

398406
return layer
@@ -401,7 +409,7 @@ func (v2Layer WMSLayer) MapToV3(v2Service WMSService) pdoknlv3.Layer {
401409
func mapV3LayerToV2Layers(v3Layer pdoknlv3.Layer, parent *pdoknlv3.Layer, serviceEPSG string) []WMSLayer {
402410
var layers []WMSLayer
403411

404-
if parent == nil && v3Layer.Name == "wms" {
412+
if parent == nil && *v3Layer.Name == "wms" {
405413
// Default top layer, do not include in v2 layers
406414
if v3Layer.Layers != nil {
407415
for _, childLayer := range *v3Layer.Layers {
@@ -410,7 +418,7 @@ func mapV3LayerToV2Layers(v3Layer pdoknlv3.Layer, parent *pdoknlv3.Layer, servic
410418
}
411419
} else {
412420
v2Layer := WMSLayer{
413-
Name: v3Layer.Name,
421+
Name: *v3Layer.Name,
414422
Title: v3Layer.Title,
415423
Abstract: v3Layer.Abstract,
416424
Keywords: v3Layer.Keywords,
@@ -421,7 +429,7 @@ func mapV3LayerToV2Layers(v3Layer pdoknlv3.Layer, parent *pdoknlv3.Layer, servic
421429
v2Layer.Visible = PointerVal(v3Layer.Visible, true)
422430

423431
if parent != nil {
424-
v2Layer.Group = &parent.Name
432+
v2Layer.Group = parent.Name
425433
}
426434

427435
if v3Layer.DatasetMetadataURL != nil && v3Layer.DatasetMetadataURL.CSW != nil {

api/v3/shared_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,8 @@ func Sha1HashOfName[O WMSWFS](obj O) string {
158158

159159
return hex.EncodeToString(s.Sum(nil))
160160
}
161+
162+
func (o *Options) UseWebserviceProxy() bool {
163+
// options.DisableWebserviceProxy not set or false
164+
return o != nil && (o.DisableWebserviceProxy == nil || !*o.DisableWebserviceProxy)
165+
}

api/v3/wfs_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ type WFSSpec struct {
7878
}
7979

8080
type WFSService struct {
81+
// Geonovum subdomein
82+
// +kubebuilder:validation:MinLength:=1
8183
Prefix string `json:"prefix"`
8284
URL string `json:"url"`
8385
Inspire *Inspire `json:"inspire,omitempty"`

api/v3/wms_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type ConfigMapRef struct {
8888
}
8989

9090
type Layer struct {
91-
Name string `json:"name"`
91+
Name *string `json:"name"`
9292
Title *string `json:"title,omitempty"`
9393
Abstract *string `json:"abstract,omitempty"`
9494
Keywords []string `json:"keywords"`

api/v3/wms_types_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package v3
33
import (
44
"github.com/google/go-cmp/cmp"
55
"github.com/pdok/smooth-operator/model"
6+
controller "github.com/pdok/smooth-operator/pkg/util"
67
"reflect"
78
"testing"
89
)
@@ -58,19 +59,19 @@ func TestLayer_setInheritedBoundingBoxes(t *testing.T) {
5859
{
5960
name: "setInheritedBoundingBoxes for layer",
6061
layer: Layer{
61-
Name: "toplayer",
62+
Name: controller.Pointer("toplayer"),
6263
BoundingBoxes: []WMSBoundingBox{first28992BoundingBox},
6364
Layers: &[]Layer{
6465
{
65-
Name: "grouplayer-1",
66+
Name: controller.Pointer("grouplayer-1"),
6667
BoundingBoxes: []WMSBoundingBox{first4326BoundingBox},
6768
Layers: &[]Layer{
6869
{
69-
Name: "datalayer-1",
70+
Name: controller.Pointer("datalayer-1"),
7071
BoundingBoxes: []WMSBoundingBox{first4258BoundingBox},
7172
},
7273
{
73-
Name: "datalayer-2",
74+
Name: controller.Pointer("datalayer-2"),
7475
BoundingBoxes: []WMSBoundingBox{second28992BoundingBox},
7576
},
7677
},
@@ -127,9 +128,9 @@ func TestLayer_setInheritedBoundingBoxes(t *testing.T) {
127128
}
128129

129130
func TestLayer_GetParent(t *testing.T) {
130-
childLayer2 := Layer{Name: "childlayer-2"}
131-
childLayer1 := Layer{Name: "childlayer-1", Layers: &[]Layer{childLayer2}}
132-
topLayer := Layer{Name: "toplayer", Layers: &[]Layer{childLayer1}}
131+
childLayer2 := Layer{Name: controller.Pointer("childlayer-2")}
132+
childLayer1 := Layer{Name: controller.Pointer("childlayer-1"), Layers: &[]Layer{childLayer2}}
133+
topLayer := Layer{Name: controller.Pointer("toplayer"), Layers: &[]Layer{childLayer1}}
133134

134135
type args struct {
135136
candidateLayer *Layer

api/v3/wms_validation.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {
9595
wms.Spec.Service.Layer.setInheritedBoundingBoxes()
9696
for _, layer := range wms.Spec.Service.Layer.GetAllLayers() {
9797
var layerReasons []string
98-
if slices.Contains(names, layer.Name) {
99-
*reasons = append(*reasons, fmt.Sprintf("layer names must be unique, layer.name '%s' is duplicated", layer.Name))
98+
if slices.Contains(names, *layer.Name) {
99+
*reasons = append(*reasons, fmt.Sprintf("layer names must be unique, layer.name '%s' is duplicated", *layer.Name))
100100
}
101-
names = append(names, layer.Name)
101+
names = append(names, *layer.Name)
102102
if service.Mapfile != nil && layer.BoundingBoxes != nil {
103103
*warnings = append(*warnings, sharedValidation.FormatValidationWarning("layer.boundingBoxes is not used when service.mapfile is configured", wms.GroupVersionKind(), wms.GetName()))
104104
}
@@ -154,7 +154,7 @@ func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {
154154
}
155155
}
156156
if !rewriteGroupToDataLayers && validateChildStyleNameEqual {
157-
equalStylesNames, ok := equalChildStyleNames[layer.Name]
157+
equalStylesNames, ok := equalChildStyleNames[*layer.Name]
158158
if ok {
159159
for _, styleName := range equalStylesNames {
160160
layerReasons = append(layerReasons, fmt.Sprintf("invalid style: '%s': style.name from parent layer must not be set on a child layer", styleName))
@@ -188,7 +188,7 @@ func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {
188188
}
189189
}
190190
if len(layerReasons) != 0 {
191-
*reasons = append(*reasons, fmt.Sprintf("%s '%s' is invalid: ", layerType, layer.Name)+strings.Join(layerReasons, ", "))
191+
*reasons = append(*reasons, fmt.Sprintf("%s '%s' is invalid: ", layerType, *layer.Name)+strings.Join(layerReasons, ", "))
192192
}
193193
}
194194

@@ -212,7 +212,7 @@ func findEqualChildStyleNames(layer *Layer, equalStyleNames *map[string][]string
212212
}
213213
}
214214
if len(equalStyles) > 0 {
215-
equalChildStyleNames[childLayer.Name] = equalStyles
215+
equalChildStyleNames[*childLayer.Name] = equalStyles
216216
}
217217
findEqualChildStyleNames(&childLayer, equalStyleNames)
218218
}

api/v3/wms_validation_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v3
22

33
import (
4+
controller "github.com/pdok/smooth-operator/pkg/util"
45
"reflect"
56
"testing"
67
)
@@ -19,21 +20,21 @@ func Test_getEqualChildStyleNames(t *testing.T) {
1920
name: "Test equal style names",
2021
args: args{
2122
layer: &Layer{
22-
Name: "toplayer",
23+
Name: controller.Pointer("toplayer"),
2324
Styles: []Style{
2425
{Name: "stylename-1"},
2526
{Name: "stylename-2"},
2627
},
2728
Layers: &[]Layer{
2829
{
29-
Name: "childlayer-1",
30+
Name: controller.Pointer("childlayer-1"),
3031
Styles: []Style{
3132
{Name: "stylename-2"},
3233
{Name: "stylename-3"},
3334
},
3435
Layers: &[]Layer{
3536
{
36-
Name: "childlayer-2",
37+
Name: controller.Pointer("childlayer-2"),
3738
Styles: []Style{
3839
{Name: "stylename-3"},
3940
{Name: "stylename-4"},
@@ -54,21 +55,21 @@ func Test_getEqualChildStyleNames(t *testing.T) {
5455
name: "Test no equal style names",
5556
args: args{
5657
layer: &Layer{
57-
Name: "toplayer",
58+
Name: controller.Pointer("toplayer"),
5859
Styles: []Style{
5960
{Name: "stylename-1"},
6061
{Name: "stylename-2"},
6162
},
6263
Layers: &[]Layer{
6364
{
64-
Name: "childlayer-1",
65+
Name: controller.Pointer("childlayer-1"),
6566
Styles: []Style{
6667
{Name: "stylename-3"},
6768
{Name: "stylename-4"},
6869
},
6970
Layers: &[]Layer{
7071
{
71-
Name: "childlayer-2",
72+
Name: controller.Pointer("childlayer-2"),
7273
Styles: []Style{
7374
{Name: "stylename-5"},
7475
{Name: "stylename-6"},

api/v3/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)