Skip to content
Snippets Groups Projects
Commit 90ae436f authored by Mike Lynch's avatar Mike Lynch
Browse files

Added a test script and a sample data pub for it to run against

parent 461afcb0
Branches
Tags
No related merge requests found
......@@ -14,4 +14,9 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
\ No newline at end of file
*/
module.exports = {
Catalog: require('./lib/catalog.js')
}
/*
This is part of datacrate, a node.js library for working with
DataCrates. Copyright (C) 2018 University of Technology Sydney
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const CONTEXT = { };
/* Convert metadata from a redbox data publication and
its data record to a JSON-LD datacrate catalogue */
// TODO; add contentSize, encodingFormat and fileFormat
// from siegfried to the dataLocations array
// org is the organisation as an array with keys @id
// and name:
// {
// "@id": "https://www.uts.edu.au/"
// "name": "University of Technology Sydney",
// }
function datapub2catalog(datapub, org) {
const catalog = {
'@context': CONTEXT,
'@graph': []
};
const organisation = {
'@id': org['@id'],
'@type': 'Organization',
'identifier': org['@id'],
'name': org['name']
};
// assuming that all creators are affiliated to this one organisation
const people = creators(datapub, organisation);
const files = files(datapub);
const graph = [
dataset(datapub, files, organisation),
organisation,
funding(datarec, datapub),
about(datapub),
spatial(datapub),
temporal(datapub),
creators,
licence(datapub),
citation(datapub),
files,
related(datapub)
];
catalog['@graph'] = graph.filter((e) => e);
return catalog;
}
function dataset(datapub, files) {
}
// files(datapub)
// crosswalk dataLocations to an array of File items.
// The dataLocations are expected to have contentSize,
// encodingFormat and fileFormat already set
function files(datapub) {
if( !datapub['dataLocations'] ) {
return [];
}
const files = datapub['dataLocations'].map((dl) => {
if( dl['type'] == 'attachment' ) {
return {
'@id': dl['name'],
'name': dl['name'],
'@type': 'File',
'contentSize': dl['contentSize'],
'encodingFormat': dl['encodingFormat'],
'fileFormat': dl['fileFormat']
}
} else {
// todo: URLs and physical locations
return undefined;
}
});
return files.filter((x) => x);
}
// creators(datapub)
//
// returns the array of Person items from the creators
// field of the data publication
// TODO: affiliations
function creators(datapub, organisation) {
if( !datapub['creators'] ) {
throw Error("A DataCrate has to have at least one creator");
}
const creators = datapub['creators'].map((p) => {
const id = p['orcid'] || p['email'] || p['text_full_name'];
return {
'@id': id,
'identifier': id,
'name': p['text_full_name'],
'familyName': p['family_name'],
'givenName': p['given_name'],
'email': p['email'],
'affiliation': { '@id': org_id }
}
})
return creators.filter((x) => x)
}
function funding(datarec, datapub) {
return undefined;
}
function about(datapub) {
return undefined;
}
function spatial(datapub) {
return undefined;
}
function temporal(datapub) {
return undefined;
}
function licence(datapub) {
return undefined;
}
function citation(datapub) {
return undefined;
}
function related(datapub) {
return undefined;
}
module.exports = {
'datapub2catalog': datapub2catalog
};
{
"name": "datacrate",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"browser-stdout": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz",
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw=="
},
"commander": {
"version": "2.15.1",
"resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
"integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag=="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"diff": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA=="
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
},
"fs-extra": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.0.tgz",
"integrity": "sha512-EglNDLRpmaTWiD/qraZn6HREAEAHJcJOmxNEYwq6xeMKnVMAy3GUcFB+wXt2C6k4CNvB/mP1y/U3dzvKKj5OtQ==",
"requires": {
"graceful-fs": "^4.1.2",
"jsonfile": "^4.0.0",
"universalify": "^0.1.0"
}
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"graceful-fs": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
},
"growl": {
"version": "1.10.5",
"resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz",
"integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA=="
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"he": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0="
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"jsonfile": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"requires": {
"graceful-fs": "^4.1.6"
}
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
},
"mkdirp": {
"version": "0.5.1",
"resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": {
"minimist": "0.0.8"
}
},
"mocha": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz",
"integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==",
"requires": {
"browser-stdout": "1.3.1",
"commander": "2.15.1",
"debug": "3.1.0",
"diff": "3.5.0",
"escape-string-regexp": "1.0.5",
"glob": "7.1.2",
"growl": "1.10.5",
"he": "1.1.1",
"minimatch": "3.0.4",
"mkdirp": "0.5.1",
"supports-color": "5.4.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"supports-color": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",
"integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==",
"requires": {
"has-flag": "^3.0.0"
}
},
"universalify": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz",
"integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}
}
}
......@@ -4,7 +4,7 @@
"description": "utilities for building and manipulating DataCrate data packages",
"main": "index.js",
"scripts": {
"test": "./node_modules/mocha/bin/mocha"
"test": "./node_modules/mocha/bin/mocha ./**/*spec.js"
},
"keywords": [
"datacrate",
......@@ -12,5 +12,11 @@
],
"author": "Mike Lynch",
"license": "GPL-3.0",
"repository": "https://code.research.uts.edu.au/eresearch/datacrate"
"repository": "https://code.research.uts.edu.au/eresearch/datacrate",
"dependencies": {
"fs-extra": "^7.0.0"
},
"devDependencies": {
"mocha": "^5.2.0"
}
}
/*
This is part of datacrate, a node.js library for working with
DataCrates. Copyright (C) 2018 University of Technology Sydney
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const catalog = require('../lib/catalog.js');
const fs = require('fs-extra');
const ORG = {
'@id': 'https://www.uts.edu.au',
'name': 'University of Technology Sydney'
};
describe("ReDBox data publication to DataCrate catalog.json", () => {
it("Can run at all ", async () => {
const dp = fs.readJson('../test/datapub.json');
const cj = catalog.datapub2catalog(dp, ORG);
assert(cj, "Got something back")
});
});
{
"parameterRetriever": "",
"dataRecordGetter": "",
"": {},
"dataRecord": {
"oid": "6a84b33c2d2db4be8a9804a5a570d734",
"title": "Test"
},
"title": "Test",
"description": "Test",
"dc:subject_anzsrc:toa_rdf:resource": "dataset",
"finalKeywords": [
"test"
],
"foaf:fundedBy_foaf:Agent": [
{}
],
"foaf:fundedBy_vivo:Grant": [
{}
],
"dc:subject_anzsrc:for": [],
"dc:subject_anzsrc:seo": [],
"startDate": "",
"endDate": "",
"timePeriod": "",
"geolocations": [
""
],
"geospatial": {},
"accessRightsToggle": "",
"dataLocations": [
{
"type": "attachment",
"location": "6a84b33c2d2db4be8a9804a5a570d734/attach/4d91abb2ffa496b2d3c78737fe74efcf",
"mimeType": "image/jpeg",
"name": "clyde_inception_3b_3x3.jpg",
"fileId": "4d91abb2ffa496b2d3c78737fe74efcf",
"uploadUrl": "http://localhost:1500/default/rdmp/record/6a84b33c2d2db4be8a9804a5a570d734/attach/4d91abb2ffa496b2d3c78737fe74efcf",
"selected": true
},
{
"type": "attachment",
"location": "6a84b33c2d2db4be8a9804a5a570d734/attach/792957fbdae8b70ee597908374dc14ad",
"mimeType": "image/jpeg",
"name": "clyde_inception_3b_3x3_reduce.jpg",
"fileId": "792957fbdae8b70ee597908374dc14ad",
"uploadUrl": "http://localhost:1500/default/rdmp/record/6a84b33c2d2db4be8a9804a5a570d734/attach/792957fbdae8b70ee597908374dc14ad",
"selected": true
}
],
"dataLicensingAccess_manager": "Local Admin",
"dc:accessRights": "Open",
"accessRights_url": "",
"related_publications": [
{
"related_title": "",
"related_url": "",
"related_notes": ""
}
],
"related_websites": [
{
"related_title": "",
"related_url": "",
"related_notes": ""
}
],
"related_metadata": [
{
"related_title": "",
"related_url": "",
"related_notes": ""
}
],
"related_data": [
{
"related_title": "",
"related_url": "",
"related_notes": ""
}
],
"related_services": [
{
"related_title": "",
"related_url": "",
"related_notes": ""
}
],
"license_identifier": "",
"license_notes": "",
"license_other_url": "",
"license_statement": "Copyright ReDBox Research Data 2018",
"license_statement_url": "",
"citation_doi": "",
"requestIdentifier": [],
"citation_title": "Test dataset",
"creators": [
{
"text_full_name": "Michael Lynch",
"email": "Michael.Lynch@uts.edu.au",
"role": "Chief Investigator",
"username": "",
"orcid": "",
"family_name": "Lynch",
"given_name": "Michael"
},
{
"text_full_name": "Local Admin",
"email": "admin@redboxresearchdata.com.au",
"role": "Data manager",
"username": "admin",
"orcid": "",
"family_name": "Admin",
"given_name": "Local"
},
{
"role": "Contributors",
"username": "",
"orcid": "",
"family_name": "",
"given_name": ""
},
{
"role": "Supervisor",
"username": "",
"orcid": "",
"family_name": "",
"given_name": ""
}
],
"citation_publisher": "ReDBox Research Data",
"citation_url": "http://mikelynch.org/",
"citation_publication_date": "",
"citation_generated": "Lynch, Michael; Admin, Local; , ; , (Invalid date): Test dataset. ReDBox Research Data. {ID_WILL_BE_HERE}",
"dataowner_name": "Michael Lynch",
"dataowner_email": "Michael.Lynch@uts.edu.au",
"contributor_ci": {
"text_full_name": "Michael Lynch",
"full_name_honorific": "Dr Michael Lynch",
"email": "Michael.Lynch@uts.edu.au",
"given_name": "Michael",
"family_name": "Lynch",
"honorific": "Dr",
"full_name_family_name_first": "Lynch, Michael",
"username": "",
"role": "Chief Investigator"
},
"contributor_data_manager": {
"text_full_name": "Local Admin",
"full_name_honorific": "",
"email": "admin@redboxresearchdata.com.au",
"given_name": "Local",
"family_name": "Admin",
"honorific": "",
"full_name_family_name_first": "Admin, Local",
"username": "admin",
"role": "Data manager"
},
"contributor_supervisor": {
"full_name_honorific": "",
"given_name": "",
"family_name": "",
"honorific": "",
"full_name_family_name_first": "",
"username": "",
"role": "Supervisor"
},
"embargoByDate": "",
"embargoNote": "",
"reviewerNote": "",
"ckanLocation": ""
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment