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
9 changes: 7 additions & 2 deletions api/v2beta1/wms_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
)

const SERVICE_METADATA_IDENTIFIER_ANNOTATION = "pdok.nl/wms-service-metadata-uuid"

Check failure on line 39 in api/v2beta1/wms_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

var-naming: don't use ALL_CAPS in Go names; use CamelCase (revive)

// ConvertTo converts this WMS (v2beta1) to the Hub version (v3).
func (src *WMS) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*pdoknlv3.WMS)
log.Printf("ConvertTo: Converting WMS from Spoke version v2beta1 to Hub version v3;"+
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
V3HubFromV2(src, dst)

return nil
}

func V3HubFromV2(src *WMS, target *pdoknlv3.WMS) {
dst := target

dst.ObjectMeta = src.ObjectMeta
dst.Annotations[SERVICE_METADATA_IDENTIFIER_ANNOTATION] = src.Spec.Service.MetadataIdentifier
Expand Down Expand Up @@ -126,8 +133,6 @@
}

dst.Spec.Service = service

return nil
}

// ConvertFrom converts the Hub version (v3) to this WMS (v2beta1).
Expand Down Expand Up @@ -390,10 +395,10 @@
return layer
}

func mapV3LayerToV2Layers(v3Layer pdoknlv3.Layer, parent *pdoknlv3.Layer, serviceEPSG string) []WMSLayer {

Check failure on line 398 in api/v2beta1/wms_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

calculated cyclomatic complexity for function mapV3LayerToV2Layers is 20, max is 15 (cyclop)
var layers []WMSLayer

if parent == nil && v3Layer.Name == "wms" {

Check failure on line 401 in api/v2beta1/wms_conversion.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

`if parent == nil && v3Layer.Name == "wms"` has complex nested blocks (complexity: 15) (nestif)
// Default top layer, do not include in v2 layers
if v3Layer.Layers != nil {
for _, childLayer := range *v3Layer.Layers {
Expand Down
20 changes: 20 additions & 0 deletions api/v2beta1/wms_conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v2beta1

import (

Check failure on line 3 in api/v2beta1/wms_conversion_test.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

File is not properly formatted (goimports)
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/yaml"
"testing"
)

func TestV2ToV3(t *testing.T) {
input := "apiVersion: pdok.nl/v2beta1\nkind: WMS\nmetadata:\n name: rws-nwbwegen-v1-0\n labels:\n dataset-owner: rws\n dataset: nwbwegen\n service-version: v1_0\n service-type: wms\n annotations:\n lifecycle-phase: prod\n service-bundle-id: b39c152b-393b-52f5-a50c-e1ffe904b6fb\nspec:\n general:\n datasetOwner: rws\n dataset: nwbwegen\n serviceVersion: v1_0\n kubernetes:\n healthCheck:\n boundingbox: 135134.89,457152.55,135416.03,457187.82\n resources:\n limits:\n ephemeralStorage: 1535Mi\n memory: 4G\n requests:\n cpu: 2000m\n ephemeralStorage: 1535Mi\n memory: 4G\n options:\n automaticCasing: true\n disableWebserviceProxy: false\n includeIngress: true\n validateRequests: true\n service:\n title: NWB - Wegen WMS\n abstract:\n Dit is de web map service van het Nationaal Wegen Bestand (NWB) - wegen.\n Deze dataset bevat alleen de wegvakken en hectometerpunten. Het Nationaal Wegen\n Bestand - Wegen is een digitaal geografisch bestand van alle wegen in Nederland.\n Opgenomen zijn alle wegen die worden beheerd door wegbeheerders als het Rijk,\n provincies, gemeenten en waterschappen, echter alleen voor zover deze zijn voorzien\n van een straatnaam of nummer.\n authority:\n name: rws\n url: https://www.rijkswaterstaat.nl\n dataEPSG: EPSG:28992\n extent: -59188.44333693248 304984.64144318487 308126.88473339565 858328.516489961\n inspire: true\n keywords:\n - Vervoersnetwerken\n - Menselijke gezondheid en veiligheid\n - Geluidsbelasting hoofdwegen (Richtlijn Omgevingslawaai)\n - Nationaal\n - Voertuigen\n - Verkeer\n - Wegvakken\n - Hectometerpunten\n - HVD\n - Mobiliteit\n stylingAssets:\n configMapRefs:\n - name: includes\n keys:\n - nwb_wegen_hectopunten.symbol\n - hectopunten.style\n - wegvakken.style\n blobKeys:\n - resources/fonts/liberation-sans.ttf\n layers:\n - abstract:\n Deze laag bevat de wegvakken uit het Nationaal Wegen bestand (NWB)\n en geeft gedetailleerde informatie per wegvak zoals straatnaam, wegnummer,\n routenummer, wegbeheerder, huisnummers, enz. weer.\n data:\n gpkg:\n columns:\n - objectid\n - wvk_id\n - wvk_begdat\n - jte_id_beg\n - jte_id_end\n - wegbehsrt\n - wegnummer\n - wegdeelltr\n - hecto_lttr\n - bst_code\n - rpe_code\n - admrichtng\n - rijrichtng\n - stt_naam\n - stt_bron\n - wpsnaam\n - gme_id\n - gme_naam\n - hnrstrlnks\n - hnrstrrhts\n - e_hnr_lnks\n - e_hnr_rhts\n - l_hnr_lnks\n - l_hnr_rhts\n - begafstand\n - endafstand\n - beginkm\n - eindkm\n - pos_tv_wol\n - wegbehcode\n - wegbehnaam\n - distrcode\n - distrnaam\n - dienstcode\n - dienstnaam\n - wegtype\n - wgtype_oms\n - routeltr\n - routenr\n - routeltr2\n - routenr2\n - routeltr3\n - routenr3\n - routeltr4\n - routenr4\n - wegnr_aw\n - wegnr_hmp\n - geobron_id\n - geobron_nm\n - bronjaar\n - openlr\n - bag_orl\n - frc\n - fow\n - alt_naam\n - alt_nr\n - rel_hoogte\n - st_lengthshape\n geometryType: MultiLineString\n blobKey: geopackages/rws/nwbwegen/410a6d1e-e767-41b4-ba8d-9e1e955dd013/1/nwb_wegen.gpkg\n table: wegvakken\n datasetMetadataIdentifier: a9b7026e-0a81-4813-93bd-ba49e6f28502\n keywords:\n - Vervoersnetwerken\n - Menselijke gezondheid en veiligheid\n - Geluidsbelasting hoofdwegen (Richtlijn Omgevingslawaai)\n - Nationaal\n - Voertuigen\n - Verkeer\n - Wegvakken\n maxScale: 50000.0\n minScale: 1.0\n name: wegvakken\n sourceMetadataIdentifier: 8f0497f0-dbd7-4bee-b85a-5fdec484a7ff\n styles:\n - name: wegvakken\n title: NWB - Wegvakken\n visualization: wegvakken.style\n title: Wegvakken\n visible: true\n - abstract:\n Deze laag bevat de hectopunten uit het Nationaal Wegen Bestand (NWB)\n en geeft gedetailleerde informatie per hectopunt zoals hectometrering, afstand,\n zijde en hectoletter weer.\n data:\n gpkg:\n columns:\n - objectid\n - hectomtrng\n - afstand\n - wvk_id\n - wvk_begdat\n - zijde\n - hecto_lttr\n geometryType: MultiPoint\n blobKey: geopackages/rws/nwbwegen/410a6d1e-e767-41b4-ba8d-9e1e955dd013/1/nwb_wegen.gpkg\n table: hectopunten\n datasetMetadataIdentifier: a9b7026e-0a81-4813-93bd-ba49e6f28502\n keywords:\n - Vervoersnetwerken\n - Menselijke gezondheid en veiligheid\n - Geluidsbelasting hoofdwegen (Richtlijn Omgevingslawaai)\n - Nationaal\n - Voertuigen\n - Verkeer\n - Hectometerpunten\n maxScale: 50000.0\n minScale: 1.0\n name: hectopunten\n sourceMetadataIdentifier: 8f0497f0-dbd7-4bee-b85a-5fdec484a7ff\n styles:\n - name: hectopunten\n title: NWB - Hectopunten\n visualization: hectopunten.style\n title: Hectopunten\n visible: true\n metadataIdentifier: f2437a92-ddd3-4777-a1bc-fdf4b4a7fcb8\n"

Check failure on line 11 in api/v2beta1/wms_conversion_test.go

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

`Nationaal` is a misspelling of `National` (misspell)
var v2wms WMS
err := yaml.Unmarshal([]byte(input), &v2wms)
assert.NoError(t, err)
var target pdoknlv3.WMS
V3HubFromV2(&v2wms, &target)
assert.Equal(t, "NWB - Wegen WMS", target.Spec.Service.Title)
a := 0
_ = a
}
14 changes: 2 additions & 12 deletions api/v3/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type WMSWFS interface {
HasPostgisData() bool
// Sha1 hash of the objects name
ID() string
URLPath() string
}

type Mapfile struct {
Expand Down Expand Up @@ -112,18 +113,7 @@ func GetHost() string {
}

func GetBaseURLPath[T WMSWFS](o T) string {
var serviceURL string
switch any(o).(type) {
case *WFS:
if WFS, ok := any(o).(*WFS); ok {
serviceURL = WFS.Spec.Service.URL
}
case *WMS:
if WMS, ok := any(o).(*WMS); ok {
serviceURL = WMS.Spec.Service.URL
}
}

serviceURL := o.URLPath()
parsed, _ := url.Parse(serviceURL)
return strings.TrimPrefix(parsed.Path, "/")
}
Expand Down
4 changes: 4 additions & 0 deletions api/v3/wfs_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@ func (wfs *WFS) Options() *Options {
func (wfs *WFS) ID() string {
return Sha1HashOfName(wfs)
}

func (wfs *WFS) URLPath() string {
return wfs.Spec.Service.URL
}
4 changes: 4 additions & 0 deletions api/v3/wms_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
AccessConstraints string `json:"accessConstraints"`
MaxSize *int32 `json:"maxSize,omitempty"`
Inspire *Inspire `json:"inspire,omitempty"`
DataEPSG string `json:"dataEPSG"`

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

View workflow job for this annotation

GitHub Actions / Run on Ubuntu

json(camel): got 'dataEPSG' want 'dataEpsg' (tagliatelle)

Check failure on line 65 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 @@ -267,3 +267,7 @@
func (wms *WMS) ID() string {
return Sha1HashOfName(wms)
}

func (wms *WMS) URLPath() string {
return wms.Spec.Service.URL
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/onsi/ginkgo/v2 v2.22.2
github.com/onsi/gomega v1.36.2
github.com/pdok/ogc-capabilities-generator v1.0.0-beta5
github.com/pdok/ogc-specifications v1.0.0-beta4
github.com/pdok/ogc-specifications v1.0.0-beta5
github.com/pdok/smooth-operator v0.0.9
github.com/traefik/traefik/v3 v3.3.4
k8s.io/api v0.32.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ github.com/pdok/ogc-capabilities-generator v1.0.0-beta5 h1:nwkIbFcUW4FIYnf6fLfzp
github.com/pdok/ogc-capabilities-generator v1.0.0-beta5/go.mod h1:qG2auFy7MDL8Zp1eOfdaUJat+jNW5oLGVd+g7Mbth4Q=
github.com/pdok/ogc-specifications v1.0.0-beta4 h1:/Dgi6ArgR0YPCkErpNyCQTCYMkH/cIfWe+VCoUUZZN0=
github.com/pdok/ogc-specifications v1.0.0-beta4/go.mod h1:YDngwkwrWOfc5MYnEYseiv97K1Y9bZXlVzwi/8EaIl8=
github.com/pdok/ogc-specifications v1.0.0-beta5 h1:j7JrXUeW55mVU9ZmJ67r8V6DhbKdgTDiGE1YKFpRWx4=
github.com/pdok/ogc-specifications v1.0.0-beta5/go.mod h1:YDngwkwrWOfc5MYnEYseiv97K1Y9bZXlVzwi/8EaIl8=
github.com/pdok/smooth-operator v0.0.9 h1:UaOPc23BaHDWzBatSWnOxEjffV0WMiy1LPUkRdqdIGI=
github.com/pdok/smooth-operator v0.0.9/go.mod h1:oZWFuIKJGjN/C6ocgMNfMZ7SbLQi+N0qaWj7j95Wdec=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package capabilitiesgenerator

import (
"errors"
"fmt"

pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
Expand Down Expand Up @@ -37,8 +36,8 @@ func GetInput[W pdoknlv3.WMSWFS](webservice W, ownerInfo *smoothoperatorv1.Owner
return createInputForWFS(WFS, ownerInfo)
}
case *pdoknlv3.WMS:
if _, ok := any(webservice).(*pdoknlv3.WMS); ok {
return "", errors.New("not implemented for WMS")
if WMS, ok := any(webservice).(*pdoknlv3.WMS); ok {
return createInputForWMS(WMS, ownerInfo)
}
default:
return "", fmt.Errorf("unexpected input, webservice should be of type WFS or WMS, webservice: %v", webservice)
Expand All @@ -58,3 +57,16 @@ func createInputForWFS(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo)

return string(yamlInput), nil
}

func createInputForWMS(wms *pdoknlv3.WMS, ownerInfo *smoothoperatorv1.OwnerInfo) (config string, err error) {
input, err := MapWMSToCapabilitiesGeneratorInput(wms, ownerInfo)
if err != nil {
return "", err
}
yamlInput, err := yaml.Marshal(input)
if err != nil {
return "", fmt.Errorf("failed to marshal the capabilities generator input to yaml: %w", err)
}

return string(yamlInput), nil
}
Loading
Loading