From 0a363c6c99bd3401beddbc2da3751ee76d3a2999 Mon Sep 17 00:00:00 2001 From: Fritz Ray Date: Tue, 29 Oct 2024 10:55:02 -0700 Subject: [PATCH] WIP Sonar --- src/main/server/adapter/asn/asn.js | 591 ++++++----- src/main/server/adapter/case/caseAdapter.js | 14 +- src/main/server/adapter/ce/pna.js | 39 +- src/main/server/adapter/ceasn/ceasn.js | 928 +++++++++--------- .../server/adapter/openbadges/openbadges.js | 3 - src/main/server/profile/calculator.js | 4 +- .../profile/coprocessors/timeBounding.js | 58 +- src/main/server/shims/cassproject.js | 98 +- src/main/server/shims/levr.js | 48 +- src/main/server/skyRepo.js | 6 +- src/main/server/skyRepo.test.js | 2 +- 11 files changed, 886 insertions(+), 905 deletions(-) diff --git a/src/main/server/adapter/asn/asn.js b/src/main/server/adapter/asn/asn.js index 9eb4b0aa5..a512c87c1 100644 --- a/src/main/server/adapter/asn/asn.js +++ b/src/main/server/adapter/asn/asn.js @@ -18,13 +18,10 @@ var asnContext = { //asnContext["@vocab"] = "http://schema.cassproject.org/0.2/cass2asn"; async function cassFrameworkAsAsn() { - EcRepository.cache = new Object(); - - if (false && repoEndpoint().contains("localhost")) - error("Endpoint Configuration is not set.", 500); - var query = queryParse.call(this); - var framework = null; - const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2asnTerms")),true)); + EcRepository.cache = {}; + let query = queryParse.call(this); + let framework = null; + const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2asnTerms")), true)); if (framework == null) framework = await skyrepoGet.call(this, query); if (framework == null || framework["@type"] == null || !framework["@type"].contains("ramework")) @@ -59,24 +56,24 @@ async function cassFrameworkAsAsn() { if (framework == null) error("Framework not found.", "404"); - var f = new EcFramework(); + let f = new EcFramework(); f.copyFrom(framework); if (f.competency === undefined || f.competency == null) f.competency = []; if (f.relation === undefined || f.relation == null) f.relation = []; - var ids = []; + let ids = []; ids = ids.concat(f.competency); ids = ids.concat(f.relation); repo.precache(ids, function (results) { }); - var allCompetencies = JSON.parse(JSON.stringify(f.competency)); - var competencies = {}; - var topLevelCompIds = [] + let allCompetencies = JSON.parse(JSON.stringify(f.competency)); + let competencies = {}; + let topLevelCompIds = [] if (f.competency != null) - for (var i = 0; i < f.competency.length; i++) { - var c = await loopback.competencyGet(f.competency[i]); + for (let i = 0; i < f.competency.length; i++) { + let c = await loopback.competencyGet(f.competency[i]); if (c == null) continue; competencies[f.competency[i]] = c; if (competencies[f.competency[i]] == null) @@ -84,10 +81,10 @@ async function cassFrameworkAsAsn() { } if (f.relation != null) - for (var i = 0; i < f.relation.length; i++) { + for (let i = 0; i < f.relation.length; i++) { //Workaround due to bug in 1.3.0 if (await loopback.repositoryGet(f.relation[i]) == null) continue; - var r = await loopback.alignmentGet(f.relation[i]); + let r = await loopback.alignmentGet(f.relation[i]); if (r.source == null || r.target == null) continue; if (r.relationType == Relation.NARROWS) { EcArray.setRemove(f.competency, r.source); @@ -165,8 +162,8 @@ async function cassFrameworkAsAsn() { } let toSerialize = []; - for (var i = 0; i < allCompetencies.length; i++) { - var c = competencies[allCompetencies[i]]; + for (let i = 0; i < allCompetencies.length; i++) { + let c = competencies[allCompetencies[i]]; delete competencies[allCompetencies[i]]; if (c == null) continue; c.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2asn.json"; @@ -189,7 +186,7 @@ async function cassFrameworkAsAsn() { delete f.relation; for (let each in f) { if (terms[each]) { - f[terms[each]] = f[each]; + f[terms[each]] = f[each]; delete f[each]; } if (each === "type") { @@ -202,152 +199,149 @@ async function cassFrameworkAsAsn() { return competencies; } -/** - * - * @param jsonLd - * @returns - */ -function fixScalars(jsonLd) { - var JSONLD_VALUE = "@value"; - var JSONLD_ID = "@id"; - var JSONLD_TYPE = "@type"; - var JSONLD_LANG = "@language"; - - if (jsonLd === Object(jsonLd)) { - for (var key in jsonLd) { - try { - var field = jsonLd[key]; - if (Array.isArray(field)) { - var flattenText = true; - var textArray = []; - var langArray = []; - for (var idx in field) { - var obj = field[idx]; - - if (obj === Object(obj)) { - if (obj["type"] != undefined) { - if (obj["type"] == "uri") { - if (obj["value"] != undefined && obj[JSONLD_ID] == undefined) { - obj[JSONLD_ID] = obj["value"]; - delete obj["value"]; - } - } else { - if (obj["value"] != undefined && obj[JSONLD_VALUE] == undefined) { - obj[JSONLD_VALUE] = obj["value"]; - delete obj["value"]; - } - } - - delete obj["type"]; - } - if (obj["datatype"] != undefined && obj[JSONLD_TYPE] == undefined) { - obj[JSONLD_TYPE] = obj["datatype"]; - delete obj["datatype"]; - } - if (obj["lang"] != undefined && obj[JSONLD_LANG] == undefined) { - obj[JSONLD_LANG] = obj["lang"]; - delete obj["lang"]; - - } - - field[idx] = obj; - } - } - - } else if (field === Object(field)) { - var keepGoing = true; - - - if (field["type"] != undefined) { - if (field["type"] == "uri") { - if (field["value"] != undefined && field[JSONLD_ID] == undefined) { - field[JSONLD_ID] = field["value"]; - delete field["value"]; - keepGoing = false; - } - } else { - if (field["value"] != undefined && field[JSONLD_VALUE] == undefined) { - field[JSONLD_VALUE] = field["value"]; - delete field["value"]; - keepGoing = false; - } - } - - delete field["type"]; - keepGoing = false; - } - if (field["datatype"] != undefined && field[JSONLD_TYPE] == undefined) { - field[JSONLD_TYPE] = field["datatype"]; - delete field["datatype"]; - keepGoing = false; - } - if (field["lang"] != undefined && field[JSONLD_LANG] == undefined) { - field[JSONLD_LANG] = field["lang"]; - delete field["lang"]; - - keepGoing = false; - } - - if (keepGoing) { - field = fixScalars(field); - } - } - - jsonLd[key] = field; - } catch (exception) { - error("Exception when fixing json-ld scalars " + exception.message) - } - } - } - return jsonLd; -} +// /** +// * +// * @param jsonLd +// * @returns +// */ +// function fixScalars(jsonLd) { +// var JSONLD_VALUE = "@value"; +// var JSONLD_ID = "@id"; +// var JSONLD_TYPE = "@type"; +// var JSONLD_LANG = "@language"; + +// if (jsonLd === Object(jsonLd)) { +// for (let key in jsonLd) { +// try { +// let field = jsonLd[key]; +// if (Array.isArray(field)) { +// let flattenText = true; +// let textArray = []; +// let langArray = []; +// for (let idx in field) { +// let obj = field[idx]; + +// if (obj === Object(obj)) { +// if (obj["type"] != undefined) { +// if (obj["type"] == "uri") { +// if (obj["value"] != undefined && obj[JSONLD_ID] == undefined) { +// obj[JSONLD_ID] = obj["value"]; +// delete obj["value"]; +// } +// } else { +// if (obj["value"] != undefined && obj[JSONLD_VALUE] == undefined) { +// obj[JSONLD_VALUE] = obj["value"]; +// delete obj["value"]; +// } +// } + +// delete obj["type"]; +// } +// if (obj["datatype"] != undefined && obj[JSONLD_TYPE] == undefined) { +// obj[JSONLD_TYPE] = obj["datatype"]; +// delete obj["datatype"]; +// } +// if (obj["lang"] != undefined && obj[JSONLD_LANG] == undefined) { +// obj[JSONLD_LANG] = obj["lang"]; +// delete obj["lang"]; + +// } + +// field[idx] = obj; +// } +// } + +// } else if (field === Object(field)) { +// let keepGoing = true; + + +// if (field["type"] != undefined) { +// if (field["type"] == "uri") { +// if (field["value"] != undefined && field[JSONLD_ID] == undefined) { +// field[JSONLD_ID] = field["value"]; +// delete field["value"]; +// keepGoing = false; +// } +// } else { +// if (field["value"] != undefined && field[JSONLD_VALUE] == undefined) { +// field[JSONLD_VALUE] = field["value"]; +// delete field["value"]; +// keepGoing = false; +// } +// } + +// delete field["type"]; +// keepGoing = false; +// } +// if (field["datatype"] != undefined && field[JSONLD_TYPE] == undefined) { +// field[JSONLD_TYPE] = field["datatype"]; +// delete field["datatype"]; +// keepGoing = false; +// } +// if (field["lang"] != undefined && field[JSONLD_LANG] == undefined) { +// field[JSONLD_LANG] = field["lang"]; +// delete field["lang"]; + +// keepGoing = false; +// } + +// if (keepGoing) { +// field = fixScalars(field); +// } +// } + +// jsonLd[key] = field; +// } catch (exception) { +// error("Exception when fixing json-ld scalars " + exception.message) +// } +// } +// } +// return jsonLd; +// } /** * */ async function importFrameworkToCass(frameworkObj, competencyList) { - var asnIdentity = new EcIdentity(); + let asnIdentity = new EcIdentity(); asnIdentity.ppk = EcPpk.fromPem(keyFor("adapter.asn.private")); asnIdentity.displayName = "ASN Server Identity"; EcIdentityManager.default.addIdentity(asnIdentity); - if (false && repoEndpoint().contains("localhost")) - error("Endpoint Configuration is not set.", 500); - - var asnToCassFrameworkContext = JSON.parse(JSON.stringify(asnContext)); + let asnToCassFrameworkContext = JSON.parse(JSON.stringify(asnContext)); asnToCassFrameworkContext["@vocab"] = "https://schema.cassproject.org/0.4/"; asnToCassFrameworkContext["asn:StandardDocument"] = "https://schema.cassproject.org/0.4/Framework"; asnToCassFrameworkContext["dc:title"] = "http://schema.org/name"; asnToCassFrameworkContext["dcterms:description"] = "http://schema.org/description"; asnToCassFrameworkContext["sameAs"] = "http://schema.org/sameAs"; - var asnToCassCompetencyContext = JSON.parse(JSON.stringify(asnContext)); + let asnToCassCompetencyContext = JSON.parse(JSON.stringify(asnContext)); asnToCassCompetencyContext["asn:Statement"] = "https://schema.cassproject.org/0.4/Competency"; asnToCassCompetencyContext["dcterms:description"] = "http://schema.org/name"; asnToCassCompetencyContext["sameAs"] = "http://schema.org/sameAs"; - var cassCompetencies = []; - var cassRelationships = []; - var relationshipMap = {}; - var parentMap = {}; + let cassCompetencies = []; + let cassRelationships = []; + let relationshipMap = {}; + let parentMap = {}; - for (var idx in competencyList) { - var asnComp = competencyList[idx]; + for (let idx in competencyList) { + let asnComp = competencyList[idx]; - var compGuid = EcCrypto.md5(asnComp["@id"]); + let compGuid = EcCrypto.md5(asnComp["@id"]); print(compGuid); - var compVersion = date(null, null, true); + let compVersion = date(null, null, true); - var canonicalId = asnComp["@id"]; + let canonicalId = asnComp["@id"]; cassCompetencies.push(canonicalId); - var childComps = asnComp["gemq:hasChild"]; + let childComps = asnComp["gemq:hasChild"]; if (childComps != undefined && childComps.length != undefined) { - for (var idx in childComps) { - var r = new EcAlignment(); - r.source = childComps[idx]["@id"]; + for (let idx2 in childComps) { + let r = new EcAlignment(); + r.source = childComps[idx2]["@id"]; r.target = canonicalId; r.relationType = Relation.NARROWS; r.generateId(repoEndpoint()); @@ -361,18 +355,18 @@ async function importFrameworkToCass(frameworkObj, competencyList) { } } - var newComp = JSON.parse(JSON.stringify(asnComp)); + let newComp = JSON.parse(JSON.stringify(asnComp)); delete newComp["gemq:hasChild"]; newComp["@context"] = asnToCassCompetencyContext; - var expandedComp = await jsonLdExpand(JSON.stringify(newComp)); + let expandedComp = await jsonLdExpand(JSON.stringify(newComp)); - var compactedComp = await jsonLdCompact(JSON.stringify(expandedComp), "https://schema.cassproject.org/0.4"); + let compactedComp = await jsonLdCompact(JSON.stringify(expandedComp), "https://schema.cassproject.org/0.4"); delete compactedComp["gemq:isChildOf"]; - var c = new EcCompetency(); + let c = new EcCompetency(); c.copyFrom(compactedComp); c.addOwner(asnIdentity.ppk.toPk()); EcIdentityManager.default.sign(c); @@ -385,9 +379,9 @@ async function importFrameworkToCass(frameworkObj, competencyList) { }); if (asnComp["gemq:isChildOf"] != undefined && asnComp["gemq:isChildOf"] != "") { - var parentId = asnComp["gemq:isChildOf"]["@id"]; + let parentId = asnComp["gemq:isChildOf"]["@id"]; if (parentId != frameworkObj["@id"]) { - var r = new EcAlignment(); + let r = new EcAlignment(); r.source = compactedComp["@id"]; r.target = parentId; @@ -405,21 +399,21 @@ async function importFrameworkToCass(frameworkObj, competencyList) { } // end for each competency in competencyList if (frameworkObj != null) { - var guid = EcCrypto.md5(frameworkObj["@id"]); - var version = date(null, null, true); + let guid = EcCrypto.md5(frameworkObj["@id"]); + let version = date(null, null, true); frameworkObj["@context"] = asnToCassFrameworkContext; - var expanded = (await jsonLdExpand(JSON.stringify(frameworkObj)))[0]; + let expanded = (await jsonLdExpand(JSON.stringify(frameworkObj)))[0]; - var compacted = await jsonLdCompact(JSON.stringify(expanded), "https://schema.cassproject.org/0.4/"); + let compacted = await jsonLdCompact(JSON.stringify(expanded), "https://schema.cassproject.org/0.4/"); delete compacted["gemq:hasChild"]; compacted["competency"] = cassCompetencies; compacted["relation"] = cassRelationships; - var f = new EcFramework(); + let f = new EcFramework(); f.copyFrom(compacted); f.addOwner(asnIdentity.ppk.toPk()); EcIdentityManager.default.sign(f); @@ -440,14 +434,14 @@ async function importFrameworkToCass(frameworkObj, competencyList) { */ function asnFrameworkToCass() { - var jsonLd, text; + let jsonLd, text; - var file = getFileFromPost.call(this); + let file = getFileFromPost.call(this); if (file == undefined || file == null) { error("Unable to find ASN to Convert"); } else if (file.length != undefined) { - var data = getFileFromPost.call(this, "data"); + let data = getFileFromPost.call(this, "data"); if (data != undefined && data != null) { text = fileToString(data); } else { @@ -464,14 +458,14 @@ function asnFrameworkToCass() { jsonLd = rdfToJsonLd(text); } - var frameworkObj = undefined; - var competencyList = []; + let frameworkObj = undefined; + let competencyList = []; if (jsonLd["@graph"] != undefined && jsonLd["@graph"] != "") { - var graph = jsonLd["@graph"]; + let graph = jsonLd["@graph"]; - for (var idx in graph) { - var graphObj = graph[idx]; + for (let idx in graph) { + let graphObj = graph[idx]; if (graphObj["@type"] == "asn:StandardDocument") { frameworkObj = graphObj; @@ -501,156 +495,153 @@ if (!global.importJsonLdGraph) { } async function importConceptPromise(graphObj, conceptSchemeId, context, skosIdentity, owner, toSave) { - return new Promise(async (resolve) => { - try { - let compacted; - - if (context != undefined) { - const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cassConceptsTerms")),true)); - if (context == "http://credreg.net/ctdlasn/schema/context/json" || context == "http://credreg.net/ctdl/schema/context/json" - || context == "https://credreg.net/ctdlasn/schema/context/json" || context == "https://credreg.net/ctdl/schema/context/json") { - context = "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cassConcepts.json"; - for (let each in graphObj) { - if (terms[each]) { - graphObj[terms[each]] = graphObj[each]; - delete graphObj[each]; - } + try { + let compacted; + + if (context != undefined) { + const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cassConceptsTerms")), true)); + if (context == "http://credreg.net/ctdlasn/schema/context/json" || context == "http://credreg.net/ctdl/schema/context/json" || + context == "https://credreg.net/ctdlasn/schema/context/json" || context == "https://credreg.net/ctdl/schema/context/json") { + context = "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cassConcepts.json"; + for (let each in graphObj) { + if (terms[each]) { + graphObj[terms[each]] = graphObj[each]; + delete graphObj[each]; } } - if (context["schema"] == undefined) { - context["schema"] = "http://schema.org"; - } + } + if (context["schema"] == undefined) { + context["schema"] = "http://schema.org"; + } - graphObj["@context"] = context; + graphObj["@context"] = context; - if (graphObj["rdfs:comment"] != null && graphObj["rdfs:comment"] !== undefined) { - delete graphObj["dct:description"]; - delete graphObj["dcterms:description"]; - } + if (graphObj["rdfs:comment"] != null && graphObj["rdfs:comment"] !== undefined) { + delete graphObj["dct:description"]; + delete graphObj["dcterms:description"]; + } - var expanded = (await jsonLdExpand(JSON.stringify(graphObj)))[0]; - let url; - if (graphObj["@type"].indexOf("Concept") != -1) { - url = "https://schema.cassproject.org/0.4/skos/"; - } - else { - url = "https://schema.cassproject.org/0.4/"; + var expanded = (await jsonLdExpand(JSON.stringify(graphObj)))[0]; + let url; + if (graphObj["@type"].indexOf("Concept") != -1) { + url = "https://schema.cassproject.org/0.4/skos/"; + } else { + url = "https://schema.cassproject.org/0.4/"; + } + let compacted = await jsonLdCompact(JSON.stringify(expanded), url); + const type = compacted["@type"] + + if ((type == "skos:ConceptScheme") || (type == "asn:ProgressionModel")) { + compacted["@type"] = "ConceptScheme"; + compacted["@context"] = "https://schema.cassproject.org/0.4/skos/"; + if (type == "asn:ProgressionModel") { + compacted["subType"] = "Progression"; } - let compacted = await jsonLdCompact(JSON.stringify(expanded), url); - const type = compacted["@type"] - - if ((type == "skos:ConceptScheme") || (type == "asn:ProgressionModel")) { - compacted["@type"] = "ConceptScheme"; - compacted["@context"] = "https://schema.cassproject.org/0.4/skos/"; - if (type == "asn:ProgressionModel") { - compacted["subType"] = "Progression"; + let objToSave = new EcConceptScheme(); + objToSave.copyFrom(compacted); + conceptSchemeId.push(objToSave.shortId()); + objToSave.addOwner(skosIdentity.ppk.toPk()); + if (owner != null) + objToSave.addOwner(EcPk.fromPem(owner)); + + if (objToSave["dcterms:language"] == null || objToSave["dcterms:language"] === undefined) { + if (EcConceptScheme.template != null && EcConceptScheme.template["dcterms:language"] != null) { + objToSave["dcterms:language"] = EcConceptScheme.template["dcterms:language"]; } - let objToSave = new EcConceptScheme(); - objToSave.copyFrom(compacted); - conceptSchemeId.push(objToSave.shortId()); - objToSave.addOwner(skosIdentity.ppk.toPk()); - if (owner != null) - objToSave.addOwner(EcPk.fromPem(owner)); - - if (objToSave["dcterms:language"] == null || objToSave["dcterms:language"] === undefined) { - if (EcConceptScheme.template != null && EcConceptScheme.template["dcterms:language"] != null) { - objToSave["dcterms:language"] = EcConceptScheme.template["dcterms:language"]; - } - else { - objToSave["dcterms:language"] = "en"; - } - } - - if (objToSave["skos:hasTopConcept"] != null && !EcArray.isArray(objToSave["skos:hasTopConcept"])) { - objToSave["skos:hasTopConcept"] = [objToSave["skos:hasTopConcept"]]; + else { + objToSave["dcterms:language"] = "en"; } + } - if (objToSave["schema:dateCreated"] == null || objToSave["schema:dateCreated"] === undefined) { - var timestamp; - var date; - if (!objToSave.id.substring(objToSave.id.lastIndexOf("/")).matches("\\/[0-9]+")) { - timestamp = null; - } - else { - timestamp = objToSave.id.substring(objToSave.id.lastIndexOf("/")+1); - } - if (timestamp != null) { - date = new Date(parseInt(timestamp)).toISOString(); - } - else { - date = new Date().toISOString(); - } - objToSave["schema:dateCreated"] = date; - } - toSave.push(objToSave); - resolve(); + if (objToSave["skos:hasTopConcept"] != null && !EcArray.isArray(objToSave["skos:hasTopConcept"])) { + objToSave["skos:hasTopConcept"] = [objToSave["skos:hasTopConcept"]]; } - else if ((type == "skos:Concept") || (type == "asn:ProgressionLevel")) { - compacted["@type"] = "Concept"; - compacted["@context"] = "https://schema.cassproject.org/0.4/skos/"; - if (type == "asn:ProgressionLevel") { - compacted["subType"] = "Progression"; - } - let objToSave = new EcConcept(); - objToSave.copyFrom(compacted); - objToSave.addOwner(skosIdentity.ppk.toPk()); - if (owner != null) - objToSave.addOwner(EcPk.fromPem(owner)); - - if (objToSave["skos:narrower"] != null && !EcArray.isArray(objToSave["skos:narrower"])) { - objToSave["skos:narrower"] = [objToSave["skos:narrower"]]; + + if (objToSave["schema:dateCreated"] == null || objToSave["schema:dateCreated"] === undefined) { + var timestamp; + var date; + if (!objToSave.id.substring(objToSave.id.lastIndexOf("/")).matches("\\/[0-9]+")) { + timestamp = null; } - if (objToSave["skos:broader"] != null && !EcArray.isArray(objToSave["skos:broader"])) { - objToSave["skos:broader"] = [objToSave["skos:broader"]]; + else { + timestamp = objToSave.id.substring(objToSave.id.lastIndexOf("/") + 1); } - if (objToSave["skos:broadMatch"] != null && !EcArray.isArray(objToSave["skos:broadMatch"])) { - objToSave["skos:broadMatch"] = [objToSave["skos:broadMatch"]]; + if (timestamp != null) { + date = new Date(parseInt(timestamp)).toISOString(); } - if (objToSave["skos:closeMatch"] != null && !EcArray.isArray(objToSave["skos:closeMatch"])) { - objToSave["skos:closeMatch"] = [objToSave["skos:closeMatch"]]; + else { + date = new Date().toISOString(); } - if (objToSave["skos:exactMatch"] != null && !EcArray.isArray(objToSave["skos:exactMatch"])) { - objToSave["skos:exactMatch"] = [objToSave["skos:exactMatch"]]; + objToSave["schema:dateCreated"] = date; + } + toSave.push(objToSave); + resolve(); + } + else if ((type == "skos:Concept") || (type == "asn:ProgressionLevel")) { + compacted["@type"] = "Concept"; + compacted["@context"] = "https://schema.cassproject.org/0.4/skos/"; + if (type == "asn:ProgressionLevel") { + compacted["subType"] = "Progression"; + } + let objToSave = new EcConcept(); + objToSave.copyFrom(compacted); + objToSave.addOwner(skosIdentity.ppk.toPk()); + if (owner != null) + objToSave.addOwner(EcPk.fromPem(owner)); + + if (objToSave["skos:narrower"] != null && !EcArray.isArray(objToSave["skos:narrower"])) { + objToSave["skos:narrower"] = [objToSave["skos:narrower"]]; + } + if (objToSave["skos:broader"] != null && !EcArray.isArray(objToSave["skos:broader"])) { + objToSave["skos:broader"] = [objToSave["skos:broader"]]; + } + if (objToSave["skos:broadMatch"] != null && !EcArray.isArray(objToSave["skos:broadMatch"])) { + objToSave["skos:broadMatch"] = [objToSave["skos:broadMatch"]]; + } + if (objToSave["skos:closeMatch"] != null && !EcArray.isArray(objToSave["skos:closeMatch"])) { + objToSave["skos:closeMatch"] = [objToSave["skos:closeMatch"]]; + } + if (objToSave["skos:exactMatch"] != null && !EcArray.isArray(objToSave["skos:exactMatch"])) { + objToSave["skos:exactMatch"] = [objToSave["skos:exactMatch"]]; + } + if (objToSave["skos:narrowMatch"] != null && !EcArray.isArray(objToSave["skos:narrowMatch"])) { + objToSave["skos:narrowMatch"] = [objToSave["skos:narrowMatch"]]; + } + if (objToSave["skos:related"] != null && !EcArray.isArray(objToSave["skos:related"])) { + objToSave["skos:related"] = [objToSave["skos:related"]]; + } + + if (objToSave["schema:dateCreated"] == null || objToSave["schema:dateCreated"] === undefined) { + var timestamp; + var date; + if (!objToSave.id.substring(objToSave.id.lastIndexOf("/")).matches("\\/[0-9]+")) { + timestamp = null; } - if (objToSave["skos:narrowMatch"] != null && !EcArray.isArray(objToSave["skos:narrowMatch"])) { - objToSave["skos:narrowMatch"] = [objToSave["skos:narrowMatch"]]; + else { + timestamp = objToSave.id.substring(objToSave.id.lastIndexOf("/") + 1); } - if (objToSave["skos:related"] != null && !EcArray.isArray(objToSave["skos:related"])) { - objToSave["skos:related"] = [objToSave["skos:related"]]; + if (timestamp != null) { + date = new Date(parseInt(timestamp)).toISOString(); } - - if (objToSave["schema:dateCreated"] == null || objToSave["schema:dateCreated"] === undefined) { - var timestamp; - var date; - if (!objToSave.id.substring(objToSave.id.lastIndexOf("/")).matches("\\/[0-9]+")) { - timestamp = null; - } - else { - timestamp = objToSave.id.substring(objToSave.id.lastIndexOf("/")+1); - } - if (timestamp != null) { - date = new Date(parseInt(timestamp)).toISOString(); - } - else { - date = new Date().toISOString(); - } - objToSave["schema:dateCreated"] = date; + else { + date = new Date().toISOString(); } - toSave.push(objToSave); - resolve(); - } else { - global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "AsnImportConceptError", "Unrecognized type: " + type); - resolve(); + objToSave["schema:dateCreated"] = date; } + toSave.push(objToSave); + resolve(); } else { - global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "AsnImportConceptError", "Context not available"); + global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "AsnImportConceptError", "Unrecognized type: " + type); resolve(); } - } catch(err) { - global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "AsnImportConceptError", err); + } else { + global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "AsnImportConceptError", "Context not available"); resolve(); } - }); + } catch (err) { + global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "AsnImportConceptError", err); + resolve(); + } } async function importJsonLdGraph(graph, context) { @@ -670,12 +661,12 @@ async function importJsonLdGraph(graph, context) { return undefined; } global.auditLogger.report(global.auditLogger.LogCategory.NETWORK, global.auditLogger.Severity.INFO, "AsnImportJsonLdGraph", graph.length, graph); - for (let i = 0; i < graph.length; i+=100) { - await Promise.all(graph.slice(i, i+100).map((id) => importConceptPromise(id, conceptSchemeId, context, skosIdentity, owner, toSave))).catch((err) => { + for (let i = 0; i < graph.length; i += 100) { + await Promise.all(graph.slice(i, i + 100).map((id) => importConceptPromise(id, conceptSchemeId, context, skosIdentity, owner, toSave))).catch((err) => { global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "ImportJsonLdGraphErr", err); }); } - await repo.multiput(toSave, function() {}, (error) => { + await repo.multiput(toSave, function () { }, (error) => { global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "AsnImportJsonLdGraphError", error); }); if (conceptSchemeId && Array.isArray(conceptSchemeId) && conceptSchemeId.length > 0) { @@ -705,41 +696,41 @@ if (!global.disabledAdapters['asn']) { //function test(){ // var jsonLd; // var text = fileToString(fileLoad(this.params.path)); -// +// // try{ // jsonLd = JSON.parse(text); // }catch(e){ // debug("Not json") -// +// // jsonLd = rdfToJsonLd(text); // } -// +// // print(JSON.stringify(jsonLd)); -// +// // jsonLd = fixScalars(jsonLd); -// +// // print(JSON.stringify(jsonLd)); -// +// // for(var idx in jsonLd){ // var obj = jsonLd[idx]; -// +// // var context = JSON.parse(JSON.stringify(asnContext)); // context["type"] = "@type"; // context["uri"] = "@id"; -// +// // obj["@context"] = context; -// +// // if(obj["@id"] == undefined) // obj["@id"] = idx; -// +// // var expanded = jsonLdExpand(JSON.stringify(obj)); -// +// // //print(JSON.stringify(expanded)); -// +// // var graphObj = jsonLdCompact(JSON.stringify(expanded), "http://schema.cassproject.org/0.3/"); -// +// // print(JSON.stringify(graphObj)); -// +// // if(graphObj["rdf:type"] != undefined && graphObj["@type"] == undefined){ // //print(JSON.stringify(graphObj["rdf:type"])); // //print(Object.keys(graphObj["rdf:type"])); @@ -750,7 +741,7 @@ if (!global.disabledAdapters['asn']) { // } // delete graphObj["rdf:type"]; // } -// +// // if(graphObj["@type"] == "asn:StandardDocument"){ // frameworkObj = graphObj; // }else if (graphObj["@type"] == "asn:Statement" ){ diff --git a/src/main/server/adapter/case/caseAdapter.js b/src/main/server/adapter/case/caseAdapter.js index 6014379c4..129be485f 100644 --- a/src/main/server/adapter/case/caseAdapter.js +++ b/src/main/server/adapter/case/caseAdapter.js @@ -126,7 +126,7 @@ cfClean = function (o) { } var ordered = {}; - Object.keys(o).sort().forEach(function (key) { + Object.keys(o).sort().forEach(function (key) { // NOSONAR - Programmatic sort is necessary ordered[key] = o[key]; delete o[key]; }); @@ -137,12 +137,12 @@ cfClean = function (o) { } /*Errors: -400 - An invalid selection field was supplied and data filtering on the selection criteria was not possible i.e. 'invalid_selection_field'. This is accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. -401 - The request was not correctly authorised i.e. 'unauthorisedrequest'. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. -403 - This is used to indicate that the server can be reached and process the request but refuses to take any further action i.e. 'forbidden'. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. -404 - Either the supplied identifier is unknown in the Service Provider and so the object could not be changed or an invalid UUID has been supplied. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The statement 'Unknown Object' of 'Invalid UUID' should also be presented. The payload structure is defined by the structure imsx_StatusInfo.Type. -429 - The server is receiving too many requests i.e. 'server_busy'. Retry at a later time. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. -500 - This code should be used only if there is catastrophic error and there is not a more appropriate code i.e. 'internal_server_error'. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. + 400 - An invalid selection field was supplied and data filtering on the selection criteria was not possible i.e. 'invalid_selection_field'. This is accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. + 401 - The request was not correctly authorised i.e. 'unauthorisedrequest'. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. + 403 - This is used to indicate that the server can be reached and process the request but refuses to take any further action i.e. 'forbidden'. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. + 404 - Either the supplied identifier is unknown in the Service Provider and so the object could not be changed or an invalid UUID has been supplied. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The statement 'Unknown Object' of 'Invalid UUID' should also be presented. The payload structure is defined by the structure imsx_StatusInfo.Type. + 429 - The server is receiving too many requests i.e. 'server_busy'. Retry at a later time. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. + 500 - This code should be used only if there is catastrophic error and there is not a more appropriate code i.e. 'internal_server_error'. This would be accompanied by the 'codeMajor/severity' values of 'failure/error'. The payload structure is defined by the structure imsx_StatusInfo.Type. */ cfDocuments = async function (f, terms) { f = await cfGetFramework.call(this, f); diff --git a/src/main/server/adapter/ce/pna.js b/src/main/server/adapter/ce/pna.js index cf0ee2b71..68d247a0f 100644 --- a/src/main/server/adapter/ce/pna.js +++ b/src/main/server/adapter/ce/pna.js @@ -5,13 +5,10 @@ // https://docs.google.com/document/d/1w_0HDNIA9GZq76txOuS8e-OhmKJiHe9Azjuq1BfrxQ0/edit async function pnaEndpoint() { - - EcRepository.cache = new Object(); + EcRepository.cache = {}; EcRepository.caching = true; - if (false && repoEndpoint().contains("localhost")) - error("Endpoint Configuration is not set.", 500); - var query = queryParse.call(this); - var framework = null; + let query = queryParse.call(this); + let framework = null; if (framework == null) framework = await skyrepoGet.call(this, query); @@ -27,7 +24,7 @@ async function pnaEndpoint() { } // Data from the framework to be stored in Competency Explorer registry for indexing - let pnaData = new Object(); + let pnaData = {}; const now = new Date(); const formattedNow = now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate(); @@ -60,23 +57,24 @@ async function pnaEndpoint() { name: framework["name"], description: framework["description"], attributionName: attribution.startsWith('http') ? "" : attribution, - attributionURL: attribution.startsWith('http') ? attribution : "", + attributionURL: attribution.startsWith('http') ? attribution : "", beneficiaryRights: framework["ceasn:license"] ? framework["ceasn:license"] : (framework["schema:license"] ? framework["schema:license"] : ""), dataURL: ceasnEndpointFramework + query["id"], - providerMetaModel: process.env.PNA_PROVIDER_META_MODEL ?process.env. PNA_PROVIDER_META_MODEL : "", + providerMetaModel: process.env.PNA_PROVIDER_META_MODEL ? process.env.PNA_PROVIDER_META_MODEL : "", registryRights: process.env.PNA_REGISTRY_RIGHTS ? process.env.PNA_REGISTRY_RIGHTS : "", }; - + if (framework.competency == null) framework.competency = []; let competencies = []; const promises = []; - framework.competency.forEach(cid => { + framework.competency.forEach((cid) => { promises.push(EcRepository.get( - EcRemoteLinkedData.trimVersionFromUrl(cid), - null, - null, - repo).then((expanded) => { + EcRemoteLinkedData.trimVersionFromUrl(cid), + null, + null, + repo + ).then((expanded) => { if (expanded && expanded["id"]) { match = expanded["id"].match('(.*)(\/data\/)(.*)'); let ceasnEndpoint = match && match.length > 1 ? match[1] + "/ceasn/" : undefined; @@ -108,12 +106,11 @@ async function pnaEndpoint() { return JSON.stringify(result); } else { return JSON.stringify(pnaData); - } + } } async function uploadToAws(data, name) { - - const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3"); + const {S3Client, PutObjectCommand} = require("@aws-sdk/client-s3"); const AWS_REGION = process.env.PNA_AWS_REGION ? process.env.PNA_AWS_REGION : ""; const AWS_BUCKET = process.env.PNA_AWS_BUCKET ? process.env.PNA_AWS_BUCKET : ""; @@ -127,14 +124,14 @@ async function uploadToAws(data, name) { return { framework: undefined, success: false - }; + }; } if (!AWS_REGION) { global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "pnaUploadErr", 'No AWS Region provided'); return { framework: name, success: false - }; + }; } if (!AWS_BUCKET) { global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "pnaUploadErr", 'No AWS Bucket provided'); @@ -181,7 +178,7 @@ async function uploadToAws(data, name) { return { framework: name, success: success - }; + }; } catch (err) { global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "pnaUploadErr", name); global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "pnaUploadErr", err); diff --git a/src/main/server/adapter/ceasn/ceasn.js b/src/main/server/adapter/ceasn/ceasn.js index 45370abb8..8cd6b13e0 100644 --- a/src/main/server/adapter/ceasn/ceasn.js +++ b/src/main/server/adapter/ceasn/ceasn.js @@ -40,7 +40,7 @@ async function ceasnExportUriTransform(uri, frameworkUri) { if (!found) { return uri; } - } catch(err) { + } catch (err) { debug(err); return uri; } @@ -57,123 +57,119 @@ async function ceasnExportUriTransform(uri, frameworkUri) { } async function competencyPromise(compId, competencies, allCompetencies, f, ctx, terms) { - return new Promise(async (resolve) => { - try { - var c = competencies[compId]; - if (!c) { - resolve(null); - return; - } - if (c == null) resolve(c); - if (c["ceasn:hasChild"] != null && c["ceasn:hasChild"]["@list"] && c["ceasn:hasChild"]["@list"] != null) - c["ceasn:hasChild"]["@list"].sort(function (a, b) { - return allCompetencies.indexOf(a) - allCompetencies.indexOf(b); - }); - c.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasn.json"; - c["ceasn:isPartOf"] = await ceasnExportUriTransform(f.id); - if (!c["ceasn:isChildOf"] || c["ceasn:isChildOf"] == null) { - c["ceasn:isTopChildOf"] = await ceasnExportUriTransform(f.id); - } - if (c.name == null || c.name == "") - if (c.description != null && c.description != "") { - c.name = c.description; - delete c.description; - } - if (c.type == null) //Already done / referred to by another name. - resolve(); - var guid = c.getGuid(); - var uuid = new UUID(3, "nil", c.shortId()).format(); - - //If schema:identifier is not a URI, remove from translation - if (c["schema:identifier"] != null && !EcArray.isArray(c["schema:identifier"]) && c["schema:identifier"].indexOf("http") == -1) { - delete c["schema:identifier"]; - } else if (c["schema:identifier"] != null) { - if (!EcArray.isArray(c["schema:identifier"])) { - c["schema:identifier"] = [c["schema:identifier"]]; - } - for (var k = c["schema:identifier"].length - 1; k >= 0; k--) { - if (c["schema:identifier"][k].indexOf("http") == -1) { - c["schema:identifier"].splice(k, 1); - } - } + try { + var c = competencies[compId]; + if (!c) { + resolve(null); + return; + } + if (c == null) resolve(c); + if (c["ceasn:hasChild"] != null && c["ceasn:hasChild"]["@list"] && c["ceasn:hasChild"]["@list"] != null) + c["ceasn:hasChild"]["@list"].sort(function(a, b) { + return allCompetencies.indexOf(a) - allCompetencies.indexOf(b); + }); + c.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasn.json"; + c["ceasn:isPartOf"] = await ceasnExportUriTransform(f.id); + if (!c["ceasn:isChildOf"] || c["ceasn:isChildOf"] == null) { + c["ceasn:isTopChildOf"] = await ceasnExportUriTransform(f.id); + } + if (c.name == null || c.name == "") + if (c.description != null && c.description != "") { + c.name = c.description; + delete c.description; } - - //Remove fields that are only whitespace - for (var key in c) { - if (typeof c[key] == "string" && c[key].trim().length == 0) { - delete c[key]; + if (c.type == null) // Already done / referred to by another name. + resolve(); + var guid = c.getGuid(); + var uuid = new UUID(3, "nil", c.shortId()).format(); + + // If schema:identifier is not a URI, remove from translation + if (c["schema:identifier"] != null && !EcArray.isArray(c["schema:identifier"]) && c["schema:identifier"].indexOf("http") == -1) { + delete c["schema:identifier"]; + } else if (c["schema:identifier"] != null) { + if (!EcArray.isArray(c["schema:identifier"])) { + c["schema:identifier"] = [c["schema:identifier"]]; + } + for (var k = c["schema:identifier"].length - 1; k >= 0; k--) { + if (c["schema:identifier"][k].indexOf("http") == -1) { + c["schema:identifier"].splice(k, 1); } } - var socList = c["socList"]; - var naicsList = c["naicsList"]; - var cipList = c["cipList"]; + } - for (let each in c) { - if (terms[each] && each !== terms[each]) { - c[terms[each]] = c[each]; - delete c[each]; - } - if (each === "type") { - c[each] = "ceasn:Competency"; - } + // Remove fields that are only whitespace + for (var key in c) { + if (typeof c[key] == "string" && c[key].trim().length == 0) { + delete c[key]; } + } + var socList = c["socList"]; + var naicsList = c["naicsList"]; + var cipList = c["cipList"]; - c = await jsonLdCompact(c.toJson(), ctx); - if (socList) { - c["socList"] = socList; + for (let each in c) { + if (terms[each] && each !== terms[each]) { + c[terms[each]] = c[each]; + delete c[each]; } - if (naicsList) { - c["naicsList"] = naicsList; - } - if (cipList) { - c["cipList"] = cipList; + if (each === "type") { + c[each] = "ceasn:Competency"; } + } - if (c["ceasn:inLanguage"] == null) - c["ceasn:inLanguage"] = "en"; + c = await jsonLdCompact(c.toJson(), ctx); + if (socList) { + c["socList"] = socList; + } + if (naicsList) { + c["naicsList"] = naicsList; + } + if (cipList) { + c["cipList"] = cipList; + } - if (c["ceterms:ctid"] == null) { - if (guid.matches("^(ce-)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")) - c["ceterms:ctid"] = guid; - else - c["ceterms:ctid"] = uuid; - } - if (c["ceterms:ctid"].indexOf("ce-") != 0) - c["ceterms:ctid"] = "ce-" + c["ceterms:ctid"]; - if (c["ceasn:name"] != null) { - c["ceasn:competencyText"] = c["ceasn:name"]; - delete c["ceasn:name"]; - } - if (c["ceasn:description"] != null) { - c["ceasn:comment"] = c["ceasn:description"]; - delete c["ceasn:description"]; - } - if (c["schema:educationalAlignment"] != null) { - if (!EcArray.isArray(c["schema:educationalAlignment"])) { - c["ceasn:educationLevelType"] = c["schema:educationalAlignment"]["schema:targetName"]; - } - else { - c["ceasn:educationLevelType"] = []; - for (var j = 0; j < c["schema:educationalAlignment"].length; j++) { - c["ceasn:educationLevelType"].push(c["schema:educationalAlignment"][j]["schema:targetName"]); - } - } - } - delete c["@context"]; - c = stripNonCe(c); - resolve(c); - } catch(err) { - global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "CeasnCompetencyError", err); - resolve(c); + if (c["ceasn:inLanguage"] == null) + c["ceasn:inLanguage"] = "en"; + + if (c["ceterms:ctid"] == null) { + if (guid.matches("^(ce-)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")) + c["ceterms:ctid"] = guid; + else + c["ceterms:ctid"] = uuid; } - }); + if (c["ceterms:ctid"].indexOf("ce-") != 0) + c["ceterms:ctid"] = "ce-" + c["ceterms:ctid"]; + if (c["ceasn:name"] != null) { + c["ceasn:competencyText"] = c["ceasn:name"]; + delete c["ceasn:name"]; + } + if (c["ceasn:description"] != null) { + c["ceasn:comment"] = c["ceasn:description"]; + delete c["ceasn:description"]; + } + if (c["schema:educationalAlignment"] != null) { + if (!EcArray.isArray(c["schema:educationalAlignment"])) { + c["ceasn:educationLevelType"] = c["schema:educationalAlignment"]["schema:targetName"]; + } + else { + c["ceasn:educationLevelType"] = []; + for (var j = 0; j < c["schema:educationalAlignment"].length; j++) { + c["ceasn:educationLevelType"].push(c["schema:educationalAlignment"][j]["schema:targetName"]); + } + } + } + delete c["@context"]; + c = stripNonCe(c); + resolve(c); + } catch (err) { + global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "CeasnCompetencyError", err); + resolve(c); + } } async function cassFrameworkAsCeasn() { - EcRepository.cache = new Object(); + EcRepository.cache = {}; EcRepository.caching = true; - if (false && repoEndpoint().contains("localhost")) - error("Endpoint Configuration is not set.", 500); var query = queryParse.call(this); var framework = null; if (framework == null) @@ -214,7 +210,7 @@ async function cassFrameworkAsCeasn() { let frameworks = []; try { frameworks = await EcFramework.search(repo, "competency:\"" + competency.shortId() + "\""); - } catch(error) { + } catch (error) { error("Framework search failed."); } if (frameworks.length == 0) { @@ -237,7 +233,7 @@ async function cassFrameworkAsCeasn() { if (f.relation != null) all = all.concat(f.relation); - repo.precache(all, function (results) {}); + repo.precache(all, function (results) { }); var allCompetencies = JSON.parse(JSON.stringify(f.competency)); var competencies = {}; @@ -384,13 +380,13 @@ async function cassFrameworkAsCeasn() { } } - var ctx = JSON.stringify((await httpGet("https://credreg.net/ctdlasn/schema/context/json"))["@context"],true); - const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnTerms")),true)); + var ctx = JSON.stringify((await httpGet("https://credreg.net/ctdlasn/schema/context/json"))["@context"], true); + const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnTerms")), true)); f.competency = []; let mappedCompetencies = []; - for (let i = 0; i < allCompetencies.length; i+=100) { - let batch = await Promise.all(allCompetencies.slice(i, i+100).map((id) => competencyPromise(id, competencies, allCompetencies, f, ctx, terms))); - mappedCompetencies.push(... batch); + for (let i = 0; i < allCompetencies.length; i += 100) { + let batch = await Promise.all(allCompetencies.slice(i, i + 100).map((id) => competencyPromise(id, competencies, allCompetencies, f, ctx, terms))); + mappedCompetencies.push(...batch); } competencies = mappedCompetencies.slice(0); if (f["ceasn:hasTopChild"] == null) { @@ -439,8 +435,8 @@ async function cassFrameworkAsCeasn() { if (f["schema:identifier"] != null && !EcArray.isArray(f["schema:identifier"]) && f["schema:identifier"].indexOf("http") == -1) { delete f["schema:identifier"]; } else if (f["schema:identifier"] != null) { - if (!EcArray.isArray(f["schema:identifier"])) { - f["schema:identifier"] = [f["schema:identifier"]]; + if (!EcArray.isArray(f["schema:identifier"])) { + f["schema:identifier"] = [f["schema:identifier"]]; } for (var i = f["schema:identifier"].length - 1; i >= 0; i--) { if (f["schema:identifier"][i].indexOf("http") == -1) { @@ -465,11 +461,11 @@ async function cassFrameworkAsCeasn() { f[terms[each]] = f[each]; delete f[each]; } - + if (each === "type") { f[each] = "ceasn:CompetencyFramework"; } - + if (each === 'validFrom' || each === 'validUntil') { if (EcObject.isObject(f[terms[each]]) && f[terms[each]]['@value']) { f[terms[each]] = f[terms[each]]['@value'] @@ -503,9 +499,9 @@ async function cassFrameworkAsCeasn() { if (EcArray.isArray(f["ceasn:source"])) { f["ceasn:source"].push(f["@id"]); } - else { - f["ceasn:source"] = [f["ceasn:source"], f["@id"]]; - } else + else { + f["ceasn:source"] = [f["ceasn:source"], f["@id"]]; + } else f["ceasn:source"] = f["@id"]; } f["@id"] = await ceasnExportUriTransform(f["@id"]); @@ -530,9 +526,9 @@ async function cassFrameworkAsCeasn() { if (EcArray.isArray(c["ceasn:exactAlignment"])) { c["ceasn:exactAlignment"].push(c["@id"]); } - else { - c["ceasn:exactAlignment"] = [c["ceasn:exactAlignment"], c["@id"]]; - } else + else { + c["ceasn:exactAlignment"] = [c["ceasn:exactAlignment"], c["@id"]]; + } else c["ceasn:exactAlignment"] = [c["@id"]]; } competencies[k]["@id"] = await ceasnExportUriTransform(competencies[k]["@id"]); @@ -594,7 +590,7 @@ function stripNonCe(f) { }); } if (k.indexOf("ceasn:") == 0 || k.indexOf("ceterms:") == 0 || k.indexOf("asn:") == 0 || k.indexOf("@") == 0 || k.indexOf("socList") != -1 || k.indexOf("naicsList") != -1 || k.indexOf("cipList") != -1) - ; + ; else delete f[k]; } @@ -603,7 +599,7 @@ function stripNonCe(f) { function orderFields(object) { var ordered = {}; - Object.keys(object).sort().forEach(function (key) { + Object.keys(object).sort().forEach(function (key) { // NOSONAR programmatic sort is necessary ordered[key] = object[key]; delete object[key]; }); @@ -614,7 +610,6 @@ function orderFields(object) { } async function competencyInCollectionPromise(compId, competencies, allCompetencies, f, ctx, terms, cass2ceasn) { - return new Promise(async (resolve) => { try { var c = competencies[compId]; if (c == null) { @@ -702,35 +697,34 @@ async function competencyInCollectionPromise(compId, competencies, allCompetenci competencies[id]["ceasn:comment"] = competencies[id]["ceasn:description"]; delete competencies[id]["ceasn:description"]; } - if (c["schema:educationalAlignment"] != null) { - if (!EcArray.isArray(c["schema:educationalAlignment"])) { - competencies[id]["ceasn:educationLevelType"] = c["schema:educationalAlignment"]["schema:targetName"]; - } - else { - competencies[id]["ceasn:educationLevelType"] = []; - for (var j = 0; j < c["schema:educationalAlignment"].length; j++) { - competencies[id]["ceasn:educationLevelType"].push(c["schema:educationalAlignment"][j]["schema:targetName"]); - } - } - } + if (c["schema:educationalAlignment"] != null) { + if (!EcArray.isArray(c["schema:educationalAlignment"])) { + competencies[id]["ceasn:educationLevelType"] = c["schema:educationalAlignment"]["schema:targetName"]; + } + else { + competencies[id]["ceasn:educationLevelType"] = []; + for (var j = 0; j < c["schema:educationalAlignment"].length; j++) { + competencies[id]["ceasn:educationLevelType"].push(c["schema:educationalAlignment"][j]["schema:targetName"]); + } + } + } delete competencies[id]["@context"]; competencies[id] = stripNonCe(competencies[id]); resolve(); - } catch(err) { + } catch (err) { global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.INFO, "CeasnCompetencyCollection", err); resolve(); } - }); } async function cassFrameworkAsCeasnCollection(framework) { EcRepository.cache = new Object(); EcRepository.caching = true; - const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnTerms")),true)); - const collectionTerms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasncollectionTerms")),true)); - var ctx = JSON.stringify((await httpGet("https://credreg.net/ctdlasn/schema/context/json"))["@context"],true); - const collectionContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasncollection.json"))["@context"],true); + const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnTerms")), true)); + const collectionTerms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasncollectionTerms")), true)); + var ctx = JSON.stringify((await httpGet("https://credreg.net/ctdlasn/schema/context/json"))["@context"], true); + const collectionContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasncollection.json"))["@context"], true); const cass2ceasn = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasn.json"))["@context"], true); const cetermsctx = JSON.stringify((await httpGet("https://credreg.net/ctdl/schema/context/json"))["@context"], true); @@ -745,7 +739,7 @@ async function cassFrameworkAsCeasnCollection(framework) { if (f.relation != null) all = all.concat(f.relation); - repo.precache(all, function (results) {}); + repo.precache(all, function (results) { }); var allCompetencies = JSON.parse(JSON.stringify(f.competency)); var competencies = {}; @@ -867,9 +861,9 @@ async function cassFrameworkAsCeasnCollection(framework) { } f.competency = []; - - for (let i = 0; i < allCompetencies.length; i+=10) { - await Promise.all(allCompetencies.slice(i, i+10).map((id) => competencyInCollectionPromise(id, competencies, allCompetencies, f, ctx, terms, cass2ceasn))); + + for (let i = 0; i < allCompetencies.length; i += 10) { + await Promise.all(allCompetencies.slice(i, i + 10).map((id) => competencyInCollectionPromise(id, competencies, allCompetencies, f, ctx, terms, cass2ceasn))); } f.context = JSON.parse(collectionContext); @@ -928,9 +922,9 @@ async function cassFrameworkAsCeasnCollection(framework) { if (EcArray.isArray(f["ceasn:source"])) { f["ceasn:source"].push(f["@id"]); } - else { - f["ceasn:source"] = [f["ceasn:source"], f["@id"]]; - } else + else { + f["ceasn:source"] = [f["ceasn:source"], f["@id"]]; + } else f["ceasn:source"] = f["@id"]; } f["@id"] = await ceasnExportUriTransform(f["@id"]); @@ -952,9 +946,9 @@ async function cassFrameworkAsCeasnCollection(framework) { if (EcArray.isArray(c["ceasn:exactAlignment"])) { c["ceasn:exactAlignment"].push(c["@id"]); } - else { - c["ceasn:exactAlignment"] = [c["ceasn:exactAlignment"], c["@id"]]; - } else + else { + c["ceasn:exactAlignment"] = [c["ceasn:exactAlignment"], c["@id"]]; + } else c["ceasn:exactAlignment"] = [c["@id"]]; } competencies[k]["@id"] = await ceasnExportUriTransform(competencies[k]["@id"]); @@ -1012,125 +1006,121 @@ function conceptArrays(object) { } async function conceptPromise(obj, concepts, cs, ctx, terms) { - return new Promise(async (resolve) => { - try { - var c = concepts[obj]; - delete concepts[obj]; - if (c != null && c.id != null) { - var id = c.id; - concepts[id] = c; - delete concepts[id]["owner"]; - delete concepts[id]["signature"]; - delete concepts[id]["skos:inLanguage"]; - - c.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnConcepts.json"; - if (c.id != await ceasnExportUriTransform(c.id)) { - if (c["skos:exactMatch"] != null) - if (EcArray.isArray(c["skos:exactMatch"])) { - c["skos:exactMatch"].push(c.id); - } + try { + var c = concepts[obj]; + delete concepts[obj]; + if (c != null && c.id != null) { + var id = c.id; + concepts[id] = c; + delete concepts[id]["owner"]; + delete concepts[id]["signature"]; + delete concepts[id]["skos:inLanguage"]; + + c.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnConcepts.json"; + if (c.id != await ceasnExportUriTransform(c.id)) { + if (c["skos:exactMatch"] != null) + if (EcArray.isArray(c["skos:exactMatch"])) { + c["skos:exactMatch"].push(c.id); + } else { c["skos:exactMatch"] = [c["skos:exactMatch"], c.id]; } else - c["skos:exactMatch"] = [c.id]; - } - c.id = await ceasnExportUriTransform(c.id); - c["skos:inScheme"] = await ceasnExportUriTransform(cs.id); - if (c["skos:topConceptOf"] != null) { - c["skos:topConceptOf"] = await ceasnExportUriTransform(cs.id); - } - if (c.type == null) //Already done / referred to by another name. - resolve(); - var guid = c.getGuid(); - var uuid = new UUID(3, "nil", c.shortId()).format(); - for (let each in c) { - if (terms[each] && each !== terms[each]) { - c[terms[each]] = c[each]; - delete c[each]; - } - if (each === "type") { - c[each] = "skos:Concept"; - } + c["skos:exactMatch"] = [c.id]; + } + c.id = await ceasnExportUriTransform(c.id); + c["skos:inScheme"] = await ceasnExportUriTransform(cs.id); + if (c["skos:topConceptOf"] != null) { + c["skos:topConceptOf"] = await ceasnExportUriTransform(cs.id); + } + if (c.type == null) //Already done / referred to by another name. + resolve(); + var guid = c.getGuid(); + var uuid = new UUID(3, "nil", c.shortId()).format(); + for (let each in c) { + if (terms[each] && each !== terms[each]) { + c[terms[each]] = c[each]; + delete c[each]; } - concepts[obj] = concepts[id] = await jsonLdCompact(c.toJson(), ctx); - - if (concepts[id]["ceterms:ctid"] == null) { - if (guid.matches("^(ce-)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")) { - concepts[id]["ceterms:ctid"] = guid; - } else { - concepts[id]["ceterms:ctid"] = uuid; - } + if (each === "type") { + c[each] = "skos:Concept"; } + } + concepts[obj] = concepts[id] = await jsonLdCompact(c.toJson(), ctx); - if (concepts[id]["ceterms:ctid"].indexOf("ce-") != 0) { - concepts[id]["ceterms:ctid"] = "ce-" + concepts[id]["ceterms:ctid"]; + if (concepts[id]["ceterms:ctid"] == null) { + if (guid.matches("^(ce-)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")) { + concepts[id]["ceterms:ctid"] = guid; + } else { + concepts[id]["ceterms:ctid"] = uuid; } - delete concepts[id]["@context"]; + } - concepts[id] = conceptArrays(concepts[id]); + if (concepts[id]["ceterms:ctid"].indexOf("ce-") != 0) { + concepts[id]["ceterms:ctid"] = "ce-" + concepts[id]["ceterms:ctid"]; } - resolve(); - } catch(err) { - global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.INFO, "CeasnConcept", err); - resolve(); + delete concepts[id]["@context"]; + + concepts[id] = conceptArrays(concepts[id]); } - }); + resolve(); + } catch (err) { + global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.INFO, "CeasnConcept", err); + resolve(); + } } async function levelPromise(obj, levels, cs, ctx, terms) { - return new Promise(async (resolve) => { - try { - var c = levels[obj]; - delete levels[obj]; - if (c != null && c.id != null) { - var id = c.id; - levels[id] = c; - delete levels[id]["owner"]; - delete levels[id]["signature"]; - delete levels[id]["skos:inLanguage"]; - - c.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnProgressions.json"; - c.id = await ceasnExportUriTransform(c.id); - if (c["skos:topConceptOf"] != null) { - c["skos:topConceptOf"] = await ceasnExportUriTransform(cs.id); - } - if (c.type == null) //Already done / referred to by another name. - resolve(); - var guid = c.getGuid(); - var uuid = new UUID(3, "nil", c.shortId()).format(); - for (let each in c) { - if (terms[each] && each !== terms[each]) { - c[terms[each]] = c[each]; - delete c[each]; - } - if (each === "type") { - c[each] = "asn:ProgressionLevel"; - } - } - levels[obj] = levels[id] = await jsonLdCompact(c.toJson(), ctx); + try { + var c = levels[obj]; + delete levels[obj]; + if (c != null && c.id != null) { + var id = c.id; + levels[id] = c; + delete levels[id]["owner"]; + delete levels[id]["signature"]; + delete levels[id]["skos:inLanguage"]; - if (levels[id]["ceterms:ctid"] == null) { - if (guid.matches("^(ce-)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")) { - levels[id]["ceterms:ctid"] = guid; - } else { - levels[id]["ceterms:ctid"] = uuid; - } + c.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnProgressions.json"; + c.id = await ceasnExportUriTransform(c.id); + if (c["skos:topConceptOf"] != null) { + c["skos:topConceptOf"] = await ceasnExportUriTransform(cs.id); + } + if (c.type == null) //Already done / referred to by another name. + resolve(); + var guid = c.getGuid(); + var uuid = new UUID(3, "nil", c.shortId()).format(); + for (let each in c) { + if (terms[each] && each !== terms[each]) { + c[terms[each]] = c[each]; + delete c[each]; + } + if (each === "type") { + c[each] = "asn:ProgressionLevel"; } + } + levels[obj] = levels[id] = await jsonLdCompact(c.toJson(), ctx); - if (levels[id]["ceterms:ctid"].indexOf("ce-") != 0) { - levels[id]["ceterms:ctid"] = "ce-" + levels[id]["ceterms:ctid"]; + if (levels[id]["ceterms:ctid"] == null) { + if (guid.matches("^(ce-)?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")) { + levels[id]["ceterms:ctid"] = guid; + } else { + levels[id]["ceterms:ctid"] = uuid; } - delete levels[id]["@context"]; + } - levels[id] = conceptArrays(levels[id]); - levels[id]["@type"] = "asn:ProgressionLevel"; + if (levels[id]["ceterms:ctid"].indexOf("ce-") != 0) { + levels[id]["ceterms:ctid"] = "ce-" + levels[id]["ceterms:ctid"]; } - resolve(); - } catch(err) { - global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.INFO, "CeasnProgression", err); - resolve(); + delete levels[id]["@context"]; + + levels[id] = conceptArrays(levels[id]); + levels[id]["@type"] = "asn:ProgressionLevel"; } - }); + resolve(); + } catch (err) { + global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.INFO, "CeasnProgression", err); + resolve(); + } } async function cassConceptSchemeAsCeasn(framework) { @@ -1143,7 +1133,7 @@ async function cassConceptSchemeAsCeasn(framework) { if (cs["skos:hasTopConcept"] == null) { cs["skos:hasTopConcept"] = []; } - repo.precache(cs["skos:hasTopConcept"], function() {}); + repo.precache(cs["skos:hasTopConcept"], function () { }); var concepts = {}; var allConcepts = JSON.parse(JSON.stringify(cs["skos:hasTopConcept"])); @@ -1154,7 +1144,7 @@ async function cassConceptSchemeAsCeasn(framework) { concepts[cs["skos:hasTopConcept"][i]] = concepts[c.id] = c; if (c["skos:narrower"]) { async function getSubConcepts(c) { - repo.precache(c["skos:narrower"], function() {}); + repo.precache(c["skos:narrower"], function () { }); for (var j = 0; j < c["skos:narrower"].length; j++) { var subC = await EcConcept.get(c["skos:narrower"][j], null, null, repo); if (subC != null) { @@ -1172,11 +1162,11 @@ async function cassConceptSchemeAsCeasn(framework) { } } - var ctx = JSON.stringify((await httpGet("https://credreg.net/ctdlasn/schema/context/json"))["@context"],true); - const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnConceptsTerms")),true)); + var ctx = JSON.stringify((await httpGet("https://credreg.net/ctdlasn/schema/context/json"))["@context"], true); + const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnConceptsTerms")), true)); - for (let i = 0; i < allConcepts.length; i+=100) { - await Promise.all(allConcepts.slice(i, i+100).map((id) => conceptPromise(id, concepts, cs, ctx, terms))); + for (let i = 0; i < allConcepts.length; i += 100) { + await Promise.all(allConcepts.slice(i, i + 100).map((id) => conceptPromise(id, concepts, cs, ctx, terms))); } cs.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnConcepts.json"; @@ -1216,9 +1206,9 @@ async function cassConceptSchemeAsCeasn(framework) { if (EcArray.isArray(cs["ceasn:exactAlignment"])) { cs["ceasn:exactAlignment"].push(csId); } - else { - cs["ceasn:exactAlignment"] = [cs["ceasn:exactAlignment"], csId]; - } else + else { + cs["ceasn:exactAlignment"] = [cs["ceasn:exactAlignment"], csId]; + } else cs["ceasn:exactAlignment"] = [csId]; } cs["@id"] = await ceasnExportUriTransform(csId); @@ -1264,7 +1254,7 @@ async function cassConceptSchemeAsCeasnProgression(framework) { if (cs["skos:hasTopConcept"] == null) { cs["skos:hasTopConcept"] = []; } - repo.precache(cs["skos:hasTopConcept"], function() {}); + repo.precache(cs["skos:hasTopConcept"], function () { }); var levels = {}; var allLevels = JSON.parse(JSON.stringify(cs["skos:hasTopConcept"])); @@ -1275,7 +1265,7 @@ async function cassConceptSchemeAsCeasnProgression(framework) { levels[cs["skos:hasTopConcept"][i]] = levels[c.id] = c; if (c["skos:narrower"]) { async function getSubConcepts(c) { - repo.precache(c["skos:narrower"], function() {}); + repo.precache(c["skos:narrower"], function () { }); for (var j = 0; j < c["skos:narrower"].length; j++) { var subC = await EcConcept.get(c["skos:narrower"][j], null, null, repo); if (subC != null) { @@ -1293,11 +1283,11 @@ async function cassConceptSchemeAsCeasnProgression(framework) { } } - var ctx = JSON.stringify((await httpGet("https://credreg.net/ctdlasn/schema/context/json"))["@context"],true); - const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnProgressionsTerms")),true)); + var ctx = JSON.stringify((await httpGet("https://credreg.net/ctdlasn/schema/context/json"))["@context"], true); + const terms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnProgressionsTerms")), true)); - for (let i = 0; i < allLevels.length; i+=100) { - await Promise.all(allLevels.slice(i, i+100).map((id) => levelPromise(id, levels, cs, ctx, terms))); + for (let i = 0; i < allLevels.length; i += 100) { + await Promise.all(allLevels.slice(i, i + 100).map((id) => levelPromise(id, levels, cs, ctx, terms))); } cs.context = "https://schema.cassproject.org/0.4/jsonld1.1/cass2ceasnProgressions.json"; @@ -1337,9 +1327,9 @@ async function cassConceptSchemeAsCeasnProgression(framework) { if (EcArray.isArray(cs["ceasn:exactAlignment"])) { cs["ceasn:exactAlignment"].push(csId); } - else { - cs["ceasn:exactAlignment"] = [cs["ceasn:exactAlignment"], csId]; - } else + else { + cs["ceasn:exactAlignment"] = [cs["ceasn:exactAlignment"], csId]; + } else cs["ceasn:exactAlignment"] = [csId]; } cs["@id"] = await ceasnExportUriTransform(csId); @@ -1409,147 +1399,143 @@ function createRelations(e, field, type, repo, ceo, id, cassRelations, toSave) { } async function importCompetencyPromise(asnComp, relationshipMap, listToSave, cassRelationships, cassCompetencies, ceasnIdentity, repo, owner, ceasn2cassTerms) { - return new Promise(async (resolve) => { - try { - var canonicalId = asnComp["@id"]; - - var childComps = asnComp["ceasn:hasChild"]; - if (childComps != null && childComps.length != null) { - for (var i = 0; i < childComps.length; i++) { - var r = new EcAlignment(); - r.source = EcRemoteLinkedData.trimVersionFromUrl(childComps[i]); - r.target = EcRemoteLinkedData.trimVersionFromUrl(canonicalId); - r.relationType = Relation.NARROWS; - r.generateId(repoEndpoint()); - r.addOwner(ceasnIdentity.ppk.toPk()); - - if (owner != null) - r.addOwner(EcPk.fromPem(owner)); - - if (relationshipMap[r.source + r.target] != true) { - relationshipMap[r.source + r.target] = true; - listToSave.push(r); - cassRelationships.push(r.shortId()); - cassCompetencies.push(r.source); - } + try { + var canonicalId = asnComp["@id"]; + + var childComps = asnComp["ceasn:hasChild"]; + if (childComps != null && childComps.length != null) { + for (var i = 0; i < childComps.length; i++) { + var r = new EcAlignment(); + r.source = EcRemoteLinkedData.trimVersionFromUrl(childComps[i]); + r.target = EcRemoteLinkedData.trimVersionFromUrl(canonicalId); + r.relationType = Relation.NARROWS; + r.generateId(repoEndpoint()); + r.addOwner(ceasnIdentity.ppk.toPk()); + + if (owner != null) + r.addOwner(EcPk.fromPem(owner)); + + if (relationshipMap[r.source + r.target] != true) { + relationshipMap[r.source + r.target] = true; + listToSave.push(r); + cassRelationships.push(r.shortId()); + cassCompetencies.push(r.source); } } + } - var newComp = JSON.parse(JSON.stringify(asnComp)); - delete newComp["ceasn:hasChild"]; + var newComp = JSON.parse(JSON.stringify(asnComp)); + delete newComp["ceasn:hasChild"]; - newComp["@context"] = "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json"; - for (let each in newComp) { - if (ceasn2cassTerms[each] && each !== ceasn2cassTerms[each]) { - newComp[ceasn2cassTerms[each]] = newComp[each]; - delete newComp[each]; - } - if (each === "@type") { - newComp[each] = "Competency"; - } + newComp["@context"] = "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json"; + for (let each in newComp) { + if (ceasn2cassTerms[each] && each !== ceasn2cassTerms[each]) { + newComp[ceasn2cassTerms[each]] = newComp[each]; + delete newComp[each]; + } + if (each === "@type") { + newComp[each] = "Competency"; } - var expandedComp = await jsonLdExpand(JSON.stringify(newComp)); - var compactedComp = await jsonLdCompact(JSON.stringify(expandedComp), "https://schema.cassproject.org/0.4"); + } + var expandedComp = await jsonLdExpand(JSON.stringify(newComp)); + var compactedComp = await jsonLdCompact(JSON.stringify(expandedComp), "https://schema.cassproject.org/0.4"); - if (compactedComp["ceasn:isChildOf"]) delete compactedComp["ceasn:isChildOf"]; - if (compactedComp["ceasn:hasChild"]) delete compactedComp["ceasn:hasChild"]; - if (compactedComp["ceasn:isPartOf"]) delete compactedComp["ceasn:isPartOf"]; + if (compactedComp["ceasn:isChildOf"]) delete compactedComp["ceasn:isChildOf"]; + if (compactedComp["ceasn:hasChild"]) delete compactedComp["ceasn:hasChild"]; + if (compactedComp["ceasn:isPartOf"]) delete compactedComp["ceasn:isPartOf"]; - var c = new EcCompetency(); - c.copyFrom(compactedComp); - c.addOwner(ceasnIdentity.ppk.toPk()); - - if (c["schema:dateCreated"] == null || c["schema:dateCreated"] === undefined) { - var timestamp; - var date; - if (!c.id.substring(c.id.lastIndexOf("/")).matches("\\/[0-9]+")) { - timestamp = null; - } else { - timestamp = c.id.substring(c.id.lastIndexOf("/") + 1); - } - if (timestamp != null) { - date = new Date(parseInt(timestamp)).toISOString(); - } else { - date = new Date().toISOString(); - } - c["schema:dateCreated"] = date; - } - if (c["ceasn:broadAlignment"]) { - createRelations(c, "ceasn:broadAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:narrowAlignment"]) { - createRelations(c, "ceasn:narrowAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["sameAs"]) { - createRelations(c, "sameAs", "isEquivalentTo", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:majorAlignment"]) { - createRelations(e, "ceasn:majorAlignment", "majorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:minorAlignment"]) { - createRelations(c, "ceasn:minorAlignment", "minorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:prerequisiteAlignment"]) { - createRelations(c, "ceasn:prerequisiteAlignment", "requires", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - delete c["ceasn:broadAlignment"]; - delete c["ceasn:narrowAlignment"]; - delete c["sameAs"]; - delete c["ceasn:majorAlignment"]; - delete c["ceasn:minorAlignment"]; - delete c["ceasn:prerequisiteAlignment"]; + var c = new EcCompetency(); + c.copyFrom(compactedComp); + c.addOwner(ceasnIdentity.ppk.toPk()); - if (c["ceasn:broadAlignment"]) { - createRelations(c, "ceasn:broadAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:narrowAlignment"]) { - createRelations(c, "ceasn:narrowAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["sameAs"]) { - createRelations(c, "sameAs", "isEquivalentTo", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:majorAlignment"]) { - createRelations(e, "ceasn:majorAlignment", "majorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:minorAlignment"]) { - createRelations(c, "ceasn:minorAlignment", "minorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); + if (c["schema:dateCreated"] == null || c["schema:dateCreated"] === undefined) { + var timestamp; + var date; + if (!c.id.substring(c.id.lastIndexOf("/")).matches("\\/[0-9]+")) { + timestamp = null; + } else { + timestamp = c.id.substring(c.id.lastIndexOf("/") + 1); } - if (c["ceasn:prerequisiteAlignment"]) { - createRelations(c, "ceasn:prerequisiteAlignment", "requires", repo, ceasnIdentity, owner, cassRelationships, listToSave); + if (timestamp != null) { + date = new Date(parseInt(timestamp)).toISOString(); + } else { + date = new Date().toISOString(); } - delete c["ceasn:broadAlignment"]; - delete c["ceasn:narrowAlignment"]; - delete c["sameAs"]; - delete c["ceasn:majorAlignment"]; - delete c["ceasn:minorAlignment"]; - delete c["ceasn:prerequisiteAlignment"]; - - if (owner != null) - c.addOwner(EcPk.fromPem(owner)); - listToSave.push(c); - resolve(); - } catch(err) { - global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "CeasnImportCompetency", err); - resolve(); + c["schema:dateCreated"] = date; } - }); + if (c["ceasn:broadAlignment"]) { + createRelations(c, "ceasn:broadAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:narrowAlignment"]) { + createRelations(c, "ceasn:narrowAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["sameAs"]) { + createRelations(c, "sameAs", "isEquivalentTo", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:majorAlignment"]) { + createRelations(e, "ceasn:majorAlignment", "majorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:minorAlignment"]) { + createRelations(c, "ceasn:minorAlignment", "minorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:prerequisiteAlignment"]) { + createRelations(c, "ceasn:prerequisiteAlignment", "requires", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + delete c["ceasn:broadAlignment"]; + delete c["ceasn:narrowAlignment"]; + delete c["sameAs"]; + delete c["ceasn:majorAlignment"]; + delete c["ceasn:minorAlignment"]; + delete c["ceasn:prerequisiteAlignment"]; + + if (c["ceasn:broadAlignment"]) { + createRelations(c, "ceasn:broadAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:narrowAlignment"]) { + createRelations(c, "ceasn:narrowAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["sameAs"]) { + createRelations(c, "sameAs", "isEquivalentTo", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:majorAlignment"]) { + createRelations(e, "ceasn:majorAlignment", "majorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:minorAlignment"]) { + createRelations(c, "ceasn:minorAlignment", "minorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:prerequisiteAlignment"]) { + createRelations(c, "ceasn:prerequisiteAlignment", "requires", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + delete c["ceasn:broadAlignment"]; + delete c["ceasn:narrowAlignment"]; + delete c["sameAs"]; + delete c["ceasn:majorAlignment"]; + delete c["ceasn:minorAlignment"]; + delete c["ceasn:prerequisiteAlignment"]; + + if (owner != null) + c.addOwner(EcPk.fromPem(owner)); + listToSave.push(c); + } catch (err) { + global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "CeasnImportCompetency", err); + } } async function importCeFrameworkToCass(frameworkObj, competencyList) { const nodeDocumentLoader = jsonld.documentLoaders.node(); - const cassContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4")),true); - const ceasn2cassContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json")),true); - const ceasn2cassTerms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cassTerms")),true)); + const cassContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4")), true); + const ceasn2cassContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json")), true); + const ceasn2cassTerms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cassTerms")), true)); const customLoader = async (url) => { - if(url === "https://schema.cassproject.org/0.4") { + if (url === "https://schema.cassproject.org/0.4") { return { contextUrl: null, // this is for a context via a link header document: cassContext, // this is the actual document that was loaded documentUrl: url // this is the actual context URL after redirects }; } - if(url === "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json") { + if (url === "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json") { return { contextUrl: null, // this is for a context via a link header document: ceasn2cassContext, // this is the actual document that was loaded @@ -1569,9 +1555,6 @@ async function importCeFrameworkToCass(frameworkObj, competencyList) { ceasnIdentity.displayName = "CEASN Server Identity"; EcIdentityManager.default.addIdentity(ceasnIdentity); - if (false && repoEndpoint().contains("localhost")) - error("Endpoint Configuration is not set.", 500); - var cassCompetencies = []; var cassRelationships = []; var relationshipMap = {}; @@ -1586,8 +1569,8 @@ async function importCeFrameworkToCass(frameworkObj, competencyList) { } var listToSave = []; - for (let idx = 0; idx < competencyList.length; idx+=100) { - await Promise.all(competencyList.slice(idx, idx+100).map((comp) => importCompetencyPromise(comp, relationshipMap, listToSave, cassRelationships, cassCompetencies, ceasnIdentity, repo, owner, ceasn2cassTerms))); + for (let idx = 0; idx < competencyList.length; idx += 100) { + await Promise.all(competencyList.slice(idx, idx + 100).map((comp) => importCompetencyPromise(comp, relationshipMap, listToSave, cassRelationships, cassCompetencies, ceasnIdentity, repo, owner, ceasn2cassTerms))); } if (frameworkObj != null) { @@ -1648,109 +1631,107 @@ async function importCeFrameworkToCass(frameworkObj, competencyList) { listToSave.push(f); - await loopback.multiput(repo,listToSave); + await loopback.multiput(repo, listToSave); return f.shortId(); } // end if frameworkObj != null } async function importCompetencyToCollectionPromise(asnComp, listToSave, cassRelationships, ceasnIdentity, repo, owner, terms) { - return new Promise(async (resolve) => { - try { - var newComp = JSON.parse(JSON.stringify(asnComp)); + try { + var newComp = JSON.parse(JSON.stringify(asnComp)); - let frameworks = await EcFramework.search(repo, 'competency:"' + EcRemoteLinkedData.trimVersionFromUrl(newComp.id) + '" AND NOT subType:Collection'); - if (frameworks && frameworks.length > 0) { - resolve(); - return; - } + let frameworks = await EcFramework.search(repo, 'competency:"' + EcRemoteLinkedData.trimVersionFromUrl(newComp.id) + '" AND NOT subType:Collection'); + if (frameworks && frameworks.length > 0) { + resolve(); + return; + } - newComp["@context"] = "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json"; - for (let each in newComp) { - if (terms[each] && each !== terms[each]) { - newComp[terms[each]] = newComp[each]; - delete newComp[each]; - } - if (each === "@type") { - newComp[each] = "Competency"; - } + newComp["@context"] = "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json"; + for (let each in newComp) { + if (terms[each] && each !== terms[each]) { + newComp[terms[each]] = newComp[each]; + delete newComp[each]; + } + if (each === "@type") { + newComp[each] = "Competency"; } - var expandedComp = await jsonLdExpand(JSON.stringify(newComp)); - var compactedComp = await jsonLdCompact(JSON.stringify(expandedComp), "https://schema.cassproject.org/0.4"); + } + var expandedComp = await jsonLdExpand(JSON.stringify(newComp)); + var compactedComp = await jsonLdCompact(JSON.stringify(expandedComp), "https://schema.cassproject.org/0.4"); - if (compactedComp["ceasn:isChildOf"]) delete compactedComp["ceasn:isChildOf"]; - if (compactedComp["ceasn:hasChild"]) delete compactedComp["ceasn:hasChild"]; - if (compactedComp["ceasn:isPartOf"]) delete compactedComp["ceasn:isPartOf"]; + if (compactedComp["ceasn:isChildOf"]) delete compactedComp["ceasn:isChildOf"]; + if (compactedComp["ceasn:hasChild"]) delete compactedComp["ceasn:hasChild"]; + if (compactedComp["ceasn:isPartOf"]) delete compactedComp["ceasn:isPartOf"]; - var c = new EcCompetency(); - c.copyFrom(compactedComp); - c.addOwner(ceasnIdentity.ppk.toPk()); - - if (c["schema:dateCreated"] == null || c["schema:dateCreated"] === undefined) { - var timestamp; - var date; - if (!c.id.substring(c.id.lastIndexOf("/")).matches("\\/[0-9]+")) { - timestamp = null; - } else { - timestamp = c.id.substring(c.id.lastIndexOf("/") + 1); - } - if (timestamp != null) { - date = new Date(parseInt(timestamp)).toISOString(); - } else { - date = new Date().toISOString(); - } - c["schema:dateCreated"] = date; - } - if (c["ceasn:broadAlignment"]) { - createRelations(c, "ceasn:broadAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:narrowAlignment"]) { - createRelations(c, "ceasn:narrowAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["sameAs"]) { - createRelations(c, "sameAs", "isEquivalentTo", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:majorAlignment"]) { - createRelations(e, "ceasn:majorAlignment", "majorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); - } - if (c["ceasn:minorAlignment"]) { - createRelations(c, "ceasn:minorAlignment", "minorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); + var c = new EcCompetency(); + c.copyFrom(compactedComp); + c.addOwner(ceasnIdentity.ppk.toPk()); + + if (c["schema:dateCreated"] == null || c["schema:dateCreated"] === undefined) { + var timestamp; + var date; + if (!c.id.substring(c.id.lastIndexOf("/")).matches("\\/[0-9]+")) { + timestamp = null; + } else { + timestamp = c.id.substring(c.id.lastIndexOf("/") + 1); } - if (c["ceasn:prerequisiteAlignment"]) { - createRelations(c, "ceasn:prerequisiteAlignment", "requires", repo, ceasnIdentity, owner, cassRelationships, listToSave); + if (timestamp != null) { + date = new Date(parseInt(timestamp)).toISOString(); + } else { + date = new Date().toISOString(); } - delete c["ceasn:broadAlignment"]; - delete c["ceasn:narrowAlignment"]; - delete c["sameAs"]; - delete c["ceasn:majorAlignment"]; - delete c["ceasn:minorAlignment"]; - delete c["ceasn:prerequisiteAlignment"]; - - if (owner != null) - c.addOwner(EcPk.fromPem(owner)); - listToSave.push(c); - resolve(); - } catch(err) { - global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "CeasnImportCollection", err); - resolve(); + c["schema:dateCreated"] = date; } - }); + if (c["ceasn:broadAlignment"]) { + createRelations(c, "ceasn:broadAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:narrowAlignment"]) { + createRelations(c, "ceasn:narrowAlignment", "narrows", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["sameAs"]) { + createRelations(c, "sameAs", "isEquivalentTo", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:majorAlignment"]) { + createRelations(e, "ceasn:majorAlignment", "majorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:minorAlignment"]) { + createRelations(c, "ceasn:minorAlignment", "minorRelated", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + if (c["ceasn:prerequisiteAlignment"]) { + createRelations(c, "ceasn:prerequisiteAlignment", "requires", repo, ceasnIdentity, owner, cassRelationships, listToSave); + } + delete c["ceasn:broadAlignment"]; + delete c["ceasn:narrowAlignment"]; + delete c["sameAs"]; + delete c["ceasn:majorAlignment"]; + delete c["ceasn:minorAlignment"]; + delete c["ceasn:prerequisiteAlignment"]; + + if (owner != null) + c.addOwner(EcPk.fromPem(owner)); + listToSave.push(c); + resolve(); + } catch (err) { + global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.ERROR, "CeasnImportCollection", err); + resolve(); + } } async function importCeCollectionToCass(frameworkObj, competencyList) { const nodeDocumentLoader = jsonld.documentLoaders.node(); - const cassContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4")),true); - const ceasn2cassContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json")),true); - const ceasn2cassTerms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cassTerms")),true)); + const cassContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4")), true); + const ceasn2cassContext = JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json")), true); + const ceasn2cassTerms = JSON.parse(JSON.stringify((await httpGet("https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cassTerms")), true)); const customLoader = async (url) => { - if(url === "https://schema.cassproject.org/0.4") { + if (url === "https://schema.cassproject.org/0.4") { return { contextUrl: null, // this is for a context via a link header document: cassContext, // this is the actual document that was loaded documentUrl: url // this is the actual context URL after redirects }; } - if(url === "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json") { + if (url === "https://schema.cassproject.org/0.4/jsonld1.1/ceasn2cass.json") { return { contextUrl: null, // this is for a context via a link header document: ceasn2cassContext, // this is the actual document that was loaded @@ -1770,9 +1751,6 @@ async function importCeCollectionToCass(frameworkObj, competencyList) { ceasnIdentity.displayName = "CEASN Server Identity"; EcIdentityManager.default.addIdentity(ceasnIdentity); - if (false && repoEndpoint().contains("localhost")) - error("Endpoint Configuration is not set.", 500); - var cassCompetencies = []; var cassRelationships = []; var relationshipMap = {}; @@ -1787,8 +1765,8 @@ async function importCeCollectionToCass(frameworkObj, competencyList) { } var listToSave = []; - for (let idx = 0; idx < competencyList.length; idx+=100) { - await Promise.all(competencyList.slice(idx, idx+100).map((comp) => importCompetencyToCollectionPromise(comp, listToSave, cassRelationships, ceasnIdentity, repo, owner, ceasn2cassTerms))); + for (let idx = 0; idx < competencyList.length; idx += 100) { + await Promise.all(competencyList.slice(idx, idx + 100).map((comp) => importCompetencyToCollectionPromise(comp, listToSave, cassRelationships, ceasnIdentity, repo, owner, ceasn2cassTerms))); } if (frameworkObj != null) { @@ -1841,7 +1819,7 @@ async function importCeCollectionToCass(frameworkObj, competencyList) { listToSave.push(f); - await loopback.multiput(repo,listToSave); + await loopback.multiput(repo, listToSave); global.auditLogger.report(global.auditLogger.LogCategory.ADAPTER, global.auditLogger.Severity.INFO, "CeasnImportCollection", listToSave); return f.shortId(); } // end if frameworkObj != null @@ -1855,7 +1833,7 @@ async function ceasnFrameworkToCass() { if (data === undefined || data == null) { data = fileFromDatastream.call(this, "file"); if (data && data.path) { - data = await fsPromises.readFile(data.path, {encoding: 'utf8'}); + data = await fsPromises.readFile(data.path, { encoding: 'utf8' }); } } text = fileToString(data); diff --git a/src/main/server/adapter/openbadges/openbadges.js b/src/main/server/adapter/openbadges/openbadges.js index 22e69dc1e..a372e60a3 100644 --- a/src/main/server/adapter/openbadges/openbadges.js +++ b/src/main/server/adapter/openbadges/openbadges.js @@ -1,9 +1,6 @@ let loopback = require('../../shims/cassproject.js'); badgeSetup = function () { - if (false && repoEndpoint().contains("localhost")) - error("Endpoint Configuration is not set.", 500); - this.setup = true; EcRepository.caching = false; diff --git a/src/main/server/profile/calculator.js b/src/main/server/profile/calculator.js index af8e3fddb..45f4409a7 100644 --- a/src/main/server/profile/calculator.js +++ b/src/main/server/profile/calculator.js @@ -371,13 +371,13 @@ module.exports = class ProfileCalculator { for (let i = 0; i < vertex.children.length; i++) { let prune = pruneNonFrameworkData(vertex.children[i], depth + 1); if (prune.length == 0) { - vertex.children.splice(i--, 1); + vertex.children.splice(i--, 1); // NOSONAR -- This is a method for filtering. } if (prune.length == 1) { vertex.children.splice(i, 1, ...prune); } if (prune.length > 1) { - vertex.children.splice(i--, 1, ...prune); + vertex.children.splice(i--, 1, ...prune); // NOSONAR -- This is a method for filtering. } } if (!EcArray.has(this.framework.competency, vertex.id)) { diff --git a/src/main/server/profile/coprocessors/timeBounding.js b/src/main/server/profile/coprocessors/timeBounding.js index 05751abf8..22e4d3f6d 100644 --- a/src/main/server/profile/coprocessors/timeBounding.js +++ b/src/main/server/profile/coprocessors/timeBounding.js @@ -1,5 +1,5 @@ //Each of these is being called such that using 'this' refers to the profileProcessor. -let fetchAssertions = async function(){ +let fetchAssertions = async function () { let params = this.params; let startDate = null; let endDate = null; @@ -7,14 +7,14 @@ let fetchAssertions = async function(){ startDate = new Date(parseInt(params.startDate)); if (params.endDate != null) endDate = new Date(parseInt(params.endDate)); - if (startDate == null && endDate == null) + if (startDate == null && endDate == null) return; this.cache = false; global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "CassFetchAssertions", "We are time bounding, turning off caching."); } -let insertResources = async function(){ +let insertResources = async function () { } -let processAssertions = async function(){ +let processAssertions = async function () { let params = this.params; let startDate = null; let endDate = null; @@ -22,59 +22,53 @@ let processAssertions = async function(){ startDate = new Date(parseInt(params.startDate)); if (params.endDate != null) endDate = new Date(parseInt(params.endDate)); - if (startDate == null && endDate == null) + if (startDate == null && endDate == null) return; global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "CassProcessAssertions", `Here I am doing additional processing over assertions and removing those that are before ${startDate} or after ${endDate}.`); for (const metaVertexId in this.g.metaVerticies) { const metaVertex = this.g.metaVerticies[metaVertexId]; if (metaVertex.positiveAssertion != null) - for (let index = 0;index < metaVertex.positiveAssertion.length;index++) - { + for (let index = 0; index < metaVertex.positiveAssertion.length; index++) { let assertionDate = await metaVertex.positiveAssertion[index].getAssertionDate(); - if (startDate != null && assertionDate < startDate.getTime()) - { + if (startDate != null && assertionDate < startDate.getTime()) { global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "CassProcessAssertions", `Removing assertion where ${assertionDate} < (startDate)${startDate.getTime()}`); - metaVertex.positiveAssertion.splice(index--,1); + metaVertex.positiveAssertion.splice(index--, 1); // NOSONAR -- Method for filtering. } - else if (endDate != null && endDate.getTime() < assertionDate) - { + else if (endDate != null && endDate.getTime() < assertionDate) { global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "CassProcessAssertions", `Removing assertion where (endDate) ${endDate.getTime()} < ${assertionDate}`); - metaVertex.positiveAssertion.splice(index--,1); + metaVertex.positiveAssertion.splice(index--, 1); // NOSONAR -- Method for filtering. } } if (metaVertex.negativeAssertion != null) - for (let index = 0;index < metaVertex.negativeAssertion.length;index++) - { + for (let index = 0; index < metaVertex.negativeAssertion.length; index++) { let assertionDate = await metaVertex.negativeAssertion[index].getAssertionDate(); - if (startDate != null && assertionDate < startDate.getTime()) - { + if (startDate != null && assertionDate < startDate.getTime()) { global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "CassProcessAssertions", `Removing assertion where ${assertionDate} < (startDate)${startDate.getTime()}`); - metaVertex.negativeAssertion.splice(index--,1); + metaVertex.negativeAssertion.splice(index--, 1); // NOSONAR -- Method for filtering. } - else if (endDate != null && endDate.getTime() < assertionDate) - { + else if (endDate != null && endDate.getTime() < assertionDate) { global.auditLogger.report(global.auditLogger.LogCategory.PROFILE, global.auditLogger.Severity.INFO, "CassProcessAssertions", `Removing assertion where ${(endDate) + endDate.getTime()} < ${assertionDate}`); - metaVertex.negativeAssertion.splice(index--,1); + metaVertex.negativeAssertion.splice(index--, 1); // NOSONAR -- Method for filtering. } } } } -let postProcessStart = async function(vertices,topLevelVertices, inEdges){ -} -let postProcessEachVertex = function(vertex,vertices,topLevelVertices,inEdges){ -} -let postProcessEachEdge = function(edge,vertices,topLevelVertices,inEdges){ +let postProcessStart = async function (vertices, topLevelVertices, inEdges) { } -let postProcessEachEdgeRepeating = function(edge,vertices,topLevelVertices,inEdges){ +let postProcessEachVertex = function (vertex, vertices, topLevelVertices, inEdges) { } -let postProcessEachVertexRepeating = function(vertex,vertices,topLevelVertices,inEdges){ +let postProcessEachEdge = function (edge, vertices, topLevelVertices, inEdges) { } -let postProcessProfileBefore = function(profile,vertices,topLevelVertices,inEdges){ +let postProcessEachEdgeRepeating = function (edge, vertices, topLevelVertices, inEdges) { } -let postProcessProfileEachElement = function(obj,inEdges,vertices,visited){ +let postProcessEachVertexRepeating = function (vertex, vertices, topLevelVertices, inEdges) { +} +let postProcessProfileBefore = function (profile, vertices, topLevelVertices, inEdges) { +} +let postProcessProfileEachElement = function (obj, inEdges, vertices, visited) { return {}; -} -let postProcessProfileAfter = function(o, profile){ +} +let postProcessProfileAfter = function (o, profile) { } module.exports = { diff --git a/src/main/server/shims/cassproject.js b/src/main/server/shims/cassproject.js index 4276aea8b..9c37abed9 100644 --- a/src/main/server/shims/cassproject.js +++ b/src/main/server/shims/cassproject.js @@ -1,98 +1,130 @@ -let frameworkGet = async function(id){ +let frameworkGet = async function (id) { return new Promise( - function(resolve,reject){ + function (resolve, reject) { return EcFramework.get( id, - function(f){resolve(f);}, - function(error){reject(error);}, + function (f) { + resolve(f); + }, + function (error) { + reject(error); + }, repo ); } ); }; -let frameworkSearch = async function(repo,query,params){ +let frameworkSearch = async function (repo, query, params) { return new Promise( - function(resolve,reject){ + function (resolve, reject) { return EcFramework.search( repo, query, - function(fs){resolve(fs)}, - function(error){reject(error)}, + function (fs) { + resolve(fs) + }, + function (error) { + reject(error) + }, params ); } ); }; -let competencyGet = async function(id){ +let competencyGet = async function (id) { return new Promise( - function(resolve,reject){ + function (resolve, reject) { return EcCompetency.get( id, - function(f){resolve(f);}, - function(error){reject(error);}, + function (f) { + resolve(f); + }, + function (error) { + reject(error); + }, repo ); } ); }; -let repositoryGet = async function(id){ +let repositoryGet = async function (id) { return new Promise( - function(resolve,reject){ + function (resolve, reject) { return EcRepository.get( id, - function(f){resolve(f);}, - function(error){reject(error);}, + function (f) { + resolve(f); + }, + function (error) { + reject(error); + }, repo ); } ); }; -let repositorySearch = async function(repo,query,params){ +let repositorySearch = async function (repo, query, params) { return new Promise( - function(resolve,reject){ + function (resolve, reject) { return repo.searchWithParams( query, params, - function(f){}, - function(fs){resolve(fs)}, - function(error){reject(error)}, + function (f) { }, + function (fs) { + resolve(fs) + }, + function (error) { + reject(error) + }, ); } ); }; -let alignmentGet = async function(id){ +let alignmentGet = async function (id) { return new Promise( - function(resolve,reject){ + function (resolve, reject) { return EcAlignment.get( id, - function(f){resolve(f);}, - function(error){reject(error);}, + function (f) { + resolve(f); + }, + function (error) { + reject(error); + }, repo ); } ); }; -let conceptGet = async function(id){ +let conceptGet = async function (id) { return new Promise( - function(resolve,reject){ + function (resolve, reject) { return EcConcept.get( id, - function(f){resolve(f);}, - function(error){reject(error);}, + function (f) { + resolve(f); + }, + function (error) { + reject(error); + }, repo ); } ); }; -let multiput = async function(repo,ary){ +let multiput = async function (repo, ary) { return new Promise( - function(resolve,reject){ + function (resolve, reject) { return repo.multiput( ary, - function(f){resolve(f);}, - function(error){reject(error);} + function (f) { + resolve(f); + }, + function (error) { + reject(error); + } ); } ); diff --git a/src/main/server/shims/levr.js b/src/main/server/shims/levr.js index 219cd4b79..35988329c 100644 --- a/src/main/server/shims/levr.js +++ b/src/main/server/shims/levr.js @@ -580,34 +580,27 @@ if (global.rsaGenerate === undefined) { }; if (global.jsonLdExpand === undefined) { - global.jsonLdExpand = function (json) { - return new Promise(async function (resolve, reject) { - try { - let actual = await jsonld.expand(JSON.parse(json)); - resolve(actual); - } catch (error) { - reject((error)['message']); - return; - } - }); + global.jsonLdExpand = async function (json) { + try { + return await jsonld.expand(JSON.parse(json)); + } catch (error) { + throw (error)['message']; + } }; }; if (global.jsonLdCompact === undefined) { - global.jsonLdCompact = function (actual, finalTargetContext) { - return new Promise(async function (resolve, reject) { - try { - finalTargetContext = JSON.parse(finalTargetContext); - } catch (ex) { } - try { - let o = await jsonld.compact(JSON.parse(actual), finalTargetContext); - (o)['@context'] = finalTargetContext; - resolve(o); - } catch (s) { - reject(s); - return; - } - }); + global.jsonLdCompact = async function (actual, finalTargetContext) { + try { + finalTargetContext = JSON.parse(finalTargetContext); + } catch (ex) { } + try { + let o = await jsonld.compact(JSON.parse(actual), finalTargetContext); + (o)['@context'] = finalTargetContext; + return o; + } catch (s) { + throw s; + } }; }; @@ -631,7 +624,7 @@ if (global.jsonLdCompact === undefined) { const $rdf = require('rdflib'); if (global.jsonLdToRdfXml === undefined) { global.jsonLdToRdfXml = function (o) { - return new Promise(async function (resolve, reject) { + return new Promise(async function (resolve, reject) { // NOSONAR -- Blends async and callback, which needs direct promise access. let rdf = await jsonld.toRDF(o, { format: 'application/n-quads' }); let store = $rdf.graph(); $rdf.parse(rdf, store, 'whatever', 'application/n-quads', (err, str) => { @@ -648,12 +641,11 @@ if (global.jsonLdToTurtle === undefined) { }; toTurtleInternal = function (o) { - return new Promise(async function (resolve, reject) { + return new Promise(async function (resolve, reject) { // NOSONAR -- Blends async and callback, which needs direct promise access. let rdf = await jsonld.toRDF(o, { format: 'application/n-quads' }); let store = $rdf.graph(); $rdf.parse(rdf, store, 'whatever', 'application/n-quads', (err, str) => { - let result = ($rdf.serialize(null, str, '*', 'text/turtle')); - resolve(result); + resolve($rdf.serialize(null, str, '*', 'text/turtle')); }); }); }; diff --git a/src/main/server/skyRepo.js b/src/main/server/skyRepo.js index fb359d72f..e7e14c0be 100644 --- a/src/main/server/skyRepo.js +++ b/src/main/server/skyRepo.js @@ -212,7 +212,7 @@ const filterResults = async function (o, dontDecryptInSso) { resolve(filterResults.call(me, x, dontDecryptInSso)); } catch (ex) { if (ex != null && ex.toString().indexOf('Object not found or you did not supply sufficient permissions to access the object.') == -1) { - reject(ex); + reject(ex); // NOSONAR -- Rethrowing error. } resolve(null); } @@ -9099,7 +9099,7 @@ global.skyrepoHistoryInternal = async function (id, version, type) { if (Bts == null) Bts = hits[j]._source.writeMs; // console.log(Ats, Bts); if (A.id + Ats == B.id + Bts) { - hits.splice(j--, 1); + hits.splice(j--, 1); // NOSONAR -- Valid method of filtering. } } } @@ -9484,7 +9484,7 @@ const skyrepoSearch = async function (q, urlRemainder, start, size, sort, track_ const searchResult = hits[i]; const type = inferTypeFromObj((searchResult)['_source'], null); if (type == null) { - hits.splice(i--, 1); + hits.splice(i--, 1); // NOSONAR -- Valid method of filtering. continue; } const id = (searchResult)['_id']; diff --git a/src/main/server/skyRepo.test.js b/src/main/server/skyRepo.test.js index 751477b83..0471381be 100644 --- a/src/main/server/skyRepo.test.js +++ b/src/main/server/skyRepo.test.js @@ -33,7 +33,7 @@ describe('SkyRepo Adapter', function() { // Wipe and create second repo link to alternate url. EcRepository.repos = []; const repo2 = new EcRepository(); - await repo2.init(process.env.CASS_LOOPBACK || `http://127.0.0.1:${PORT}/api/`); + await repo2.init(process.env.CASS_LOOPBACK || `http://127.0.0.1:${process.env.PORT || 80}/api/`); // Get from repo2. Falls back to search (in error case); const thingCopy2 = await EcRepository.get(canonicalUrl);