Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions api/v3/wms_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ SOFTWARE.
package v3

import (
"maps"
"slices"
"sort"

shared_model "github.com/pdok/smooth-operator/model"
autoscalingv2 "k8s.io/api/autoscaling/v2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"maps"
"slices"
"sort"
)

const (
topLayer = "topLayer"
dataLayer = "dataLayer"
groupLayer = "groupLayer"
TopLayer = "topLayer"
DataLayer = "dataLayer"
GroupLayer = "groupLayer"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -161,16 +162,34 @@ func init() {
SchemeBuilder.Register(&WMS{}, &WMSList{})
}

func (layer *Layer) getAllLayers() (layers []Layer) {
func (layer *Layer) GetAllLayers() (layers []Layer) {
layers = append(layers, *layer)
if layer.Layers != nil {
for _, childLayer := range *layer.Layers {
layers = append(layers, childLayer.getAllLayers()...)
layers = append(layers, childLayer.GetAllLayers()...)
}
}
return
}

func (layer *Layer) GetParent(candidateLayer *Layer) *Layer {
if candidateLayer.Layers == nil {
return nil
}

for _, childLayer := range *candidateLayer.Layers {
if childLayer.Name == layer.Name {
return candidateLayer
} else {
parent := layer.GetParent(&childLayer)
if parent != nil {
return parent
}
}
}
return nil
}

func (layer *Layer) hasData() bool {
switch {
case layer.Data == nil:
Expand All @@ -193,17 +212,25 @@ func (layer *Layer) hasTIFData() bool {
return layer.Data.TIF != nil && layer.Data.TIF.BlobKey != ""
}

func (layer *Layer) getLayerType(service *WMSService) (layerType string) {
func (layer *Layer) GetLayerType(service *WMSService) (layerType string) {
switch {
case layer.hasData() && layer.Layers == nil:
return dataLayer
return DataLayer
case layer.Name == service.Layer.Name:
return topLayer
return TopLayer
default:
return groupLayer
return GroupLayer
}
}

func (layer *Layer) IsDataLayer(service *WMSService) bool {
return layer.GetLayerType(service) == DataLayer
}

func (layer *Layer) IsGroupLayer(service *WMSService) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deze function heeft Leon nu ook geschreven, even verwijderen na merge, als het al geen conflict oplevert

return layer.GetLayerType(service) == GroupLayer
}

func (layer *Layer) hasBoundingBoxForCRS(crs string) bool {
for _, bbox := range layer.BoundingBoxes {
if bbox.CRS == crs {
Expand Down Expand Up @@ -233,7 +260,7 @@ func (layer *Layer) setInheritedBoundingBoxes() {
}

func (wms *WMS) GetAllLayersWithLegend() (layers []Layer) {
for _, layer := range wms.Spec.Service.Layer.getAllLayers() {
for _, layer := range wms.Spec.Service.Layer.GetAllLayers() {
if !layer.hasData() || len(layer.Styles) == 0 {
continue
}
Expand All @@ -249,7 +276,7 @@ func (wms *WMS) GetAllLayersWithLegend() (layers []Layer) {

func (wms *WMS) GetUniqueTiffBlobKeys() []string {
blobKeys := map[string]bool{}
for _, layer := range wms.Spec.Service.Layer.getAllLayers() {
for _, layer := range wms.Spec.Service.Layer.GetAllLayers() {
if layer.hasTIFData() {
blobKeys[layer.Data.TIF.BlobKey] = true
}
Expand Down Expand Up @@ -280,7 +307,7 @@ func (wms *WMS) GetAuthority() *Authority {
}

func (wms *WMS) HasPostgisData() bool {
for _, layer := range wms.Spec.Service.Layer.getAllLayers() {
for _, layer := range wms.Spec.Service.Layer.GetAllLayers() {
if layer.Data != nil && layer.Data.Postgis != nil {
return true
}
Expand Down
37 changes: 37 additions & 0 deletions api/v3/wms_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v3
import (
"github.com/google/go-cmp/cmp"
"github.com/pdok/smooth-operator/model"
"reflect"
"testing"
)

Expand Down Expand Up @@ -124,3 +125,39 @@ func TestLayer_setInheritedBoundingBoxes(t *testing.T) {
})
}
}

func TestLayer_GetParent(t *testing.T) {
childLayer2 := Layer{Name: "childlayer-2"}
childLayer1 := Layer{Name: "childlayer-1", Layers: &[]Layer{childLayer2}}
topLayer := Layer{Name: "toplayer", Layers: &[]Layer{childLayer1}}

type args struct {
candidateLayer *Layer
}
tests := []struct {
name string
layer Layer
args args
want *Layer
}{
{
name: "Test GetParent on layer with parent",
layer: childLayer2,
args: args{candidateLayer: &topLayer},
want: &childLayer1,
},
{
name: "Test GetParent on layer without parent",
layer: topLayer,
args: args{candidateLayer: &topLayer},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.layer.GetParent(tt.args.candidateLayer); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetParent() = %v, want %v", got, tt.want)
}
})
}
}
9 changes: 5 additions & 4 deletions api/v3/wms_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {
var names []string
hasVisibleLayer := false
wms.Spec.Service.Layer.setInheritedBoundingBoxes()
for _, layer := range wms.Spec.Service.Layer.getAllLayers() {
for _, layer := range wms.Spec.Service.Layer.GetAllLayers() {
var layerReasons []string
if slices.Contains(names, layer.Name) {
*reasons = append(*reasons, fmt.Sprintf("layer names must be unique, layer.name '%s' is duplicated", layer.Name))
Expand Down Expand Up @@ -162,8 +162,8 @@ func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {
}
}
}
layerType := layer.getLayerType(&service)
if layerType == dataLayer {

if layer.IsDataLayer(&wms.Spec.Service) {
for _, style := range layer.Styles {
if wms.Spec.Service.Mapfile == nil && style.Visualization == nil {
layerReasons = append(layerReasons, fmt.Sprintf("invalid style: '%s': style.visualization must be set on a dataLayer", style.Name))
Expand All @@ -173,7 +173,8 @@ func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {
}
}
}
if layerType == groupLayer || layerType == topLayer {
layerType := layer.GetLayerType(&service)
if layerType == GroupLayer || layerType == TopLayer {
if !*layer.Visible {
layerReasons = append(layerReasons, layerType+" must be visible")
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
defaultMultitoolImage = "docker.io/pdok/docker-multitool:0.9.1"
defaultMapfileGeneratorImage = "docker.io/pdok/mapfile-generator:1.9.3"
defaultCapabilitiesGeneratorImage = "docker.io/pdok/ogc-capabilities-generator:1.0.0-beta5"
defaultFeatureinfoGeneratorImage = "docker.io/pdok/featureinfo-generator:v1.4.0-beta1"
)

var (
Expand Down Expand Up @@ -78,6 +79,7 @@
var multitoolImage string
var mapfileGeneratorImage string
var capabilitiesGeneratorImage string
var featureinfoGeneratorImage string
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
Expand All @@ -99,6 +101,7 @@
flag.StringVar(&multitoolImage, "multitool-image", defaultMultitoolImage, "The image to use in the blob download init-container.")
flag.StringVar(&mapfileGeneratorImage, "mapfile-generator-image", defaultMapfileGeneratorImage, "The image to use in the mapfile generator init-container.")
flag.StringVar(&capabilitiesGeneratorImage, "capabilities-generator-image", defaultCapabilitiesGeneratorImage, "The image to use in the capabilities generator init-container.")
flag.StringVar(&featureinfoGeneratorImage, "featureinfo-generator-image", defaultFeatureinfoGeneratorImage, "The image to use in the featureinfo generator init-container.")

opts := zap.Options{
Development: true,
Expand Down Expand Up @@ -228,8 +231,9 @@
}

if err = (&controller.WMSReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
FeatureinfoGeneratorImage: featureinfoGeneratorImage,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "WMS")
os.Exit(1)
Expand All @@ -245,7 +249,7 @@
os.Exit(1)
}

if os.Getenv("ENABLE_WEBHOOKS") != "false" {

Check failure on line 252 in cmd/main.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

string `false` has 3 occurrences, make it a constant (goconst)

Check failure on line 252 in cmd/main.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

string `false` has 3 occurrences, make it a constant (goconst)
if err = webhookpdoknlv3.SetupWFSWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "WFS")
os.Exit(1)
Expand Down
Loading
Loading