Skip to content

Commit

Permalink
Format JSON-LD export with arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristin committed Mar 13, 2019
1 parent 3228355 commit a44acdf
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/main/resources/c-adapter/ceasn/ceasn.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,41 @@ function orderFields(object) {
return object;
}

function conceptArrays(object) {
for (var k in object) {
if (EcObject.isObject(object[k]) == false)
if (k.indexOf("@") != 0)
if (k.indexOf("ceterms:ctid") != 0)
if (k.indexOf("ceasn:description") != 0)
if (k.indexOf("ceasn:name") != 0)
if (k.indexOf("ceasn:dateCopyrighted") != 0)
if (k.indexOf("ceasn:dateCreated") != 0)
if (k.indexOf("ceasn:dateModified") != 0)
if (k.indexOf("ceasn:license") != 0)
if (k.indexOf("ceasn:publicationStatusType") != 0)
if (k.indexOf("ceasn:publisher") != 0)
if (k.indexOf("ceasn:publisherName") != 0)
if (k.indexOf("ceasn:rights") != 0)
if (k.indexOf("ceasn:source") != 0)
if (k.indexOf("skos:broader") != 0)
if (k.indexOf("skos:definition") != 0)
if (k.indexOf("skos:inScheme") != 0)
if (k.indexOf("skos:notation") != 0)
if (k.indexOf("skos:prefLabel") != 0)
if (k.indexOf("skos:topConceptOf") != 0)
if (EcArray.isArray(object[k]) == false)
object[k] = [object[k]];
//For properties that allow many per language, force it into an array with even just 1 value.
if (k === "skos:changeNote" || k === "ceasn:conceptKeyword" || k === "skos:note" || k === "skos:hiddenLabel" || k === "skos:altLabel") {
Object.keys(object[k]).forEach(function (key) {
if (EcArray.isArray(object[k][key]) == false)
object[k][key] = [object[k][key]];
});
}
}
return orderFields(object);
}

function cassConceptSchemeAsCeasn(framework) {
if (framework == null)
error("Concept Scheme not found.", 404);
Expand Down Expand Up @@ -464,7 +499,7 @@ function cassConceptSchemeAsCeasn(framework) {
}
delete concepts[id]["@context"];

concepts[id] = orderFields(concepts[id]);
concepts[id] = conceptArrays(concepts[id]);
}

cs.context = "http://schema.cassproject.org/0.3/cass2ceasnConcepts";
Expand Down Expand Up @@ -493,7 +528,8 @@ function cassConceptSchemeAsCeasn(framework) {
cs["@id"] = ceasnExportUriTransform(cs["@id"]);

var results = [];
cs = orderFields(cs);

cs = conceptArrays(cs);
results.push(cs);
for (var k in concepts) {
var c = concepts[k];
Expand Down

0 comments on commit a44acdf

Please sign in to comment.