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

Now makes history actions (create and publish) and adds people items for

the agents of these who weren't already listed as creators
parent 546a622e
No related merge requests found
...@@ -18,28 +18,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -18,28 +18,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
const CONTEXT = './defaults/context.json'; const CONTEXT = './defaults/context.json';
fs = require('fs-extra'); const fs = require('fs-extra');
const _ = require('lodash');
/* Convert metadata from a redbox data publication and /* datapub2catalog(options)
its data record to a JSON-LD datacrate catalogue */
Convert metadata from a redbox data publication and
its data record to a JSON-LD datacrate catalogue
options = {
id: redbox oid,
datapub: redbox data publication record,
org: {
@id: organisation identifier,
name: organisation name
},
owner: email of the data pub's record,
approver: email of the librarian who approved publication
}
The owner and approver are used to build two Actions against
the object - creation and publication.
TODO; add contentSize, encodingFormat and fileFormat from
siegfried to the dataLocations array
Remember to keep the connection to the data record
*/
// 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",
// }
async function datapub2catalog(id, datapub, org) {
async function datapub2catalog(options) {
const id = options['id'];
const datapub = options['datapub'];
const org = options['organisation'];
const owner = options['owner'];
const approver = options['approver'];
const context = await fs.readJson(CONTEXT); const context = await fs.readJson(CONTEXT);
const catalog = { const catalog = {
'@context': context, '@context': context
'@graph': []
}; };
const organisation = { const organisation = {
...@@ -51,25 +74,36 @@ async function datapub2catalog(id, datapub, org) { ...@@ -51,25 +74,36 @@ async function datapub2catalog(id, datapub, org) {
// assuming that all creators are affiliated to this one organisation // assuming that all creators are affiliated to this one organisation
const people = creators(datapub, organisation); var people = make_creators(datapub, organisation);
const files = attachments(datapub);
const files = make_files(datapub);
const dataset = make_dataset(id, datapub, organisation, files);
const [ history, more_people ] = make_history(dataset, people, owner, approver);
if( more_people.length > 0 ) {
people = people.concat(more_people);
}
const graph = [ const graph = _.flatten([
dataset(id, datapub, organisation, files), dataset,
organisation, organisation,
funding(datapub), make_funding(datapub),
about(datapub), make_about(datapub),
spatial(datapub), make_spatial(datapub),
temporal(datapub), make_temporal(datapub),
people, people,
licence(datapub), make_licence(datapub),
citation(datapub), make_citation(datapub),
files, files,
related(datapub) make_related(datapub),
]; history
]);
catalog['@graph'] = graph.filter((e) => e); return {
return catalog; '@context': context,
'@graph': graph.filter((e) => e)
};
} }
...@@ -77,8 +111,9 @@ function link_id(item) { ...@@ -77,8 +111,9 @@ function link_id(item) {
return { '@id': item['@id'] }; return { '@id': item['@id'] };
} }
// TODO: isBasedOn the data record
function dataset(id, datapub, organisation, files) { function make_dataset(id, datapub, organisation, files) {
return { return {
'@id': id, '@id': id,
'type': 'Dataset', 'type': 'Dataset',
...@@ -86,11 +121,58 @@ function dataset(id, datapub, organisation, files) { ...@@ -86,11 +121,58 @@ function dataset(id, datapub, organisation, files) {
'description': datapub['description'], 'description': datapub['description'],
'Publisher': link_id(organisation), 'Publisher': link_id(organisation),
'hasPart': files.map(link_id), 'hasPart': files.map(link_id),
} }
} }
function find_by_email(people, email) {
const match = people.filter((x) => x['email'] == email);
if( match.length ) {
return match[0];
} else {
return undefined;
}
}
function make_history(dataset, people, owner, approver) {
var owner_item = find_by_email(people, owner);
var approver_item = find_by_email(people, approver);
const new_people = []
if( !owner_item ) {
owner_item = {
'@id': owner,
'email': owner
};
new_people.push(owner_item)
}
if( !approver_item ) {
approver_item = {
'@id': approver,
'email': approver
};
new_people.push(approver_item)
}
// TODO: descriptions for these and maybe a link to the
// data record for the CreateAction
const history = [
{
'@id': dataset['@id'] + '_h0',
'@type': 'CreateAction',
'name': 'Create',
'object': link_id(dataset),
'agent': link_id(owner_item),
'startTime': 'yyyy-mm-dd'
},
{
'@id': dataset['@id'] + '_h1',
'@type': 'UpdateAction',
'name': 'Publish',
'object': link_id(dataset),
'agent': link_id(approver_item),
'startTime': 'yyyy-mm-dd'
}
];
return [ history, new_people ];
}
// files(datapub) // files(datapub)
...@@ -99,7 +181,7 @@ function dataset(id, datapub, organisation, files) { ...@@ -99,7 +181,7 @@ function dataset(id, datapub, organisation, files) {
// The dataLocations are expected to have contentSize, // The dataLocations are expected to have contentSize,
// encodingFormat and fileFormat already set // encodingFormat and fileFormat already set
function attachments(datapub) { function make_files(datapub) {
if( !datapub['dataLocations'] ) { if( !datapub['dataLocations'] ) {
return []; return [];
} }
...@@ -128,7 +210,7 @@ function attachments(datapub) { ...@@ -128,7 +210,7 @@ function attachments(datapub) {
// TODO: affiliations // TODO: affiliations
function creators(datapub, organisation) { function make_creators(datapub, organisation) {
if( !datapub['creators'] ) { if( !datapub['creators'] ) {
throw Error("A DataCrate has to have at least one creator"); throw Error("A DataCrate has to have at least one creator");
} }
...@@ -149,37 +231,38 @@ function creators(datapub, organisation) { ...@@ -149,37 +231,38 @@ function creators(datapub, organisation) {
return undefined; return undefined;
} }
}) })
console.log("make_creators " + typeof(creators));
return creators.filter((x) => x) const nc = creators.filter((x) => x)
console.log("make_creators " + typeof(nc));
return nc;
} }
function funding(datapub) { function make_funding(datapub) {
return undefined; return undefined;
} }
function about(datapub) { function make_about(datapub) {
return undefined; return undefined;
} }
function spatial(datapub) { function make_spatial(datapub) {
return undefined; return undefined;
} }
function temporal(datapub) { function make_temporal(datapub) {
return undefined; return undefined;
} }
function licence(datapub) { function make_licence(datapub) {
return undefined; return undefined;
} }
function citation(datapub) { function make_citation(datapub) {
return undefined; return undefined;
} }
function related(datapub) { function make_related(datapub) {
return undefined; return undefined;
} }
......
...@@ -405,6 +405,11 @@ ...@@ -405,6 +405,11 @@
"verror": "1.10.0" "verror": "1.10.0"
} }
}, },
"lodash": {
"version": "4.17.11",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
},
"mime-db": { "mime-db": {
"version": "1.36.0", "version": "1.36.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.36.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.36.0.tgz",
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
"repository": "https://code.research.uts.edu.au/eresearch/datacrate", "repository": "https://code.research.uts.edu.au/eresearch/datacrate",
"dependencies": { "dependencies": {
"fs-extra": "^7.0.0", "fs-extra": "^7.0.0",
"jsonld": "^1.1.0" "jsonld": "^1.1.0",
"lodash": "^4.17.11"
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.1.2", "chai": "^4.1.2",
......
...@@ -34,14 +34,23 @@ const ORG = { ...@@ -34,14 +34,23 @@ const ORG = {
'name': 'University of Technology Sydney' 'name': 'University of Technology Sydney'
}; };
const OWNER = 'Michael.Lynch@uts.edu.au';
const APPROVER = 'data.librarian@uts.edu.au';
const DATASET_ID = 'https://data.research.uts.edu.au/public/XYZ'; const DATASET_ID = 'https://data.research.uts.edu.au/public/XYZ';
describe("ReDBox data publication to DataCrate catalog.json", () => { describe("ReDBox data publication to DataCrate catalog.json", () => {
it("Can run at all ", async () => { it("Can run at all ", async () => {
const dp = await fs.readJson('./test_data/datapub.json'); const dp = await fs.readJson('./test_data/datapub.json');
const cj = await catalog.datapub2catalog(DATASET_ID, dp, ORG); const cj = await catalog.datapub2catalog({
console.log(JSON.stringify(cj, null, 2)); '@id': DATASET_ID,
'datapub': dp,
'organisation': ORG,
'owner': OWNER,
'approver': APPROVER
});
console.log(JSON.stringify(cj['@graph'], null, 2));
assert(cj, "Got something back") assert(cj, "Got something back")
}); });
......
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