Skip to content

Commit a7abea4

Browse files
committed
Add nil checks and extra logging
1 parent 84b9c79 commit a7abea4

File tree

1 file changed

+102
-38
lines changed

1 file changed

+102
-38
lines changed

api/v2beta1/atom_conversion.go

Lines changed: 102 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
3737
log.Printf("ConvertTo: Converting Atom from Spoke version v2beta1 to Hub version v3;"+
3838
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
3939

40-
// TODO(user): Implement conversion logic from v2beta1 to v3
41-
4240
// Lifecycle
41+
log.Printf("Start mapping the Lifecycle specs...")
4342
dst.Spec.Lifecycle.TTLInDays = GetInt32Pointer(int32(*src.Spec.Kubernetes.Lifecycle.TTLInDays))
43+
log.Printf("Done mapping the Lifecycle specs...")
4444

4545
// Service
46+
log.Printf("Start mapping the Service...")
4647
dst.Spec.Service = pdoknlv3.Service{
4748
// Todo BaseURL opbouwen
4849
BaseURL: "http://localhost/owner/dataset",
@@ -72,8 +73,10 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
7273
7374
},
7475
}
76+
log.Printf("Done mapping the Service...")
7577

7678
dst.Spec.DatasetFeeds = []pdoknlv3.DatasetFeed{}
79+
log.Printf("Start mapping the Datasets...")
7780
for _, srcDataset := range src.Spec.Service.Datasets {
7881
dstDatasetFeed := pdoknlv3.DatasetFeed{
7982
TechnicalName: "<id>.xml",
@@ -88,22 +91,32 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
8891
}
8992

9093
// Map the links
94+
log.Printf("Start mapping the Links...")
9195
for _, srcLink := range srcDataset.Links {
92-
dstDatasetFeed.Links = append(dstDatasetFeed.Links, pdoknlv3.Link{
93-
Title: srcLink.Type,
94-
Href: srcLink.URI,
95-
Type: *srcLink.ContentType,
96-
Hreflang: *srcLink.Language,
97-
})
96+
dstLink := pdoknlv3.Link{
97+
Title: srcLink.Type,
98+
Href: srcLink.URI,
99+
}
100+
if srcLink.ContentType != nil {
101+
dstLink.Type = *srcLink.ContentType
102+
}
103+
if srcLink.Language != nil {
104+
dstLink.Href = *srcLink.Language
105+
}
106+
107+
dstDatasetFeed.Links = append(dstDatasetFeed.Links, dstLink)
98108
}
109+
log.Printf("Done mapping the Links...")
99110

100111
// Map the entries
112+
log.Printf("Start mapping the Entries...")
101113
for _, srcDownload := range srcDataset.Downloads {
102114
dstEntry := pdoknlv3.Entry{
103-
TechnicalName: srcDownload.Name, // TechnicalName vs Name?
104-
Title: *srcDownload.Title,
105-
Content: *srcDownload.Content,
106-
Updated: nil, // TODO Convert from srcDownload.Updated
115+
TechnicalName: srcDownload.Name,
116+
SRS: &pdoknlv3.SRS{
117+
URI: srcDownload.Srs.URI,
118+
Name: srcDownload.Srs.Code,
119+
},
107120
// TODO fix polygon float dangerousTypes
108121
// Polygon: pdoknlv3.Polygon{
109122
// BBox: pdoknlv3.BBox{
@@ -113,27 +126,50 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error {
113126
// MaxY: strconv.FormatFloat(srcDataset.Bbox.Maxy, 'f', -1, 32),
114127
// },
115128
// },
116-
SRS: &pdoknlv3.SRS{
117-
URI: srcDownload.Srs.URI,
118-
Name: srcDownload.Srs.Code,
119-
},
129+
}
130+
131+
if srcDownload.Title != nil {
132+
dstEntry.Title = *srcDownload.Title
133+
}
134+
if srcDownload.Content != nil {
135+
dstEntry.Content = *srcDownload.Content
136+
}
137+
if srcDownload.Updated != nil {
138+
dstEntry.Updated = nil // TODO Convert from srcDownload.Updated
120139
}
121140

122141
// Map the links
142+
log.Printf("Start mapping the DownloadLinks...")
123143
for _, srcLink := range srcDownload.Links {
124-
dstEntry.DownloadLinks = append(dstEntry.DownloadLinks, pdoknlv3.DownloadLink{
125-
Data: *srcLink.BlobKey,
126-
Time: srcLink.Updated,
127-
Rel: *srcLink.Rel,
128-
Version: srcLink.Version,
129-
// Todo bbox
130-
})
144+
dstDownloadLink := pdoknlv3.DownloadLink{}
145+
146+
if srcLink.BlobKey != nil {
147+
dstDownloadLink.Data = *srcLink.BlobKey
148+
}
149+
if srcLink.Updated != nil {
150+
dstDownloadLink.Time = srcLink.Updated
151+
}
152+
if srcLink.Version != nil {
153+
dstDownloadLink.Version = srcLink.Version
154+
}
155+
156+
// Todo bbox
157+
158+
if srcLink.Rel != nil {
159+
dstDownloadLink.Rel = *srcLink.Rel
160+
}
161+
162+
dstEntry.DownloadLinks = append(dstEntry.DownloadLinks, dstDownloadLink)
131163
}
164+
log.Printf("Done mapping the DownloadLinks...")
165+
132166
dstDatasetFeed.Entries = append(dstDatasetFeed.Entries, dstEntry)
133167
}
168+
log.Printf("Done mapping the Entries...")
134169

135170
dst.Spec.DatasetFeeds = append(dst.Spec.DatasetFeeds, dstDatasetFeed)
136171
}
172+
log.Printf("Done mapping the Datasets...")
137173

138174
return nil
139175
}
@@ -144,18 +180,19 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
144180
log.Printf("ConvertFrom: Converting Atom from Hub version v3 to Spoke version v2beta1;"+
145181
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name)
146182

