Skip to content

Commit fb6a792

Browse files
committed
Updated atom spec and additional mapping
1 parent fcff76d commit fb6a792

File tree

3 files changed

+122
-87
lines changed

3 files changed

+122
-87
lines changed

api/v2beta1/atom_conversion.go

Lines changed: 97 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ SOFTWARE.
2525
package v2beta1
2626

2727
import (
28+
"fmt"
2829
"log"
30+
"strconv"
2931
"time"
3032

3133
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -40,6 +42,8 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
4042
log.Printf("ConvertTo: Converting Atom from Spoke version v2beta1 to Hub version v3;"+
4143
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
4244

45+
host := "https://service.dok.nl/" // Todo read from flag
46+
4347
// ObjectMeta
4448
dst.ObjectMeta = src.ObjectMeta
4549

@@ -53,49 +57,26 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
5357
// Service
5458
log.Printf("Start mapping the Service...")
5559
dst.Spec.Service = pdoknlv3.Service{
56-
// Todo BaseURL opbouwen
57-
BaseURL: "http://localhost/owner/dataset",
58-
Lang: "nl",
59-
Stylesheet: "https://service.pdok.nl/atom/style/style.xsl",
60-
Title: src.Spec.Service.Title,
61-
Subtitle: src.Spec.Service.Subtitle,
62-
// Todo metadata-id invullen in links
63-
Links: []pdoknlv3.Link{
64-
{
65-
Href: "https://www.ngr.nl/geonetwork/srv/dut/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id=<id>",
66-
Category: "metadataXml",
67-
},
68-
{
69-
Href: "https://www.ngr.nl/geonetwork/opensearch/dut/<id>>/OpenSearchDescription.xml",
70-
Category: "opensearch",
71-
},
72-
{
73-
Href: "https://www.ngr.nl/geonetwork/srv/dut/catalog.search#/metadata/<id>",
74-
Category: "metadataHtml",
75-
Rel: "describedBy",
76-
},
77-
},
78-
Rights: src.Spec.Service.Rights,
79-
Author: pdoknlv3.Author{
80-
Name: "PDOK Beheer",
81-
82-
},
60+
BaseURL: createBaseURL(host, src.Spec.General),
61+
Lang: "nl",
62+
Stylesheet: "https://service.pdok.nl/atom/style/style.xsl",
63+
Title: src.Spec.Service.Title,
64+
Subtitle: src.Spec.Service.Subtitle,
65+
OwnerInfoRef: "pdok",
66+
Links: []pdoknlv3.Link{},
67+
Rights: src.Spec.Service.Rights,
8368
}
8469
log.Printf("Done mapping the Service...")
8570

8671
dst.Spec.DatasetFeeds = []pdoknlv3.DatasetFeed{}
8772
log.Printf("Start mapping the Datasets...")
8873
for _, srcDataset := range src.Spec.Service.Datasets {
8974
dstDatasetFeed := pdoknlv3.DatasetFeed{
90-
TechnicalName: "<id>.xml",
91-
Title: srcDataset.Title,
92-
Subtitle: srcDataset.Subtitle,
93-
Author: pdoknlv3.Author{
94-
Name: "",
95-
Email: "",
96-
},
75+
TechnicalName: srcDataset.Name,
76+
Title: srcDataset.Title,
77+
Subtitle: srcDataset.Subtitle,
9778
SpatialDatasetIdentifierCode: srcDataset.SourceIdentifier,
98-
SpatialDatasetIdentifierNamespace: "",
79+
SpatialDatasetIdentifierNamespace: "http://www.pdok.nl",
9980
}
10081

10182
// Map the links
@@ -125,15 +106,14 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
125106
URI: srcDownload.Srs.URI,
126107
Name: srcDownload.Srs.Code,
127108
},
128-
// TODO fix polygon float dangerousTypes
129-
// Polygon: pdoknlv3.Polygon{
130-
// BBox: pdoknlv3.BBox{
131-
// MinX: strconv.FormatFloat(srcDataset.Bbox.Minx, 'f', -1, 32),
132-
// MinY: strconv.FormatFloat(srcDataset.Bbox.Miny, 'f', -1, 32),
133-
// MaxX: strconv.FormatFloat(srcDataset.Bbox.Maxx, 'f', -1, 32),
134-
// MaxY: strconv.FormatFloat(srcDataset.Bbox.Maxy, 'f', -1, 32),
135-
// },
136-
// },
109+
Polygon: &pdoknlv3.Polygon{
110+
BBox: pdoknlv3.BBox{
111+
MinX: GetFloat32AsString(srcDataset.Bbox.Minx),
112+
MinY: GetFloat32AsString(srcDataset.Bbox.Miny),
113+
MaxX: GetFloat32AsString(srcDataset.Bbox.Maxx),
114+
MaxY: GetFloat32AsString(srcDataset.Bbox.Maxy),
115+
},
116+
},
137117
}
138118

139119
if srcDownload.Title != nil {
@@ -166,9 +146,14 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
166146
if srcLink.Version != nil {
167147
dstDownloadLink.Version = srcLink.Version
168148
}
169-
170-
// Todo bbox
171-
149+
if srcLink.Bbox != nil {
150+
dstDownloadLink.BBox = &pdoknlv3.BBox{
151+
MinX: GetFloat32AsString(srcLink.Bbox.Minx),
152+
MinY: GetFloat32AsString(srcLink.Bbox.Miny),
153+
MaxX: GetFloat32AsString(srcLink.Bbox.Maxx),
154+
MaxY: GetFloat32AsString(srcLink.Bbox.Maxy),
155+
}
156+
}
172157
if srcLink.Rel != nil {
173158
dstDownloadLink.Rel = *srcLink.Rel
174159
}
@@ -199,25 +184,33 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
199184

200185
// General
201186
log.Printf("Start mapping the General specs...")
202-
dst.Spec.General = General{ // Todo waar halen we deze info vandaan
203-
Dataset: "",
204-
DatasetOwner: "",
205-
DataVersion: new(string),
206-
ServiceVersion: new(string),
207-
Theme: new(string),
187+
dst.Spec.General = General{
188+
Dataset: src.ObjectMeta.Labels["dataset"],
189+
DatasetOwner: src.ObjectMeta.Labels["dataset-owner"],
190+
DataVersion: nil,
191+
}
192+
193+
serviceVersion, ok := src.ObjectMeta.Labels["service-version"]
194+
if ok {
195+
dst.Spec.General.ServiceVersion = &serviceVersion
196+
}
197+
198+
theme, ok := src.ObjectMeta.Labels["theme"]
199+
if ok {
200+
dst.Spec.General.Theme = &theme
208201
}
202+
209203
log.Printf("Done mapping the General specs...")
210204

211205
// Service
212206
log.Printf("Start mapping the Service...")
213207
dst.Spec.Service = AtomService{
214208
Title: src.Spec.Service.Title,
215209
Subtitle: src.Spec.Service.Subtitle,
216-
// MetadataIdentifier: Todo take from service.links?
217-
Rights: src.Spec.Service.Rights,
210+
Rights: src.Spec.Service.Rights,
218211
Author: Author{
219-
Name: src.Spec.Service.Author.Name,
220-
Email: src.Spec.Service.Author.Email,
212+
Name: "PDOK Beheer",
213+
221214
},
222215
}
223216
log.Printf("Done mapping the Service...")
@@ -227,11 +220,10 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
227220
dst.Spec.Service.Datasets = []Dataset{}
228221
for _, srcDatasetFeed := range src.Spec.DatasetFeeds {
229222
dstDataset := Dataset{
230-
Name: srcDatasetFeed.TechnicalName,
231-
Title: srcDatasetFeed.Title,
232-
Subtitle: srcDatasetFeed.Subtitle,
233-
MetadataIdentifier: "", // Todo take from Links?
234-
SourceIdentifier: srcDatasetFeed.SpatialDatasetIdentifierCode,
223+
Name: srcDatasetFeed.TechnicalName,
224+
Title: srcDatasetFeed.Title,
225+
Subtitle: srcDatasetFeed.Subtitle,
226+
SourceIdentifier: srcDatasetFeed.SpatialDatasetIdentifierCode,
235227
}
236228

237229
// Map the links
@@ -246,7 +238,16 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
246238
}
247239
log.Printf("Done mapping the Links...")
248240

249-
// TODO Bbox
241+
if srcDatasetFeed.Entries != nil && len(srcDatasetFeed.Entries) > 0 {
242+
// We can assume all entries have the same bbox, so we take the first one
243+
firstBbox := srcDatasetFeed.Entries[0].Polygon.BBox
244+
dstDataset.Bbox = Bbox{
245+
Minx: GetStringAsFloat32(firstBbox.MinX),
246+
Miny: GetStringAsFloat32(firstBbox.MinY),
247+
Maxx: GetStringAsFloat32(firstBbox.MaxX),
248+
Maxy: GetStringAsFloat32(firstBbox.MaxY),
249+
}
250+
}
250251

251252
// Map the downloads
252253
log.Printf("Start mapping the Entries...")
@@ -262,7 +263,6 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
262263
dstDownload.Updated = &updatedString
263264
}
264265

265-
// Polygon
266266
if srcEntry.SRS != nil {
267267
dstDownload.Srs = Srs{
268268
URI: srcEntry.SRS.URI,
@@ -285,8 +285,14 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
285285
if srcDownloadLink.Version != nil {
286286
dstLink.Version = srcDownloadLink.Version
287287
}
288-
// Todo bbox
289-
288+
if srcDownloadLink.BBox != nil {
289+
dstLink.Bbox = &Bbox{
290+
Minx: GetStringAsFloat32(srcDownloadLink.BBox.MinX),
291+
Miny: GetStringAsFloat32(srcDownloadLink.BBox.MinY),
292+
Maxx: GetStringAsFloat32(srcDownloadLink.BBox.MaxX),
293+
Maxy: GetStringAsFloat32(srcDownloadLink.BBox.MaxY),
294+
}
295+
}
290296
}
291297

292298
log.Printf("Done mapping the DownloadLinks...")
@@ -310,10 +316,35 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
310316
return nil
311317
}
312318

319+
func createBaseURL(host string, general General) (baseURL string) {
320+
321+
atomURI := fmt.Sprintf("%s/%s", general.DatasetOwner, general.Dataset)
322+
if general.Theme != nil {
323+
atomURI += fmt.Sprintf("/%s", *general.Theme)
324+
}
325+
atomURI += "/atom"
326+
327+
if general.ServiceVersion != nil {
328+
atomURI += fmt.Sprintf("/%s", *general.ServiceVersion)
329+
}
330+
331+
baseURL = fmt.Sprintf("%s/%s/index.xml", host, atomURI)
332+
return
333+
}
334+
313335
func GetInt32Pointer(value int32) *int32 {
314336
return &value
315337
}
316338

317339
func GetIntPointer(value int) *int {
318340
return &value
319341
}
342+
343+
func GetFloat32AsString(value float32) string {
344+
return strconv.FormatFloat(float64(value), 'f', 0, 32)
345+
}
346+
347+
func GetStringAsFloat32(value string) float32 {
348+
float, _ := strconv.ParseFloat(value, 32)
349+
return float32(float)
350+
}

api/v3/atom_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ type Lifecycle struct {
4242

4343
// Service defines the service configuration for the Atom feed
4444
type Service struct {
45-
BaseURL string `json:"baseUrl"`
46-
Lang string `json:"lang,omitempty"`
47-
Stylesheet string `json:"stylesheet,omitempty"`
48-
Title string `json:"title"`
49-
Subtitle string `json:"subtitle,omitempty"`
50-
Links []Link `json:"links,omitempty"`
51-
Rights string `json:"rights,omitempty"`
52-
Author Author `json:"author"`
45+
BaseURL string `json:"baseUrl"`
46+
Lang string `json:"lang,omitempty"`
47+
Stylesheet string `json:"stylesheet,omitempty"`
48+
Title string `json:"title"`
49+
Subtitle string `json:"subtitle,omitempty"`
50+
OwnerInfoRef string `json:"ownerInfoRef"`
51+
Links []Link `json:"links,omitempty"`
52+
Rights string `json:"rights,omitempty"`
5353
}
5454

5555
// Link represents a link in the service or dataset feed

config/samples/v3_atom.yaml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ spec:
1717
stylesheet: "http://localhost/atom/style/style.xsl"
1818
title: Test Dataset ATOM
1919
subtitle: Test Dataset ATOM
20-
links:
21-
- href: "https://www.ngr.nl/geonetwork/srv/dut/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id=9615cd15-631b-45f8-a22a-d9d9c48cf211"
22-
category: metadataXml
23-
- href: "https://www.ngr.nl/geonetwork/opensearch/dut/9615cd15-631b-45f8-a22a-d9d9c48cf211/OpenSearchDescription.xml"
24-
category: opensearch
25-
- href: "https://www.ngr.nl/geonetwork/srv/dut/catalog.search#/metadata/9615cd15-631b-45f8-a22a-d9d9c48cf211"
26-
category: metadataHtml
27-
rel: describedBy #zie https://kadaster.atlassian.net/browse/PDOK-15321
20+
ownerInfoRef: pdok
21+
serviceMetadataLinks:
22+
metadataIdentifier: 9615cd15-631b-45f8-a22a-d9d9c48cf211
23+
templates:
24+
- csv
25+
- opensearch
26+
- html
2827
rights: https://creativecommons.org/publicdomain/zero/1.0/deed.nl
2928
author:
3029
name: "PDOK Beheer"
@@ -33,9 +32,11 @@ spec:
3332
- technicalName: dataset-1-name
3433
title: "dataset-1-title \"1\""
3534
subtitle: "dataset-1-subtitle \"1\""
36-
links:
37-
- href: "https://www.ngr.nl/geonetwork/srv/dut/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id=9615cd15-631b-45f8-a22a-d9d9c48cf211"
38-
category: metadataXml
35+
datasetMetadataLinks:
36+
metadataIdentifier: 9615cd15-631b-45f8-a22a-d9d9c48cf211
37+
templates:
38+
- csv
39+
- html
3940
author:
4041
name: owner
4142
@@ -58,9 +59,12 @@ spec:
5859
- technicalName: dataset-2-name
5960
title: "dataset-2-title \"2\""
6061
subtitle: "dataset-2-subtitle \"2\""
62+
datasetMetadataLinks:
63+
metadataIdentifier: 9615cd15-631b-45f8-a22a-d9d9c48cf211
64+
templates:
65+
- csv
66+
- html
6167
links:
62-
- href: "https://www.ngr.nl/geonetwork/srv/dut/csw?service=CSW&version=2.0.2&request=GetRecordById&outputschema=http://www.isotc211.org/2005/gmd&elementsetname=full&id=9615cd15-631b-45f8-a22a-d9d9c48cf211"
63-
category: metadataXml
6468
- href: https://www.eionet.europa.eu/reportnet/docs/noise/guidelines/geopackage-encoding-rule-end.pdf
6569
title: encodingRule
6670
type: application/pdf

0 commit comments

Comments
 (0)