Skip to content

Commit e1c2017

Browse files
committed
Worked out mapped data a bit more. Upgraded ogc-specifications for nullability
1 parent 790450c commit e1c2017

File tree

4 files changed

+181
-20
lines changed

4 files changed

+181
-20
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/onsi/ginkgo/v2 v2.22.2
1212
github.com/onsi/gomega v1.36.2
1313
github.com/pdok/ogc-capabilities-generator v1.0.0-beta5
14-
github.com/pdok/ogc-specifications v1.0.0-beta4
14+
github.com/pdok/ogc-specifications v1.0.0-beta5
1515
github.com/pdok/smooth-operator v0.0.9
1616
github.com/traefik/traefik/v3 v3.3.4
1717
k8s.io/api v0.32.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ github.com/pdok/ogc-capabilities-generator v1.0.0-beta5 h1:nwkIbFcUW4FIYnf6fLfzp
362362
github.com/pdok/ogc-capabilities-generator v1.0.0-beta5/go.mod h1:qG2auFy7MDL8Zp1eOfdaUJat+jNW5oLGVd+g7Mbth4Q=
363363
github.com/pdok/ogc-specifications v1.0.0-beta4 h1:/Dgi6ArgR0YPCkErpNyCQTCYMkH/cIfWe+VCoUUZZN0=
364364
github.com/pdok/ogc-specifications v1.0.0-beta4/go.mod h1:YDngwkwrWOfc5MYnEYseiv97K1Y9bZXlVzwi/8EaIl8=
365+
github.com/pdok/ogc-specifications v1.0.0-beta5 h1:j7JrXUeW55mVU9ZmJ67r8V6DhbKdgTDiGE1YKFpRWx4=
366+
github.com/pdok/ogc-specifications v1.0.0-beta5/go.mod h1:YDngwkwrWOfc5MYnEYseiv97K1Y9bZXlVzwi/8EaIl8=
365367
github.com/pdok/smooth-operator v0.0.9 h1:UaOPc23BaHDWzBatSWnOxEjffV0WMiy1LPUkRdqdIGI=
366368
github.com/pdok/smooth-operator v0.0.9/go.mod h1:oZWFuIKJGjN/C6ocgMNfMZ7SbLQi+N0qaWj7j95Wdec=
367369
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=

