Skip to content

Commit e9e8fe4

Browse files
committed
PDOK-17552 Operator uitwerken voor ATOM v3. Mapping
1 parent f98e117 commit e9e8fe4

File tree

3 files changed

+44
-34
lines changed

3 files changed

+44
-34
lines changed

go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/onsi/gomega v1.35.1
1010
github.com/pdok/atom-generator v0.6.0
1111
github.com/traefik/traefik/v2 v2.11.20
12+
golang.org/x/tools v0.28.0
1213
k8s.io/api v0.32.0
1314
k8s.io/apimachinery v0.32.0
1415
k8s.io/client-go v0.32.0
@@ -25,7 +26,6 @@ require (
2526
github.com/blang/semver/v4 v4.0.0 // indirect
2627
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2728
github.com/cespare/xxhash/v2 v2.3.0 // indirect
28-
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
2929
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3030
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
3131
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
@@ -68,15 +68,12 @@ require (
6868
github.com/prometheus/common v0.55.0 // indirect
6969
github.com/prometheus/procfs v0.15.1 // indirect
7070
github.com/rogpeppe/go-internal v1.13.1 // indirect
71-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
7271
github.com/sirupsen/logrus v1.9.3 // indirect
7372
github.com/spf13/cobra v1.8.1 // indirect
7473
github.com/spf13/pflag v1.0.5 // indirect
7574
github.com/stoewer/go-strcase v1.3.0 // indirect
7675
github.com/traefik/paerser v0.2.1 // indirect
77-
github.com/urfave/cli/v2 v2.27.5 // indirect
7876
github.com/x448/float16 v0.8.4 // indirect
79-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
8077
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
8178
go.opentelemetry.io/otel v1.32.0 // indirect
8279
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
@@ -97,7 +94,6 @@ require (
9794
golang.org/x/term v0.27.0 // indirect
9895
golang.org/x/text v0.21.0 // indirect
9996
golang.org/x/time v0.8.0 // indirect
100-
golang.org/x/tools v0.28.0 // indirect
10197
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
10298
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
10399
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect

go.sum

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
1515
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1616
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
1717
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
18-
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
19-
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
2018
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2119
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2220
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
@@ -107,8 +105,6 @@ github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4=
107105
github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
108106
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
109107
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
110-
github.com/pdok/atom-generator v0.0.0-20241003082215-84430ecd16d1 h1:FiEShEG+b/UKtBDwid3p1MIjamaHuc++RBYz1+3V1xc=
111-
github.com/pdok/atom-generator v0.0.0-20241003082215-84430ecd16d1/go.mod h1:+tW5rgSjcPZeLkIBeKAkCKMeQNHVl/2moqf3uvv7LTI=
112108
github.com/pdok/atom-generator v0.6.0 h1:7VbGn98Js2kJwhLRqbeX8D+byW5DfovTgJ09bMYg3Ew=
113109
github.com/pdok/atom-generator v0.6.0/go.mod h1:+tW5rgSjcPZeLkIBeKAkCKMeQNHVl/2moqf3uvv7LTI=
114110
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -126,7 +122,6 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
126122
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
127123
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
128124
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
129-
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
130125
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
131126
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
132127
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
@@ -150,12 +145,8 @@ github.com/traefik/paerser v0.2.1 h1:LFgeak1NmjEHF53c9ENdXdL1UMkF/lD5t+7Evsz4hH4
150145
github.com/traefik/paerser v0.2.1/go.mod h1:7BBDd4FANoVgaTZG+yh26jI6CA2nds7D/4VTEdIsh24=
151146
github.com/traefik/traefik/v2 v2.11.20 h1:22xF9h9/X6V4753ICTNHS6UnkwfHMy8+I9Swb4nEBt4=
152147
github.com/traefik/traefik/v2 v2.11.20/go.mod h1:MnIv8lbvljiRR3NIrF4F/RfkUtHovQ8C9nHhKRFnA6U=
153-
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
154-
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
155148
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
156149
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
157-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
158-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
159150
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
160151
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
161152
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 h1:TT4fX+nBOA/+LUkobKGW1ydGcn+G3vRw9+g5HwCphpk=

internal/controller/atom_generator/mapping.go

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func MapAtomV3ToAtomGeneratorConfig(atom pdoknlv3.Atom) (atomGeneratorConfig ato
1616
searchLink := getLinkByRelation(atom, language, "search")
1717
upLink := getLinkByRelation(atom, language, "up")
1818
relatedLink := getLinkByRelation(atom, language, "related")
19+
latestUpdated := getLatestUpdate(atom.Spec.DatasetFeeds)
1920

2021
atomGeneratorConfig = atom_feed.Feeds{
2122
Feeds: []atom_feed.Feed{
@@ -37,33 +38,45 @@ func MapAtomV3ToAtomGeneratorConfig(atom pdoknlv3.Atom) (atomGeneratorConfig ato
3738
Link: []atom_feed.Link{
3839
relatedLink,
3940
},
40-
Rights: atom.Spec.Service.Rights,
41-
//Updated: atom.Spec.Service.U niet meer vindbaar
42-
Author: getAuthor(atom.Spec.Author),
43-
Entry: getEntriesArray(atom),
41+
Rights: atom.Spec.Service.Rights,
42+
Updated: &latestUpdated,
43+
Author: getAuthor(atom.Spec.Author),
44+
Entry: getEntriesArray(atom),
4445
},
4546
},
4647
}
4748
return atomGeneratorConfig, err
4849
}
4950

51+
func getLatestUpdate(feeds []pdoknlv3.DatasetFeed) string {
52+
updateTime := feeds[0].Entries[0].Updated
53+
for _, datasetFeed := range feeds {
54+
for _, entry := range datasetFeed.Entries {
55+
if updateTime.Before(entry.Updated) {
56+
updateTime = entry.Updated
57+
}
58+
}
59+
}
60+
return updateTime.Format(time.RFC3339)
61+
}
62+
5063
func getEntriesArray(atom pdoknlv3.Atom) []atom_feed.Entry {
5164
var retEntriesArray []atom_feed.Entry
5265
for _, datasetFeed := range atom.Spec.DatasetFeeds {
5366
for _, entry := range datasetFeed.Entries {
5467
updateTime := entry.Updated.Format(time.RFC3339)
5568

5669
singleEntry := atom_feed.Entry{
57-
ID: entry.TechnicalName,
58-
Title: entry.Title,
59-
Content: entry.Content,
60-
//Summary: entry.,
61-
//Rights: entry.Right,
62-
Updated: &updateTime,
63-
Polygon: getBoundingBoxPolygon(entry.Polygon),
64-
//SpatialDatasetIdentifierCode: nil,
65-
//SpatialDatasetIdentifierNamespace: nil,
66-
//Category: nil,
70+
ID: entry.TechnicalName,
71+
Title: entry.Title,
72+
Content: entry.Content,
73+
Summary: datasetFeed.Subtitle,
74+
Rights: atom.Spec.Service.Rights,
75+
Updated: &updateTime,
76+
Polygon: getBoundingBoxPolygon(entry.Polygon.BBox),
77+
SpatialDatasetIdentifierCode: datasetFeed.SpatialDatasetIdentifierCode,
78+
SpatialDatasetIdentifierNamespace: datasetFeed.SpatialDatasetIdentifierNamespace,
79+
Category: getCategory(entry.SRS),
6780
//Link: nil, // []Links
6881
}
6982
retEntriesArray = append(retEntriesArray, singleEntry)
@@ -73,18 +86,28 @@ func getEntriesArray(atom pdoknlv3.Atom) []atom_feed.Entry {
7386
return retEntriesArray
7487
}
7588

76-
func getBoundingBoxPolygon(polygon *pdoknlv3.Polygon) string {
89+
func getCategory(srs *pdoknlv3.SRS) []atom_feed.Category {
90+
cat := []atom_feed.Category{
91+
{
92+
Term: srs.URI,
93+
Label: srs.Name,
94+
},
95+
}
96+
return cat
97+
}
98+
99+
func getBoundingBoxPolygon(bbox pdoknlv3.BBox) string {
77100
var sb strings.Builder
78101
// punt links beneden start van een polygon
79-
sb.WriteString(polygon.BBox.MinX + " " + polygon.BBox.MinY + " ")
102+
sb.WriteString(bbox.MinX + " " + bbox.MinY + " ")
80103
// punt links boven start van een polygon
81-
sb.WriteString(polygon.BBox.MinX + " " + polygon.BBox.MaxY + " ")
104+
sb.WriteString(bbox.MinX + " " + bbox.MaxY + " ")
82105
// punt rechts boven start van een polygon
83-
sb.WriteString(polygon.BBox.MaxX + " " + polygon.BBox.MaxY + " ")
106+
sb.WriteString(bbox.MaxX + " " + bbox.MaxY + " ")
84107
// punt rechts beneden start van een polygon
85-
sb.WriteString(polygon.BBox.MaxX + " " + polygon.BBox.MinY + " ")
108+
sb.WriteString(bbox.MaxX + " " + bbox.MinY + " ")
86109
// punt links beneden. eninde van een polygon is gelijk aan de start
87-
sb.WriteString(polygon.BBox.MinX + " " + polygon.BBox.MinY + " ")
110+
sb.WriteString(bbox.MinX + " " + bbox.MinY + " ")
88111
return sb.String()
89112
}
90113

0 commit comments

Comments
 (0)