@@ -28,6 +28,7 @@ import (
28
28
"fmt"
29
29
"log"
30
30
"strconv"
31
+ "strings"
31
32
"time"
32
33
33
34
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -42,47 +43,44 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
42
43
log .Printf ("ConvertTo: Converting Atom from Spoke version v2beta1 to Hub version v3;" +
43
44
"source: %s/%s, target: %s/%s" , src .Namespace , src .Name , dst .Namespace , dst .Name )
44
45
45
- host := "https://service.pdok.nl/" // Todo read from flag
46
-
47
46
// ObjectMeta
48
47
dst .ObjectMeta = src .ObjectMeta
49
48
50
49
// Lifecycle
51
- log .Printf ("Start mapping the Lifecycle specs..." )
52
50
if src .Spec .Kubernetes != nil && src .Spec .Kubernetes .Lifecycle != nil && src .Spec .Kubernetes .Lifecycle .TTLInDays != nil {
53
51
dst .Spec .Lifecycle .TTLInDays = GetInt32Pointer (int32 (* src .Spec .Kubernetes .Lifecycle .TTLInDays ))
54
52
}
55
- log .Printf ("Done mapping the Lifecycle specs..." )
56
53
57
54
// Service
58
- log .Printf ("Start mapping the Service..." )
59
55
dst .Spec .Service = pdoknlv3.Service {
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
- ServiceMetadataLinks : []pdoknlv3.MetadataLink {}, // Todo
68
- Rights : src .Spec .Service .Rights ,
56
+ BaseURL : createBaseURL (pdoknlv3 .GetAtomBaseURLHost (), src .Spec .General ),
57
+ Lang : "nl" ,
58
+ Stylesheet : "https://service.pdok.nl/atom/style/style.xsl" ,
59
+ Title : src .Spec .Service .Title ,
60
+ Subtitle : src .Spec .Service .Subtitle ,
61
+ OwnerInfoRef : "pdok" ,
62
+ ServiceMetadataLinks : pdoknlv3.MetadataLink {
63
+ MetadataIdentifier : src .Spec .Service .MetadataIdentifier ,
64
+ Templates : []string {"csw" , "opensearch" , "html" },
65
+ },
66
+ Rights : src .Spec .Service .Rights ,
69
67
}
70
- log .Printf ("Done mapping the Service..." )
71
68
72
69
dst .Spec .DatasetFeeds = []pdoknlv3.DatasetFeed {}
73
- log .Printf ("Start mapping the Datasets..." )
74
70
for _ , srcDataset := range src .Spec .Service .Datasets {
75
71
dstDatasetFeed := pdoknlv3.DatasetFeed {
76
- TechnicalName : srcDataset .Name ,
77
- Title : srcDataset .Title ,
78
- Subtitle : srcDataset .Subtitle ,
79
- DatasetMetadataLinks : []pdoknlv3.MetadataLink {}, // Todo
72
+ TechnicalName : srcDataset .Name ,
73
+ Title : srcDataset .Title ,
74
+ Subtitle : srcDataset .Subtitle ,
75
+ DatasetMetadataLinks : pdoknlv3.MetadataLink {
76
+ MetadataIdentifier : srcDataset .MetadataIdentifier ,
77
+ Templates : []string {"csw" , "html" },
78
+ },
80
79
SpatialDatasetIdentifierCode : srcDataset .SourceIdentifier ,
81
80
SpatialDatasetIdentifierNamespace : "http://www.pdok.nl" ,
82
81
}
83
82
84
83
// Map the links
85
- log .Printf ("Start mapping the Links..." )
86
84
for _ , srcLink := range srcDataset .Links {
87
85
dstLink := pdoknlv3.Link {
88
86
Title : srcLink .Type ,
@@ -97,10 +95,8 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
97
95
98
96
dstDatasetFeed .Links = append (dstDatasetFeed .Links , dstLink )
99
97
}
100
- log .Printf ("Done mapping the Links..." )
101
98
102
99
// Map the entries
103
- log .Printf ("Start mapping the Entries..." )
104
100
for _ , srcDownload := range srcDataset .Downloads {
105
101
dstEntry := pdoknlv3.Entry {
106
102
TechnicalName : srcDownload .Name ,
@@ -135,7 +131,6 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
135
131
}
136
132
137
133
// Map the links
138
- log .Printf ("Start mapping the DownloadLinks..." )
139
134
for _ , srcLink := range srcDownload .Links {
140
135
dstDownloadLink := pdoknlv3.DownloadLink {}
141
136
@@ -162,15 +157,12 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
162
157
163
158
dstEntry .DownloadLinks = append (dstEntry .DownloadLinks , dstDownloadLink )
164
159
}
165
- log .Printf ("Done mapping the DownloadLinks..." )
166
160
167
161
dstDatasetFeed .Entries = append (dstDatasetFeed .Entries , dstEntry )
168
162
}
169
- log .Printf ("Done mapping the Entries..." )
170
163
171
164
dst .Spec .DatasetFeeds = append (dst .Spec .DatasetFeeds , dstDatasetFeed )
172
165
}
173
- log .Printf ("Done mapping the Datasets..." )
174
166
175
167
return nil
176
168
}
@@ -185,7 +177,6 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
185
177
dst .ObjectMeta = src .ObjectMeta
186
178
187
179
// General
188
- log .Printf ("Start mapping the General specs..." )
189
180
dst .Spec .General = General {
190
181
Dataset : src .ObjectMeta .Labels ["dataset" ],
191
182
DatasetOwner : src .ObjectMeta .Labels ["dataset-owner" ],
@@ -202,10 +193,7 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
202
193
dst .Spec .General .Theme = & theme
203
194
}
204
195
205
- log .Printf ("Done mapping the General specs..." )
206
-
207
196
// Service
208
- log .Printf ("Start mapping the Service..." )
209
197
dst .Spec .Service = AtomService {
210
198
Title : src .Spec .Service .Title ,
211
199
Subtitle : src .Spec .Service .Subtitle ,
@@ -214,11 +202,10 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
214
202
Name : "PDOK Beheer" ,
215
203
216
204
},
205
+ MetadataIdentifier : src .Spec .Service .ServiceMetadataLinks .MetadataIdentifier ,
217
206
}
218
- log .Printf ("Done mapping the Service..." )
219
207
220
208
// Datasets
221
- log .Printf ("Start mapping the Datasets..." )
222
209
dst .Spec .Service .Datasets = []Dataset {}
223
210
for _ , srcDatasetFeed := range src .Spec .DatasetFeeds {
224
211
dstDataset := Dataset {
@@ -229,7 +216,6 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
229
216
}
230
217
231
218
// Map the links
232
- log .Printf ("Start mapping the Links..." )
233
219
for _ , srcLink := range srcDatasetFeed .Links {
234
220
dstDataset .Links = append (dstDataset .Links , OtherLink {
235
221
Type : srcLink .Title ,
@@ -238,7 +224,6 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
238
224
Language : & srcLink .Hreflang ,
239
225
})
240
226
}
241
- log .Printf ("Done mapping the Links..." )
242
227
243
228
if len (srcDatasetFeed .Entries ) > 0 && srcDatasetFeed .Entries [0 ].Polygon != nil {
244
229
// We can assume all entries have the same bbox, so we take the first one
@@ -252,7 +237,6 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
252
237
}
253
238
254
239
// Map the downloads
255
- log .Printf ("Start mapping the Entries..." )
256
240
for _ , srcEntry := range srcDatasetFeed .Entries {
257
241
dstDownload := Download {
258
242
Name : srcEntry .TechnicalName ,
@@ -273,9 +257,7 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
273
257
}
274
258
275
259
// Map the links
276
- log .Printf ("Start mapping the DownloadLinks..." )
277
260
for _ , srcDownloadLink := range srcEntry .DownloadLinks {
278
-
279
261
dstLink := Link {
280
262
BlobKey : & srcDownloadLink .Data ,
281
263
Rel : & srcDownloadLink .Rel ,
@@ -297,29 +279,23 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
297
279
}
298
280
}
299
281
300
- log .Printf ("Done mapping the DownloadLinks..." )
301
282
dstDataset .Downloads = append (dstDataset .Downloads , dstDownload )
302
283
}
303
- log .Printf ("Done mapping the Entries..." )
304
284
dst .Spec .Service .Datasets = append (dst .Spec .Service .Datasets , dstDataset )
305
285
}
306
- log .Printf ("Start mapping the Datasets..." )
307
286
308
287
// Kubernetes
309
- log .Printf ("Start mapping the Kubernetes Specs..." )
310
288
dst .Spec .Kubernetes = & Kubernetes {
311
289
Lifecycle : & Lifecycle {},
312
290
}
313
291
if src .Spec .Lifecycle .TTLInDays != nil {
314
292
dst .Spec .Kubernetes .Lifecycle .TTLInDays = GetIntPointer (int (* src .Spec .Lifecycle .TTLInDays ))
315
293
}
316
- log .Printf ("Done mapping the Kubernetes Specs..." )
317
294
318
295
return nil
319
296
}
320
297
321
298
func createBaseURL (host string , general General ) (baseURL string ) {
322
-
323
299
atomURI := fmt .Sprintf ("%s/%s" , general .DatasetOwner , general .Dataset )
324
300
if general .Theme != nil {
325
301
atomURI += fmt .Sprintf ("/%s" , * general .Theme )
@@ -330,7 +306,7 @@ func createBaseURL(host string, general General) (baseURL string) {
330
306
atomURI += fmt .Sprintf ("/%s" , * general .ServiceVersion )
331
307
}
332
308
333
- baseURL = fmt .Sprintf ("%s/%s/index.xml" , host , atomURI )
309
+ baseURL = fmt .Sprintf ("%s/%s/index.xml" , strings . TrimSuffix ( host , "/" ) , atomURI )
334
310
return
335
311
}
336
312
0 commit comments