Skip to content

Commit 790450c

Browse files
committed
Started on WMS Capabilities Generator input
1 parent 27774e1 commit 790450c

File tree

6 files changed

+101
-20
lines changed

6 files changed

+101
-20
lines changed

api/v3/shared_types.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type WMSWFS interface {
3535
HasPostgisData() bool
3636
// Sha1 hash of the objects name
3737
ID() string
38+
URLPath() string
3839
}
3940

4041
type Mapfile struct {
@@ -112,18 +113,7 @@ func GetHost() string {
112113
}
113114

114115
func GetBaseURLPath[T WMSWFS](o T) string {
115-
var serviceURL string
116-
switch any(o).(type) {
117-
case *WFS:
118-
if WFS, ok := any(o).(*WFS); ok {
119-
serviceURL = WFS.Spec.Service.URL
120-
}
121-
case *WMS:
122-
if WMS, ok := any(o).(*WMS); ok {
123-
serviceURL = WMS.Spec.Service.URL
124-
}
125-
}
126-
116+
serviceURL := o.URLPath()
127117
parsed, _ := url.Parse(serviceURL)
128118
return strings.TrimPrefix(parsed.Path, "/")
129119
}

api/v3/wfs_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,7 @@ func (wfs *WFS) Options() *Options {
150150
func (wfs *WFS) ID() string {
151151
return Sha1HashOfName(wfs)
152152
}
153+
154+
func (wfs *WFS) URLPath() string {
155+
return wfs.Spec.Service.URL
156+
}

api/v3/wms_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,7 @@ func (wms *WMS) Options() *Options {
267267
func (wms *WMS) ID() string {
268268
return Sha1HashOfName(wms)
269269
}
270+
271+
func (wms *WMS) URLPath() string {
272+
return wms.Spec.Service.URL
273+
}

internal/controller/capabilitiesgenerator/capabilities_generator.go

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

33
import (
4-
"errors"
54
"fmt"
65

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

5958
return string(yamlInput), nil
6059
}
60+
61+
func createInputForWMS(wms *pdoknlv3.WMS, ownerInfo *smoothoperatorv1.OwnerInfo) (config string, err error) {
62+
input, err := MapWMSToCapabilitiesGeneratorInput(wms, ownerInfo)
63+
if err != nil {
64+
return "", err
65+
}
66+
yamlInput, err := yaml.Marshal(input)
67+
if err != nil {
68+
return "", fmt.Errorf("failed to marshal the capabilities generator input to yaml: %w", err)
69+
}
70+
71+
return string(yamlInput), nil
72+
}

internal/controller/capabilitiesgenerator/capabilities_generator_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ 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"
7+
"github.com/stretchr/testify/assert"
68
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
79

810
"testing"
@@ -116,6 +118,7 @@ func TestGetInputForWFS(t *testing.T) {
116118
},
117119
Spec: pdoknlv3.WFSSpec{
118120
Service: pdoknlv3.WFSService{
121+
URL: "/datasetOwner/dataset/theme/wfs/v1_0",
119122
Title: "some Service title",
120123
Abstract: "some \"Service\" abstract",
121124
Keywords: []string{"service-keyword-1", "service-keyword-2", "infoFeatureAccessService"},
@@ -201,3 +204,32 @@ func TestGetInputForWFS(t *testing.T) {
201204
})
202205
}
203206
}
207+
208+
func TestInputForWMS(t *testing.T) {
209+
wms := pdoknlv3.WMS{
210+
TypeMeta: metav1.TypeMeta{},
211+
ObjectMeta: metav1.ObjectMeta{},
212+
Spec: pdoknlv3.WMSSpec{},
213+
Status: model.OperatorStatus{},
214+
}
215+
216+
ownerInfo := smoothoperatorv1.OwnerInfo{
217+
Spec: smoothoperatorv1.OwnerInfoSpec{
218+
NamespaceTemplate: "http://{{prefix}}.geonovum.nl",
219+
MetadataUrls: smoothoperatorv1.MetadataUrls{
220+
CSW: smoothoperatorv1.MetadataURL{
221+
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}}",
222+
},
223+
},
224+
WFS: smoothoperatorv1.WFS{
225+
ServiceProvider: smoothoperatorv1.ServiceProvider{
226+
ProviderName: smoothoperatorutils.Pointer("PDOK"),
227+
},
228+
},
229+
},
230+
}
231+
232+
input, err := GetInput(&wms, &ownerInfo)
233+
assert.NoError(t, err)
234+
println(input)
235+
}

