-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from PDOK/PDOK-17553-Atom-crd_converter-v2-v3
Pdok 17553 atom crd converter v2 v3
- Loading branch information
Showing
12 changed files
with
174 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ import ( | |
"fmt" | ||
"log" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -42,47 +43,44 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error { | |
log.Printf("ConvertTo: Converting Atom from Spoke version v2beta1 to Hub version v3;"+ | ||
"source: %s/%s, target: %s/%s", src.Namespace, src.Name, dst.Namespace, dst.Name) | ||
|
||
host := "https://service.pdok.nl/" // Todo read from flag | ||
|
||
// ObjectMeta | ||
dst.ObjectMeta = src.ObjectMeta | ||
|
||
// Lifecycle | ||
log.Printf("Start mapping the Lifecycle specs...") | ||
if src.Spec.Kubernetes != nil && src.Spec.Kubernetes.Lifecycle != nil && src.Spec.Kubernetes.Lifecycle.TTLInDays != nil { | ||
dst.Spec.Lifecycle.TTLInDays = GetInt32Pointer(int32(*src.Spec.Kubernetes.Lifecycle.TTLInDays)) | ||
} | ||
log.Printf("Done mapping the Lifecycle specs...") | ||
|
||
// Service | ||
log.Printf("Start mapping the Service...") | ||
dst.Spec.Service = pdoknlv3.Service{ | ||
BaseURL: createBaseURL(host, src.Spec.General), | ||
Lang: "nl", | ||
Stylesheet: "https://service.pdok.nl/atom/style/style.xsl", | ||
Title: src.Spec.Service.Title, | ||
Subtitle: src.Spec.Service.Subtitle, | ||
OwnerInfoRef: "pdok", | ||
Links: []pdoknlv3.Link{}, | ||
ServiceMetadataLinks: []pdoknlv3.MetadataLink{}, // Todo | ||
Rights: src.Spec.Service.Rights, | ||
BaseURL: createBaseURL(pdoknlv3.GetAtomBaseURLHost(), src.Spec.General), | ||
Lang: "nl", | ||
Stylesheet: "https://service.pdok.nl/atom/style/style.xsl", | ||
Title: src.Spec.Service.Title, | ||
Subtitle: src.Spec.Service.Subtitle, | ||
OwnerInfoRef: "pdok", | ||
ServiceMetadataLinks: pdoknlv3.MetadataLink{ | ||
MetadataIdentifier: src.Spec.Service.MetadataIdentifier, | ||
Templates: []string{"csw", "opensearch", "html"}, | ||
}, | ||
Rights: src.Spec.Service.Rights, | ||
} | ||
log.Printf("Done mapping the Service...") | ||
|
||
dst.Spec.DatasetFeeds = []pdoknlv3.DatasetFeed{} | ||
log.Printf("Start mapping the Datasets...") | ||
for _, srcDataset := range src.Spec.Service.Datasets { | ||
dstDatasetFeed := pdoknlv3.DatasetFeed{ | ||
TechnicalName: srcDataset.Name, | ||
Title: srcDataset.Title, | ||
Subtitle: srcDataset.Subtitle, | ||
DatasetMetadataLinks: []pdoknlv3.MetadataLink{}, // Todo | ||
TechnicalName: srcDataset.Name, | ||
Title: srcDataset.Title, | ||
Subtitle: srcDataset.Subtitle, | ||
DatasetMetadataLinks: pdoknlv3.MetadataLink{ | ||
MetadataIdentifier: srcDataset.MetadataIdentifier, | ||
Templates: []string{"csw", "html"}, | ||
}, | ||
SpatialDatasetIdentifierCode: srcDataset.SourceIdentifier, | ||
SpatialDatasetIdentifierNamespace: "http://www.pdok.nl", | ||
} | ||
|
||
// Map the links | ||
log.Printf("Start mapping the Links...") | ||
for _, srcLink := range srcDataset.Links { | ||
dstLink := pdoknlv3.Link{ | ||
Title: srcLink.Type, | ||
|
@@ -97,10 +95,8 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error { | |
|
||
dstDatasetFeed.Links = append(dstDatasetFeed.Links, dstLink) | ||
} | ||
log.Printf("Done mapping the Links...") | ||
|
||
// Map the entries | ||
log.Printf("Start mapping the Entries...") | ||
for _, srcDownload := range srcDataset.Downloads { | ||
dstEntry := pdoknlv3.Entry{ | ||
TechnicalName: srcDownload.Name, | ||
|
@@ -135,7 +131,6 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error { | |
} | ||
|
||
// Map the links | ||
log.Printf("Start mapping the DownloadLinks...") | ||
for _, srcLink := range srcDownload.Links { | ||
dstDownloadLink := pdoknlv3.DownloadLink{} | ||
|
||
|
@@ -162,15 +157,12 @@ func (src *Atom) ConvertTo(dstRaw conversion.Hub) error { | |
|
||
dstEntry.DownloadLinks = append(dstEntry.DownloadLinks, dstDownloadLink) | ||
} | ||
log.Printf("Done mapping the DownloadLinks...") | ||
|
||
dstDatasetFeed.Entries = append(dstDatasetFeed.Entries, dstEntry) | ||
} | ||
log.Printf("Done mapping the Entries...") | ||
|
||
dst.Spec.DatasetFeeds = append(dst.Spec.DatasetFeeds, dstDatasetFeed) | ||
} | ||
log.Printf("Done mapping the Datasets...") | ||
|
||
return nil | ||
} | ||
|
@@ -185,7 +177,6 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error { | |
dst.ObjectMeta = src.ObjectMeta | ||
|
||
// General | ||
log.Printf("Start mapping the General specs...") | ||
dst.Spec.General = General{ | ||
Dataset: src.ObjectMeta.Labels["dataset"], | ||
DatasetOwner: src.ObjectMeta.Labels["dataset-owner"], | ||
|
@@ -202,10 +193,7 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error { | |
dst.Spec.General.Theme = &theme | ||
} | ||
|
||
log.Printf("Done mapping the General specs...") | ||
|
||
// Service | ||
log.Printf("Start mapping the Service...") | ||
dst.Spec.Service = AtomService{ | ||
Title: src.Spec.Service.Title, | ||
Subtitle: src.Spec.Service.Subtitle, | ||
|
@@ -214,11 +202,10 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error { | |
Name: "PDOK Beheer", | ||
Email: "[email protected]", | ||
}, | ||
MetadataIdentifier: src.Spec.Service.ServiceMetadataLinks.MetadataIdentifier, | ||
} | ||
log.Printf("Done mapping the Service...") | ||
|
||
// Datasets | ||
log.Printf("Start mapping the Datasets...") | ||
dst.Spec.Service.Datasets = []Dataset{} | ||
for _, srcDatasetFeed := range src.Spec.DatasetFeeds { | ||
dstDataset := Dataset{ | ||
|
@@ -229,7 +216,6 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error { | |
} | ||
|
||
// Map the links | ||
log.Printf("Start mapping the Links...") | ||
for _, srcLink := range srcDatasetFeed.Links { | ||
dstDataset.Links = append(dstDataset.Links, OtherLink{ | ||
Type: srcLink.Title, | ||
|
@@ -238,7 +224,6 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error { | |
Language: &srcLink.Hreflang, | ||
}) | ||
} | ||
log.Printf("Done mapping the Links...") | ||
|
||
if len(srcDatasetFeed.Entries) > 0 && srcDatasetFeed.Entries[0].Polygon != nil { | ||
// 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 { | |
} | ||
|
||
// Map the downloads | ||
log.Printf("Start mapping the Entries...") | ||
for _, srcEntry := range srcDatasetFeed.Entries { | ||
dstDownload := Download{ | ||
Name: srcEntry.TechnicalName, | ||
|
@@ -273,9 +257,7 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error { | |
} | ||
|
||
// Map the links | ||
log.Printf("Start mapping the DownloadLinks...") | ||
for _, srcDownloadLink := range srcEntry.DownloadLinks { | ||
|
||
dstLink := Link{ | ||
BlobKey: &srcDownloadLink.Data, | ||
Rel: &srcDownloadLink.Rel, | ||
|
@@ -297,29 +279,23 @@ func (dst *Atom) ConvertFrom(srcRaw conversion.Hub) error { | |
} | ||
} | ||
|
||
log.Printf("Done mapping the DownloadLinks...") | ||
dstDataset.Downloads = append(dstDataset.Downloads, dstDownload) | ||
} | ||
log.Printf("Done mapping the Entries...") | ||
dst.Spec.Service.Datasets = append(dst.Spec.Service.Datasets, dstDataset) | ||
} | ||
log.Printf("Start mapping the Datasets...") | ||
|
||
// Kubernetes | ||
log.Printf("Start mapping the Kubernetes Specs...") | ||
dst.Spec.Kubernetes = &Kubernetes{ | ||
Lifecycle: &Lifecycle{}, | ||
} | ||
if src.Spec.Lifecycle.TTLInDays != nil { | ||
dst.Spec.Kubernetes.Lifecycle.TTLInDays = GetIntPointer(int(*src.Spec.Lifecycle.TTLInDays)) | ||
} | ||
log.Printf("Done mapping the Kubernetes Specs...") | ||
|
||
return nil | ||
} | ||
|
||
func createBaseURL(host string, general General) (baseURL string) { | ||
|
||
atomURI := fmt.Sprintf("%s/%s", general.DatasetOwner, general.Dataset) | ||
if general.Theme != nil { | ||
atomURI += fmt.Sprintf("/%s", *general.Theme) | ||
|
@@ -330,7 +306,7 @@ func createBaseURL(host string, general General) (baseURL string) { | |
atomURI += fmt.Sprintf("/%s", *general.ServiceVersion) | ||
} | ||
|
||
baseURL = fmt.Sprintf("%s/%s/index.xml", host, atomURI) | ||
baseURL = fmt.Sprintf("%s/%s/index.xml", strings.TrimSuffix(host, "/"), atomURI) | ||
return | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.