internal/controller/capabilitiesgenerator/capabilities_generator_test.go

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package capabilitiesgenerator
33
import (
44
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
55
smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
6-
"github.com/pdok/smooth-operator/model"
76
"github.com/stretchr/testify/assert"
87
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
98

@@ -206,11 +205,60 @@ func TestGetInputForWFS(t *testing.T) {
206205
}
207206

208207
func TestInputForWMS(t *testing.T) {
208+
var maxSize int32 = 123
209+
209210
wms := pdoknlv3.WMS{
210-
TypeMeta: metav1.TypeMeta{},
211-
ObjectMeta: metav1.ObjectMeta{},
212-
Spec: pdoknlv3.WMSSpec{},
213-
Status: model.OperatorStatus{},
211+
ObjectMeta: metav1.ObjectMeta{
212+
Labels: map[string]string{
213+
"dataset": "dataset",
214+
"dataset-owner": "datasetOwner",
215+
"theme": "theme",
216+
"service-version": "v1_0",
217+
},
218+
},
219+
Spec: pdoknlv3.WMSSpec{
220+
Service: pdoknlv3.WMSService{
221+
URL: "/datasetOwner/dataset/theme/wms/v1_0",
222+
Title: "some Service title",
223+
Abstract: "some \"Service\" abstract",
224+
Keywords: []string{"service-keyword-1", "service-keyword-2", "infoFeatureAccessService"},
225+
AccessConstraints: "http://creativecommons.org/publicdomain/zero/1.0/deed.nl",
226+
MaxSize: &maxSize,
227+
Inspire: &pdoknlv3.Inspire{
228+
ServiceMetadataURL: pdoknlv3.MetadataURL{
229+
CSW: &pdoknlv3.Metadata{
230+
MetadataIdentifier: "metameta-meta-meta-meta-metametameta",
231+
},
232+
},
233+
Language: "dut",
234+
SpatialDatasetIdentifier: "datadata-data-data-data-datadatadata",
235+
},
236+
DataEPSG: "EPSG:28992",
237+
StylingAssets: nil,
238+
Mapfile: nil,
239+
Layer: pdoknlv3.Layer{
240+
Name: "",
241+
Title: nil,
242+
Abstract: nil,
243+
Keywords: nil,
244+
BoundingBoxes: nil,
245+
Visible: nil,
246+
Authority: nil,
247+
DatasetMetadataURL: nil,
248+
MinScaleDenominator: nil,
249+
MaxScaleDenominator: nil,
250+
Styles: nil,
251+
LabelNoClip: false,
252+
Data: nil,
253+
Layers: nil,
254+
},
255+
},
256+
},
257+
}
258+
259+
contactPersonPrimary := smoothoperatorv1.ContactPersonPrimary{
260+
ContactPerson: asPtr("KlantContactCenter PDOK"),
261+
ContactOrganization: asPtr("PDOK"),
214262
}
215263

216264
ownerInfo := smoothoperatorv1.OwnerInfo{
@@ -221,9 +269,21 @@ func TestInputForWMS(t *testing.T) {
221269
HrefTemplate: "https://www.nationaalgeoregister.nl/geonetwork/srv/dut/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id={{identifier}}",
222270
},
223271
},
224-
WFS: smoothoperatorv1.WFS{
225-
ServiceProvider: smoothoperatorv1.ServiceProvider{
226-
ProviderName: smoothoperatorutils.Pointer("PDOK"),
272+
WMS: smoothoperatorv1.WMS{
273+
ContactInformation: &smoothoperatorv1.ContactInformation{
274+
ContactPersonPrimary: &contactPersonPrimary,
275+
ContactPosition: asPtr("pointOfContact"),
276+
ContactAddress: &smoothoperatorv1.ContactAddress{
277+
AddressType: asPtr("Work"),
278+
Address: nil,
279+
City: asPtr("Apeldoorn"),
280+
StateOrProvince: nil,
281+
PostCode: nil,
282+
Country: asPtr("The Netherlands"),
283+
},
284+
ContactVoiceTelephone: nil,
285+
ContactFacsimileTelephone: nil,
286+
ContactElectronicMailAddress: asPtr("[email protected]"),
227287
},
228288
},
229289
},

internal/controller/capabilitiesgenerator/mapper.go

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

33
import (
4-
"encoding/xml"
54
"fmt"
65
"github.com/pdok/ogc-specifications/pkg/wms130"
76
"strconv"
@@ -205,37 +204,137 @@ func mapServiceProvider(provider *smoothoperatorv1.ServiceProvider) (serviceProv
205204
}
206205

207206
func MapWMSToCapabilitiesGeneratorInput(wms *pdoknlv3.WMS, ownerInfo *smoothoperatorv1.OwnerInfo) (*capabilitiesgenerator.Config, error) {
208-
//featureTypeList, err := getFeatureTypeList(wms, ownerInfo)
209-
//if err != nil {
210-
// return nil, err
211-
//}
207+
abstract := mapperutils.EscapeQuotes(wms.Spec.Service.Abstract)
208+
var fees *string = nil
209+
if wms.Spec.Service.Fees != nil {
210+
feesPtr := mapperutils.EscapeQuotes(*wms.Spec.Service.Fees)
211+
fees = &feesPtr
212+
}
212213

213214
config := capabilitiesgenerator.Config{
214215
Global: capabilitiesgenerator.Global{
215216
Namespace: mapperutils.GetNamespaceURI("prefix", ownerInfo),
216217
Prefix: "prefix",
217218
Onlineresourceurl: pdoknlv3.GetHost(),
218-
Path: pdoknlv3.GetBaseURLPath(wms),
219+
Path: "/" + pdoknlv3.GetBaseURLPath(wms),
219220
Version: *mapperutils.GetLabelValueByKey(wms.ObjectMeta.Labels, "service-version"),
220221
},
221222
Services: capabilitiesgenerator.Services{
222223
WMS130Config: &capabilitiesgenerator.WMS130Config{
223224
Filename: wmsCapabilitiesFilename,
224225
Wms130: wms130.GetCapabilitiesResponse{
225-
XMLName: xml.Name{},
226-
Namespaces: wms130.Namespaces{},
227-
WMSService: wms130.WMSService{},
228-
Capabilities: wms130.Capabilities{},
226+
WMSService: wms130.WMSService{
227+
Name: "WMS",
228+
Title: mapperutils.EscapeQuotes(wms.Spec.Service.Title),
229+
Abstract: &abstract,
230+
KeywordList: &wms130.Keywords{Keyword: wms.Spec.Service.Keywords},
231+
OnlineResource: wms130.OnlineResource{Href: &wms.Spec.Service.URL},
232+
ContactInformation: getContactInformation(ownerInfo),
233+
Fees: fees,
234+
AccessConstraints: &wms.Spec.Service.AccessConstraints,
235+
LayerLimit: nil,
236+
MaxWidth: nil,
237+
MaxHeight: nil,
238+
},
239+
Capabilities: wms130.Capabilities{
240+
WMSCapabilities: wms130.WMSCapabilities{
241+
Request: wms130.Request{
242+
GetCapabilities: wms130.RequestType{},
243+
GetMap: wms130.RequestType{},
244+
GetFeatureInfo: nil,
245+
},
246+
Exception: wms130.ExceptionType{Format: []string{"XML", "BLANK"}},
247+
ExtendedCapabilities: nil,
248+
Layer: nil,
249+
},
250+
OptionalConstraints: wms130.OptionalConstraints{},
251+
},
229252
},
230253
},
231254
},
232255
}
233256

234257
if wms.Spec.Service.Inspire != nil {
235258
config.Global.AdditionalSchemaLocations = inspireSchemaLocations
236-
//metadataURL, _ := replaceMustachTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wms.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier)
259+
metadataURL, _ := replaceMustachTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wms.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier)
237260

261+
defaultLanguage := wms130.Language{Language: wms.Spec.Service.Inspire.Language}
262+
263+
config.Services.WMS130Config.Wms130.Capabilities.ExtendedCapabilities = &wms130.ExtendedCapabilities{
264+
MetadataURL: wms130.ExtendedMetadataURL{URL: metadataURL, MediaType: metadataMediaType},
265+
SupportedLanguages: wms130.SupportedLanguages{
266+
DefaultLanguage: defaultLanguage,
267+
SupportedLanguage: &[]wms130.Language{defaultLanguage},
268+
},
269+
ResponseLanguage: defaultLanguage,
270+
}
238271
}
239272

240273
return &config, nil
241274
}
275+
276+
func getContactInformation(ownerInfo *smoothoperatorv1.OwnerInfo) *wms130.ContactInformation {
277+
result := wms130.ContactInformation{
278+
ContactPersonPrimary: nil,
279+
ContactPosition: nil,
280+
ContactAddress: nil,
281+
ContactVoiceTelephone: nil,
282+
ContactFacsimileTelephone: nil,
283+
ContactElectronicMailAddress: nil,
284+
}
285+
286+
providedContactInformation := ownerInfo.Spec.WMS.ContactInformation
287+
288+
if providedContactInformation == nil {
289+
return &result
290+
}
291+
292+
if providedContactInformation.ContactPersonPrimary != nil {
293+
contactPerson := ""
294+
if providedContactInformation.ContactPersonPrimary.ContactPerson != nil {
295+
contactPerson = *providedContactInformation.ContactPersonPrimary.ContactPerson
296+
}
297+
contactOrganisation := ""
298+
if providedContactInformation.ContactPersonPrimary.ContactOrganization != nil {
299+
contactOrganisation = *providedContactInformation.ContactPersonPrimary.ContactOrganization
300+
}
301+
302+
contactPersonPrimary := wms130.ContactPersonPrimary{
303+
ContactPerson: contactPerson,
304+
ContactOrganization: contactOrganisation,
305+
}
306+
result.ContactPersonPrimary = &contactPersonPrimary
307+
}
308+
309+
result.ContactPosition = providedContactInformation.ContactPosition
310+
if providedContactInformation.ContactAddress != nil {
311+
contactAddressInput := providedContactInformation.ContactAddress
312+
contactAddress := wms130.ContactAddress{
313+
AddressType: pointerValOrDefault(contactAddressInput.AddressType, ""),
314+
Address: pointerValOrDefault(contactAddressInput.Address, ""),
315+
City: pointerValOrDefault(contactAddressInput.City, ""),
316+
StateOrProvince: pointerValOrDefault(contactAddressInput.StateOrProvince, ""),
317+
PostalCode: pointerValOrDefault(contactAddressInput.PostCode, ""),
318+
Country: pointerValOrDefault(contactAddressInput.Country, ""),
319+
}
320+
result.ContactAddress = &contactAddress
321+
}
322+
323+
result.ContactVoiceTelephone = providedContactInformation.ContactVoiceTelephone
324+
result.ContactFacsimileTelephone = providedContactInformation.ContactFacsimileTelephone
325+
result.ContactElectronicMailAddress = providedContactInformation.ContactElectronicMailAddress
326+
327+
return &result
328+
}
329+
330+
func pointerValOrDefault[T any](pointer *T, defaultValue T) T {
331+
if pointer != nil {
332+
return *pointer
333+
} else {
334+
return defaultValue
335+
}
336+
}
337+
338+
func asPtr[T any](value T) *T {
339+
return &value
340+
}

0 commit comments

Comments
 (0)