Commit fc1c4291 authored by PTSEFTON's avatar PTSEFTON
Browse files

Tidying up test_data

parent 52a2ec9f
......@@ -174,6 +174,8 @@ if (program.generateHtml) {
"encodingFormat": "zip"
}
)
// Reinitialize the helper object as we have added to the JSON
json_helper.init(json_helper.json_ld);
}
json_helper.trim_context()
fs.writeFileSync(path.join(c.dir, defaults.catalog_json_file_name), JSON.stringify(json_helper.json_ld, null, 2 ))
......
......@@ -70,9 +70,7 @@ module.exports = function() {
item_json["TYPE:"] = "Dataset";
item_json["path"] = collection.rel_path;
if (!(collection.rel_path === "./")) {
//console.log("Setting dataset based on path");
item_json["ID"] = collection.rel_path;
//item_json["TYPE:"] = "Dataset";
} else if (!item_json["ID"]) {
item_json["ID"] = collection.rel_path;
}
......@@ -134,7 +132,7 @@ module.exports = function() {
},
index_graph: function index_graph() {
// TODO - PUT THIS IN A HELPER MODULE
// TODO - REMOVE this - we now have a helper for this stuff
this.item_by_id = {};
this.item_by_path = {};
this.item_by_type = {};
......
......@@ -21,7 +21,8 @@ var ejs = require("ejs");
context = require("../defaults/context.json");
const path = require("path");
const shell = require("shelljs");
const jsonld = require("jsonld");
const jsonld_helper = require("./jsonldhelper")
var helper = new jsonld_helper();
const filesize = require("filesize");
const display_keys = [
"name",
......@@ -77,7 +78,7 @@ module.exports = function () {
) {
// Item is the thing we're displaying
// K is for Key - ie the property name
// list is the list of values for propery k in item
// list is the list of values for property k in item
// details: bool - are we doing pagination? If so need to display the "details element"
var l = list.length;
var html = "";
......@@ -455,7 +456,15 @@ module.exports = function () {
//console.log("Processing dataset", node["@id"]);
var html = "";
var keys = new Set(Object.keys(node));
keys.delete("identifier");
if (node["identifier"]) {
node["identifier"] = helper.value_as_array(node["identifier"]).filter(id => id != node["@id"]);
if (node["identifier"].length === 0) {
keys.delete("identifier")
}
}
keys.delete("@id");
keys.delete("filename");
if (keys.has("encodingFormat")) {
......
......@@ -23,6 +23,11 @@ const context = require("../defaults/context.json");
const metadata_property_name = require("./property.js");
const uuidv4 = require("uuid/v4");
const ejs = require("ejs");
const jsonld = require("../lib/jsonldhelper.js");
const helper = new jsonld()
module.exports = function() {
this.metadata = {};
this.json_ld = {};
......@@ -113,7 +118,15 @@ module.exports = function() {
if (this.collection.bagged && frag.path) {
frag.path = path.join("data", frag.path);
}
var ident = helper.value_as_array(this.id)
for (let id of ident){
if (id && id.match(/(https?:\/\/)(dx\.)?(doi.org\/10\.)/i)) {
helper.push_value(frag, "identifier", id.replace(/https?:\/\//i, ""))
}
this.json_ld_fragment = frag;
}
//console.log(frag);
return frag;
},
......@@ -136,6 +149,10 @@ module.exports = function() {
//console.log("FILE ", this.collection.path, value);
this.id = path.join(this.collection.rel_path, value);
this.types.push("File");
var pr = new metadata_property_name();
pr.parse("path", this.id);
this.properties[pr.name] = pr;
this.is_file = value;
} else if (property.is_id) {
//console.log("Got an ID", value);
......
......@@ -87,14 +87,28 @@ module.exports = function () {
},
value_as_array: function (value) {
if (!Array.isArray(value)) {
if (!value) {
return []
}
else if (!Array.isArray(value)) {
return [value];
console.log("Making array", key, item[key])
} else {
return value;
}
},
push_value: function(item, key, value) {
if (item[key]) {
if (!Array.isArray(item[key])) {
item[key] = [item[key]]
}
item[key].push(value)
}
else {
item[key] = [value]
}
},
init: function init(json) {
this.json_ld = json;
this.item_by_id = {};
......
......@@ -66,6 +66,24 @@ describe("Create nested item", function() {
assert.equal(j1["creator"]["@id"], "http://orcid.org/0000-0002-3545-944X");
//assert(Object.is(c.collection_metadata, {} ));
t1.load_json(
{
"contactPoint>TYPE:ContactPoint>":
"Email: someone@somewhere.com"
},
new Collection()
);
assert.equal(t1.nested_items["contactPoint"].types[0], "ContactPoint");
assert.equal(
t1.nested_items["contactPoint"].name,
"Email: someone@somewhere.com"
);
j1 = t1.to_json_ld_fragment();
assert.equal(j1["contactPoint"]["@type"][0], "ContactPoint");
assert.equal(j1["contactPoint"]["email"], "someone@somewhere.com");
t1.load_json(
{
"geo>TYPE:GeoCoordinates>":
......@@ -87,6 +105,7 @@ describe("Create nested item", function() {
done();
});
});
describe("Create simple item", function() {
it("Should create an empty metadata set", function(done) {
var t1 = new Item();
......
Markdown is supported
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