Compare commits

..

2 Commits

Author SHA1 Message Date
Elias Papanikitas
0d9fc97995 removed line from testing 2024-03-26 17:30:25 +01:00
Elias Papanikitas
0baaec1614 updated queries to for namechange kboEenheid to kboOrganisatie 2024-03-26 17:27:26 +01:00
2 changed files with 34 additions and 30 deletions

11
app.js
View File

@@ -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
);
}
}
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);

View File

@@ -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 {
<http://mu.semte.ch/graphs/administrative-unit>
<http://mu.semte.ch/graphs/worship-service>
@@ -18,12 +18,12 @@ export async function getAbbOrganizationInfo(kboStructuredIdUuid) {
?kboId <https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ?kboStructuredId ;
<http://www.w3.org/2004/02/skos/core#notation> ?kboNotation .
?bestuurseenheid <http://www.w3.org/ns/adms#identifier> ?kboId .
?organization <http://www.w3.org/ns/adms#identifier> ?kboId .
FILTER (?kboNotation IN ("KBO nummer"@nl, "KBO nummer"))
OPTIONAL {
?bestuurseenheid <http://www.w3.org/ns/adms#identifier> ?ovoId .
?organization <http://www.w3.org/ns/adms#identifier> ?ovoId .
?ovoId <https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ?ovoStructuredId ;
<http://www.w3.org/2004/02/skos/core#notation> ?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 {
<http://mu.semte.ch/graphs/administrative-unit>
<http://mu.semte.ch/graphs/worship-service>
}
GRAPH ?g {
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
?kboOrg a <http://mu.semte.ch/vocabularies/ext/KboOrganisatie> ;
<http://mu.semte.ch/vocabularies/core/uuid> ?uuid ;
<http://schema.org/contactPoint> ?contactPointUri ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime .
?contactPointUri <http://www.w3.org/ns/locn#address> ?addressUri .
?kboUnit <http://www.w3.org/2002/07/owl#sameAs> ?abbUnit
?kboOrg <http://www.w3.org/2002/07/owl#sameAs> ?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 <http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri(
?organization <http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri(
idUri
)} .
@@ -134,7 +134,7 @@ export async function constructOvoStructure(kboStructuredId) {
)} ;
<http://www.w3.org/2004/02/skos/core#notation> ?notation .
?bestuurseenheid <http://www.w3.org/ns/adms#identifier> ?kboId .
?organization <http://www.w3.org/ns/adms#identifier> ?kboId .
FILTER (?notation IN ("KBO nummer"@nl, "KBO nummer"))
}
@@ -221,7 +221,7 @@ export async function getAllAbbKboOrganizations() {
?abbOrg <http://www.w3.org/ns/adms#identifier> ?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 <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
)} a <http://mu.semte.ch/vocabularies/ext/KboOrganisatie> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(
newKboOrgIdUuId
)}`;
@@ -377,8 +377,11 @@ export async function createNewKboOrg(kboOrg, kboId) {
<http://mu.semte.ch/graphs/administrative-unit>
<http://mu.semte.ch/graphs/worship-service>
}
GRAPH ?g {
?organization <http://www.w3.org/ns/adms#identifier> ${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 <http://mu.semte.ch/vocabularies/ext/KboEenheid> .
)} a <http://mu.semte.ch/vocabularies/ext/KboOrganisatie> .
}
`;
@@ -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 <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
?kboOrg a <http://mu.semte.ch/vocabularies/ext/KboOrganisatie> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ;
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
@@ -530,7 +533,7 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) {
}
INSERT{
graph ?g{
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid>
?kboOrg a <http://mu.semte.ch/vocabularies/ext/KboOrganisatie>
`;
if (newKboInfo.rechtsvorm) {
updateStr += `
@@ -585,7 +588,7 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) {
<http://mu.semte.ch/graphs/administrative-unit>
}
GRAPH ?g {
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
?kboOrg a <http://mu.semte.ch/vocabularies/ext/KboOrganisatie> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ;
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
@@ -593,7 +596,7 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) {
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
<http://www.w3.org/ns/regorg#orgStatus> ?activeState .
FILTER(?kboUnit = ${sparqlEscapeUri(identifiers.kboUnit)})
FILTER(?kboOrg = ${sparqlEscapeUri(identifiers.kboOrg)})
}
}
`;