147-
// TODO(user): Implement conversion logic from v3 to v2beta1
148-
149183
// General
184+
log.Printf("Start mapping the General specs...")
150185
dst.Spec.General = General{ // Todo waar halen we deze info vandaan
151186
Dataset: "",
152187
DatasetOwner: "",
153188
DataVersion: new(string),
154189
ServiceVersion: new(string),
155190
Theme: new(string),
156191
}
192+
log.Printf("Done mapping the General specs...")
157193

158194
// Service
195+
log.Printf("Start mapping the Service...")
159196
dst.Spec.Service = AtomService{
160197
Title: src.Spec.Service.Title,
161198
Subtitle: src.Spec.Service.Subtitle,
@@ -166,8 +203,10 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
166203
Email: src.Spec.Service.Author.Email,
167204
},
168205
}
206+
log.Printf("Done mapping the Service...")
169207

170208
// Datasets
209+
log.Printf("Start mapping the Datasets...")
171210
dst.Spec.Service.Datasets = []Dataset{}
172211
for _, srcDatasetFeed := range src.Spec.DatasetFeeds {
173212
dstDataset := Dataset{
@@ -179,6 +218,7 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
179218
}
180219

181220
// Map the links
221+
log.Printf("Start mapping the Links...")
182222
for _, srcLink := range srcDatasetFeed.Links {
183223
dstDataset.Links = append(dstDataset.Links, OtherLink{
184224
Type: srcLink.Title,
@@ -187,44 +227,68 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error {
187227
Language: &srcLink.Hreflang,
188228
})
189229
}
230+
log.Printf("Done mapping the Links...")
190231

191232
// TODO Bbox
192233

193234
// Map the downloads
235+
log.Printf("Start mapping the Entries...")
194236
for _, srcEntry := range srcDatasetFeed.Entries {
195237
dstDownload := Download{
196238
Name: srcEntry.TechnicalName,
197-
Updated: nil,
198239
Content: &srcEntry.Content,
199240
Title: &srcEntry.Title,
200-
// Todo links
201-
Srs: Srs{
241+
}
242+
243+
if srcEntry.Updated != nil {
244+
// Todo convert
245+
//dstDownload.Updated = srcEntry.Updated
246+
}
247+
248+
// Polygon
249+
if srcEntry.SRS != nil {
250+
dstDownload.Srs = Srs{
202251
URI: srcEntry.SRS.URI,
203252
Code: srcEntry.SRS.Name,
204-
},
253+
}
205254
}
255+
206256
// Map the links
257+
log.Printf("Start mapping the DownloadLinks...")
207258
for _, srcDownloadLink := range srcEntry.DownloadLinks {
208-
dstDownload.Links = append(dstDownload.Links, Link{
259+
260+
dstLink := Link{
209261
BlobKey: &srcDownloadLink.Data,
210-
Updated: srcDownloadLink.Time,
211262
Rel: &srcDownloadLink.Rel,
212-
Version: srcDownloadLink.Version,
213-
// Todo bbox
214-
})
263+
}
264+
265+
if srcDownloadLink.Time != nil {
266+
dstLink.Updated = srcDownloadLink.Time
267+
}
268+
if srcDownloadLink.Version != nil {
269+
dstLink.Version = srcDownloadLink.Version
270+
}
271+
// Todo bbox
272+
215273
}
274+
275+
log.Printf("Done mapping the DownloadLinks...")
216276
dstDataset.Downloads = append(dstDataset.Downloads, dstDownload)
217277
}
218-
278+
log.Printf("Done mapping the Entries...")
219279
dst.Spec.Service.Datasets = append(dst.Spec.Service.Datasets, dstDataset)
220280
}
281+
log.Printf("Start mapping the Datasets...")
221282

222283
// Kubernetes
284+
log.Printf("Start mapping the Kubernetes Specs...")
223285
dst.Spec.Kubernetes = &Kubernetes{
224-
Lifecycle: &Lifecycle{
225-
TTLInDays: GetIntPointer(int(*src.Spec.Lifecycle.TTLInDays)),
226-
},
286+
Lifecycle: &Lifecycle{},
287+
}
288+
if src.Spec.Lifecycle.TTLInDays != nil {
289+
dst.Spec.Kubernetes.Lifecycle.TTLInDays = GetIntPointer(int(*src.Spec.Lifecycle.TTLInDays))
227290
}
291+
log.Printf("Done mapping the Kubernetes Specs...")
228292

229293
return nil
230294
}

0 commit comments

Comments
 (0)