internal/controller/capabilitiesgenerator/mapper.go

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

33
import (
4+
"encoding/xml"
45
"fmt"
6+
"github.com/pdok/ogc-specifications/pkg/wms130"
57
"strconv"
68
"strings"
79

@@ -15,9 +17,10 @@ import (
1517
)
1618

1719
const (
18-
inspireSchemaLocations = "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd"
19-
capabilitiesFilename = "/var/www/config/capabilities_wfs_200.xml"
20-
metadataMediaType = "application/vnd.ogc.csw.GetRecordByIdResponse_xml"
20+
inspireSchemaLocations = "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 http://inspire.ec.europa.eu/schemas/inspire_dls/1.0/inspire_dls.xsd"
21+
wfsCapabilitiesFilename = "/var/www/config/capabilities_wfs_200.xml"
22+
wmsCapabilitiesFilename = "/var/www/config/capabilities_wms_130.xml"
23+
metadataMediaType = "application/vnd.ogc.csw.GetRecordByIdResponse_xml"
2124
)
2225

2326
func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo) (*capabilitiesgenerator.Config, error) {
@@ -31,12 +34,12 @@ func MapWFSToCapabilitiesGeneratorInput(wfs *pdoknlv3.WFS, ownerInfo *smoothoper
3134
Namespace: mapperutils.GetNamespaceURI(wfs.Spec.Service.Prefix, ownerInfo),
3235
Prefix: wfs.Spec.Service.Prefix,
3336
Onlineresourceurl: pdoknlv3.GetHost(),
34-
Path: mapperutils.GetPath(wfs),
37+
Path: "/" + pdoknlv3.GetBaseURLPath(wfs),
3538
Version: *mapperutils.GetLabelValueByKey(wfs.ObjectMeta.Labels, "service-version"),
3639
},
3740
Services: capabilitiesgenerator.Services{
3841
WFS200Config: &capabilitiesgenerator.WFS200Config{
39-
Filename: capabilitiesFilename,
42+
Filename: wfsCapabilitiesFilename,
4043
Wfs200: wfs200.GetCapabilitiesResponse{
4144

4245
ServiceProvider: mapServiceProvider(&ownerInfo.Spec.WFS.ServiceProvider),
@@ -200,3 +203,39 @@ func mapServiceProvider(provider *smoothoperatorv1.ServiceProvider) (serviceProv
200203

201204
return serviceProvider
202205
}
206+
207+
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+
//}
212+
213+
config := capabilitiesgenerator.Config{
214+
Global: capabilitiesgenerator.Global{
215+
Namespace: mapperutils.GetNamespaceURI("prefix", ownerInfo),
216+
Prefix: "prefix",
217+
Onlineresourceurl: pdoknlv3.GetHost(),
218+
Path: pdoknlv3.GetBaseURLPath(wms),
219+
Version: *mapperutils.GetLabelValueByKey(wms.ObjectMeta.Labels, "service-version"),
220+
},
221+
Services: capabilitiesgenerator.Services{
222+
WMS130Config: &capabilitiesgenerator.WMS130Config{
223+
Filename: wmsCapabilitiesFilename,
224+
Wms130: wms130.GetCapabilitiesResponse{
225+
XMLName: xml.Name{},
226+
Namespaces: wms130.Namespaces{},
227+
WMSService: wms130.WMSService{},
228+
Capabilities: wms130.Capabilities{},
229+
},
230+
},
231+
},
232+
}
233+
234+
if wms.Spec.Service.Inspire != nil {
235+
config.Global.AdditionalSchemaLocations = inspireSchemaLocations
236+
//metadataURL, _ := replaceMustachTemplate(ownerInfo.Spec.MetadataUrls.CSW.HrefTemplate, wms.Spec.Service.Inspire.ServiceMetadataURL.CSW.MetadataIdentifier)
237+
238+
}
239+
240+
return &config, nil
241+
}

0 commit comments

Comments
 (0)