diff --git a/app.js b/app.js index 5687dc3..5416cd3 100644 --- a/app.js +++ b/app.js @@ -7,7 +7,7 @@ import { updateOvoNumberAndUri, createNewKboOrg, linkAbbOrgToKboOrg, - getKboOrgnizationInfo, + getKboOrganizationInfo, updateKboOrg, getAllAbbKboOrganizations, } from "./lib/queries"; @@ -42,7 +42,7 @@ app.post("/sync-kbo-data/:kboStructuredIdUuid", async function (req, res) { // We got a match on the KBO, getting the associated OVO back const wegwijsInfo = data[0]; // Wegwijs should only have only one entry per KBO const kboObject = getKboFields(wegwijsInfo); - const kboIdentifiers = await getKboOrgnizationInfo( + const kboIdentifiers = await getKboOrganizationInfo( abbOrganizationInfo.adminUnit ); @@ -52,8 +52,9 @@ app.post("/sync-kbo-data/:kboStructuredIdUuid", async function (req, res) { abbOrganizationInfo.kboId, abbOrganizationInfo.adminUnit ); - } + } + await healAbbWithWegWijsData(); if (isUpdateNeeded(kboObject, kboIdentifiers)) { await updateKboOrg(kboObject, kboIdentifiers); } @@ -71,7 +72,7 @@ app.post("/sync-kbo-data/:kboStructuredIdUuid", async function (req, res) { } await updateOvoNumberAndUri(ovoStructuredIdUri, wegwijsOvo); } - + return setServerStatus(API_STATUS_CODES.OK, res); // since we await, it should be 200 } catch (e) { return setServerStatus(API_STATUS_CODES.CUSTOM_SERVER_ERROR, res, e); @@ -217,7 +218,7 @@ async function healAbbWithWegWijsData() { } if (isUpdateNeeded(wegwijsKboOrg, kboIdentifierOP)) { - const kboIdentifiers = await getKboOrgnizationInfo( + const kboIdentifiers = await getKboOrganizationInfo( kboIdentifierOP.abbOrg ); await updateKboOrg(wegwijsKboOrg, kboIdentifiers); diff --git a/lib/queries.js b/lib/queries.js index bd0d7e2..d794a12 100644 --- a/lib/queries.js +++ b/lib/queries.js @@ -3,7 +3,7 @@ import { querySudo as query, updateSudo as update } from "@lblod/mu-auth-sudo"; export async function getAbbOrganizationInfo(kboStructuredIdUuid) { const queryStr = ` - SELECT DISTINCT ?kbo ?kboId ?ovo ?kboStructuredId ?ovoStructuredId ?bestuurseenheid WHERE { + SELECT DISTINCT ?kbo ?kboId ?ovo ?kboStructuredId ?ovoStructuredId ?organization WHERE { VALUES ?g { @@ -18,12 +18,12 @@ export async function getAbbOrganizationInfo(kboStructuredIdUuid) { ?kboId ?kboStructuredId ; ?kboNotation . - ?bestuurseenheid ?kboId . + ?organization ?kboId . FILTER (?kboNotation IN ("KBO nummer"@nl, "KBO nummer")) OPTIONAL { - ?bestuurseenheid ?ovoId . + ?organization ?ovoId . ?ovoId ?ovoStructuredId ; ?ovoNotation . @@ -46,28 +46,28 @@ export async function getAbbOrganizationInfo(kboStructuredIdUuid) { ovo: binding.ovo?.value, ovoStructuredId: binding.ovoStructuredId?.value, kboId: binding.kboId?.value, - adminUnit: binding.bestuurseenheid.value, + adminUnit: binding.organization.value, }; } return null; } -export async function getKboOrgnizationInfo(administrativeUnit) { +export async function getKboOrganizationInfo(administrativeUnit) { const queryStr = ` - SELECT DISTINCT ?kboUnit ?abbUnit ?changeTime ?contactPointUri ?addressUri WHERE { + SELECT DISTINCT ?kboOrg ?abbUnit ?changeTime ?contactPointUri ?addressUri WHERE { VALUES ?g { } GRAPH ?g { - ?kboUnit a ; + ?kboOrg a ; ?uuid ; ?contactPointUri ; ?changeTime . ?contactPointUri ?addressUri . - ?kboUnit ?abbUnit + ?kboOrg ?abbUnit FILTER(?abbUnit = ${sparqlEscapeUri(administrativeUnit)}) } @@ -79,7 +79,7 @@ export async function getKboOrgnizationInfo(administrativeUnit) { if (result.results.bindings.length) { const binding = result.results.bindings[0]; return { - kboUnit: binding.kboUnit?.value, + kboOrg: binding.kboOrg?.value, abbUnit: binding.abbUnit?.value, changeTime: binding.changeTime?.value, contactPointUri: binding.contactPointUri?.value, @@ -98,7 +98,7 @@ export async function constructOvoStructure(kboStructuredId) { const updateStr = ` INSERT { GRAPH ?g { - ?bestuurseenheid ${sparqlEscapeUri( + ?organization ${sparqlEscapeUri( idUri )} . @@ -134,7 +134,7 @@ export async function constructOvoStructure(kboStructuredId) { )} ; ?notation . - ?bestuurseenheid ?kboId . + ?organization ?kboId . FILTER (?notation IN ("KBO nummer"@nl, "KBO nummer")) } @@ -221,7 +221,7 @@ export async function getAllAbbKboOrganizations() { ?abbOrg ?kboId . FILTER (?kboNotation IN ("KBO nummer"@nl, "KBO nummer")) - FILTER (!regex(?abbOrg, "kboBestuurseenheden","i")) + FILTER (!regex(?abbOrg, "kboOrganisaties","i")) OPTIONAL{ ?kboOrg owl:sameAs ?abbOrg . @@ -276,9 +276,9 @@ export async function getAllAbbKboOrganizations() { return null; } -export async function createNewKboOrg(kboOrg, kboId) { +export async function createNewKboOrg(kboOrg, kboId, kboStructuredId) { const newKboOrgIdUuId = uuid(); - const newKboIdUri = `http://data.lblod.info/id/kboBestuurseenheden/${newKboOrgIdUuId}`; + const newKboIdUri = `http://data.lblod.info/id/kboOrganisaties/${newKboOrgIdUuId}`; const contactPointUuidId = uuid(); const contactPointUri = `http://data.lblod.info/id/contact-punten/${contactPointUuidId}`; @@ -328,7 +328,7 @@ export async function createNewKboOrg(kboOrg, kboId) { updateStr += ` ${sparqlEscapeUri( newKboIdUri - )} a ; + )} a ; ${sparqlEscapeString( newKboOrgIdUuId )}`; @@ -377,8 +377,11 @@ export async function createNewKboOrg(kboOrg, kboId) { } - - + GRAPH ?g { + ?organization ${sparqlEscapeUri( + kboId + )} + } } `; @@ -393,8 +396,8 @@ export async function updateKboOrg(newKboInfo, identifiers) { //update ContactPoint await updateKboContact(newKboInfo, identifiers); - //update kboUnit - await updateKboAdministrativeUnit(newKboInfo, identifiers); + //update kboOrg + await updateKboOrganization(newKboInfo, identifiers); } export async function linkAbbOrgToKboOrg(abbOrgUri, kboOrgUri) { @@ -414,7 +417,7 @@ export async function linkAbbOrgToKboOrg(abbOrgUri, kboOrgUri) { ${sparqlEscapeUri( kboOrgUri - )} a . + )} a . } `; @@ -515,11 +518,11 @@ WHERE{ `; await update(updateStr); } -async function updateKboAdministrativeUnit(newKboInfo, identifiers) { +async function updateKboOrganization(newKboInfo, identifiers) { let updateStr = ` DELETE{ GRAPH ?g{ - ?kboUnit a ; + ?kboOrg a ; ?rechtsVorm ; ?shortName ; ?startDate ; @@ -530,7 +533,7 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) { } INSERT{ graph ?g{ - ?kboUnit a + ?kboOrg a `; if (newKboInfo.rechtsvorm) { updateStr += ` @@ -585,7 +588,7 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) { } GRAPH ?g { - ?kboUnit a ; + ?kboOrg a ; ?rechtsVorm ; ?shortName ; ?startDate ; @@ -593,7 +596,7 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) { ?changeTime ; ?activeState . - FILTER(?kboUnit = ${sparqlEscapeUri(identifiers.kboUnit)}) + FILTER(?kboOrg = ${sparqlEscapeUri(identifiers.kboOrg)}) } } `;