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

Deposit now uses local ids which it adds back to the ro-crate-metadata.jsonld and

checks in.
Deposit looks for an existing local id before minting a new identifier
parent 7463e356
Branches
No related merge requests found
......@@ -17,7 +17,7 @@
"jsonld": "^1.6.2",
"nunjucks": "^3.2.0",
"ocfl": "^1.0.3",
"ro-crate": "^1.2.8",
"ro-crate": "^1.2.10",
"uuid": "^3.3.3",
"yargs": "^13.3.0"
}
......
......@@ -27,6 +27,39 @@ async function connectRepo(repoPath) {
}
async function checkin(repo, repoName, rocratePath) {
const rocrateFile = path.join(rocratePath, "ro-crate-metadata.jsonld");
try {
const jsonld = await fs.readJson(rocrateFile);
const crate = new ROCrate(jsonld);
crate.index();
const dataset = crate.getRootDataset();
console.log("Ingesting ro-crate " + dataset['name']);
const existingId = crate.getNamedIdentifier(repoName);
if( existingId ) {
console.log(`Local identifier found ${repoName}/${existingId}`);
await repo.importNewObjectDir(existingId, rocratePath);
console.log(`Updated ${existingId}`);
} else {
const newId = uuid();
console.log(`Minting new local identifier ${repoName}/${newId}`);
await repo.importNewObjectDir(newId, rocratePath);
console.log(`Imported ${rocratePath} ${dataset['name']} ${newId}`);
crate.addIdentifier({name: repoName, identifier: newId});
await fs.writeJson(rocrateFile, crate.getJson(), {spaces: 2});
await repo.importNewObjectDir(newId, rocratePath);
console.log(`Updated ${rocratePath} ${newId} metadata with identifier`);
}
} catch(e) {
console.log(`Error importing ${rocratePath}`);
console.log(e);
}
}
async function main() {
......@@ -35,22 +68,8 @@ async function main() {
const repo = await connectRepo(repoPath);
for (let fromPath of argv._) {
const rocrateFile = path.join(fromPath, "ro-crate-metadata.jsonld");
try {
const jsonld = await fs.readJson(rocrateFile);
crate = new ROCrate(jsonld);
crate.index();
const dataset = crate.getRootDataset();
const local_id = uuid();
crate.addIdentifier({name: repoName, identifier: local_id});
await fs.writeJson(crate.getJson(), rocrateFile);
const ocflObject = await repo.importNewObjectDir(local_id, fromPath);
console.log(`Imported ${fromPath} ${dataset['title']} ${local_id}`);
} catch(e) {
console.log(`Error importing ${fromPath}`);
console.log(e);
}
for (let rocratePath of argv._) {
await checkin(repo, repoName, rocratePath);
}
}
......
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