Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@
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 @@ -67,7 +68,7 @@
AccessConstraints string `json:"accessConstraints"`
MaxSize *int32 `json:"maxSize,omitempty"`
Inspire *Inspire `json:"inspire,omitempty"`
DataEPSG string `json:"dataEPSG"`

Check failure on line 71 in api/v3/wms_types.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

json(camel): got 'dataEPSG' want 'dataEpsg' (tagliatelle)
Resolution *int32 `json:"resolution,omitempty"`
DefResolution *int32 `json:"defResolution,omitempty"`
StylingAssets *StylingAssets `json:"stylingAssets,omitempty"`
Expand Down Expand Up @@ -161,16 +162,34 @@
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 {

Check failure on line 183 in api/v3/wms_types.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
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 @@
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 @@ -232,8 +259,8 @@
*layer.Layers = updatedLayers
}

func (wms *WMS) GetAllLayersWithLegend() (layers []Layer) {

Check failure on line 262 in api/v3/wms_types.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

method Layer.IsGroupLayer already declared at api/v3/wms_types.go:230:21

Check failure on line 262 in api/v3/wms_types.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

method Layer.IsGroupLayer already declared at api/v3/wms_types.go:230:21) (typecheck)

Check failure on line 262 in api/v3/wms_types.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

method Layer.IsGroupLayer already declared at api/v3/wms_types.go:230:21) (typecheck)

Check failure on line 262 in api/v3/wms_types.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

method Layer.IsGroupLayer already declared at api/v3/wms_types.go:230:21
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) 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) 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
@@ -1,8 +1,9 @@
package v3

import (
"github.com/google/go-cmp/cmp"

Check failure on line 4 in api/v3/wms_types_test.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

File is not properly formatted (goimports)
"github.com/pdok/smooth-operator/model"
"reflect"
"testing"
)

Expand Down Expand Up @@ -124,3 +125,39 @@
})
}
}

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 @@ -2,7 +2,7 @@

import (
"fmt"
sharedValidation "github.com/pdok/smooth-operator/pkg/validation"

Check failure on line 5 in api/v3/wms_validation.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

File is not properly formatted (goimports)
"k8s.io/utils/strings/slices"
"maps"
"strings"
Expand Down Expand Up @@ -54,7 +54,7 @@
return warnings, nil
}

func validateWMS(wms *WMS, warnings *[]string, reasons *[]string) {

Check failure on line 57 in api/v3/wms_validation.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

calculated cyclomatic complexity for function validateWMS is 53, max is 15 (cyclop)
if strings.Contains(wms.GetName(), "wms") {
*warnings = append(*warnings, sharedValidation.FormatValidationWarning("name should not contain wms", wms.GroupVersionKind(), wms.GetName()))
}
Expand Down Expand Up @@ -93,7 +93,7 @@
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 All @@ -106,7 +106,7 @@
*reasons = append(*reasons, "layer.boundingBoxes must contain a boundingBox for CRS '"+service.DataEPSG+"' when service.dataEPSG is not 'EPSG:28992'")
}

if !*layer.Visible {

Check failure on line 109 in api/v3/wms_validation.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

`if !*layer.Visible` has complex nested blocks (complexity: 7) (nestif)
if layer.Title != nil {
*warnings = append(*warnings, sharedValidation.FormatValidationWarning("layer.title is not used when layer.visible=false", wms.GroupVersionKind(), wms.GetName()))
}
Expand All @@ -132,7 +132,7 @@
}
}

if layer.Visible != nil && *layer.Visible {

Check failure on line 135 in api/v3/wms_validation.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

`if layer.Visible != nil && *layer.Visible` has complex nested blocks (complexity: 8) (nestif)
var fields []string
hasVisibleLayer = true

Expand Down Expand Up @@ -162,8 +162,8 @@
}
}
}
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 @@
}
}
}
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 @@ const (
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 @@ func main() {
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 @@ func main() {
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 @@ func main() {
}

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 Down
Loading
Loading