diff --git a/lib/catalog.js b/lib/catalog.js index 33c784f76de2e75f608d4e0bf8d71b42c29d77a9..28162c57e30069863d8b7f391d792ad6c356480f 100644 --- a/lib/catalog.js +++ b/lib/catalog.js @@ -58,7 +58,8 @@ const DEFAULT_IRI_PREFS = { 'funder': '_:funder/', 'license': '_:license/', 'citation': '_:citation/', - 'contact': '_:contact/' + 'contact': '_:contact/', + 'location': '_:location/' }; @@ -395,13 +396,15 @@ function make_files(datapub) { 'encodingFormat': dl['mimeType'] } } + // Not using the url as the @id because there's no guarantee it won't + // accidentally match another @id - prefix it if( dl['type'] === 'url' ) { return { - '@id': dl['url'], - 'name': dl['url'], + '@id': DEFAULT_IRI_PREFS['location'] + dl['location'], + 'name': dl['location'], '@type': 'WebSite', 'description': dl['notes'], - 'url': dl['url'] + 'url': dl['location'] } } // physical locations or file paths don't get anything diff --git a/test/catalog.spec.js b/test/catalog.spec.js index 107ccb6b556a61e899b2ecc279f4eaf46ced8108..6da02eaaf8ff3d03607679c80c3e418099afb864 100644 --- a/test/catalog.spec.js +++ b/test/catalog.spec.js @@ -67,7 +67,8 @@ const IRI_PREFIXES = { 'funder': '_:funder/', 'licence': '_:licence/', 'citation': '_:citation/', - 'contact': '_:contact/' + 'contact': '_:contact/', + 'location': '_:location/' }; @@ -307,7 +308,7 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { it("has the payload files", () => { const files = get_type(cj, "File"); - const datalocs = dp['dataLocations']; + const datalocs = dp['dataLocations'].filter(dl => dl['type'] === 'attachment'); expect(files).to.have.length(datalocs.length); const fids = files.map((f) => f['@id']).sort(); const dlids = datalocs.map((dl) => dl['fileId'] + '/' + dl['name']).sort(); @@ -315,6 +316,17 @@ describe("Convert a ReDBox 2.0 DataPub to CATALOG.json", () => { files.map((f) => assert_link(cjds, 'hasPart', f)); }); + it("has the payload url", () => { + const urls = get_type(cj, "WebSite").filter(ws => ws['@id'].startsWith(IRI_PREFIXES['location'])); + const datalocs = dp['dataLocations'].filter(dl => dl['type'] === 'url'); + expect(urls).to.have.length(datalocs.length); + const fids = urls.map((f) => f['@id']).sort(); + const dlids = datalocs.map((dl) => IRI_PREFIXES['location'] + dl['location']).sort(); + expect(fids).to.eql(dlids); + urls.map((f) => assert_link(cjds, 'hasPart', f)); + }); + + it("has creators", function () { const creators_orig = _.compact(_.uniq(dp['creators'].map(c => c['email']))); const dataset = get_id(cj, DATASET_ID); @@ -509,8 +521,9 @@ describe("Create catalogs with some or none of the data payloads", () => { }); - it("can create a catalog with one payload file deselected", async () => { + it("can create a catalog with one payload file selected", async () => { dp['dataLocations'][0]['selected'] = false; + dp['dataLocations'][2]['selected'] = false; var selected = []; dp['dataLocations'].forEach((l) => { if( l['selected'] ) { diff --git a/test_data/datapub.json b/test_data/datapub.json index af8592a119fda1fec08c4e004334bd042ac10dbb..9d46598bcef89ce86262542cbb40d4e6fcc69d30 100644 --- a/test_data/datapub.json +++ b/test_data/datapub.json @@ -197,7 +197,15 @@ "uploadUrl" : "https://stash-uat.research.uts.edu.au/default/rdmp/record/61b10d12b2d40f3d3286da5a27c4eb5a/attach/f39fca10e8a2bcaad04045c2cea3c2d3", "selected" : true, "notes" : "Notes about the second attachment" + }, + { + "type" : "url", + "location" : "https://datasets.org", + "isc" : "public", + "notes" : "an imaginary url", + "selected" : true } + ], "dataLicensingAccess_manager" : "Michael Lynch", "dc:accessRights" : "Open",