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

7
app.js
View File

@@ -7,7 +7,7 @@ import {
updateOvoNumberAndUri, updateOvoNumberAndUri,
createNewKboOrg, createNewKboOrg,
linkAbbOrgToKboOrg, linkAbbOrgToKboOrg,
getKboOrgnizationInfo, getKboOrganizationInfo,
updateKboOrg, updateKboOrg,
getAllAbbKboOrganizations, getAllAbbKboOrganizations,
} from "./lib/queries"; } 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 // 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 wegwijsInfo = data[0]; // Wegwijs should only have only one entry per KBO
const kboObject = getKboFields(wegwijsInfo); const kboObject = getKboFields(wegwijsInfo);
const kboIdentifiers = await getKboOrgnizationInfo( const kboIdentifiers = await getKboOrganizationInfo(
abbOrganizationInfo.adminUnit abbOrganizationInfo.adminUnit
); );
@@ -52,6 +52,7 @@ app.post("/sync-kbo-data/:kboStructuredIdUuid", async function (req, res) {
abbOrganizationInfo.kboId, abbOrganizationInfo.kboId,
abbOrganizationInfo.adminUnit abbOrganizationInfo.adminUnit
); );
} }
if (isUpdateNeeded(kboObject, kboIdentifiers)) { if (isUpdateNeeded(kboObject, kboIdentifiers)) {
@@ -217,7 +218,7 @@ async function healAbbWithWegWijsData() {
} }
if (isUpdateNeeded(wegwijsKboOrg, kboIdentifierOP)) { if (isUpdateNeeded(wegwijsKboOrg, kboIdentifierOP)) {
const kboIdentifiers = await getKboOrgnizationInfo( const kboIdentifiers = await getKboOrganizationInfo(
kboIdentifierOP.abbOrg kboIdentifierOP.abbOrg
); );
await updateKboOrg(wegwijsKboOrg, kboIdentifiers); 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) { export async function getAbbOrganizationInfo(kboStructuredIdUuid) {
const queryStr = ` const queryStr = `
SELECT DISTINCT ?kbo ?kboId ?ovo ?kboStructuredId ?ovoStructuredId ?bestuurseenheid WHERE { SELECT DISTINCT ?kbo ?kboId ?ovo ?kboStructuredId ?ovoStructuredId ?organization WHERE {
VALUES ?g { VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit> <http://mu.semte.ch/graphs/administrative-unit>
<http://mu.semte.ch/graphs/worship-service> <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 ; ?kboId <https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ?kboStructuredId ;
<http://www.w3.org/2004/02/skos/core#notation> ?kboNotation . <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")) FILTER (?kboNotation IN ("KBO nummer"@nl, "KBO nummer"))
OPTIONAL { 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 ; ?ovoId <https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ?ovoStructuredId ;
<http://www.w3.org/2004/02/skos/core#notation> ?ovoNotation . <http://www.w3.org/2004/02/skos/core#notation> ?ovoNotation .
@@ -46,28 +46,28 @@ export async function getAbbOrganizationInfo(kboStructuredIdUuid) {
ovo: binding.ovo?.value, ovo: binding.ovo?.value,
ovoStructuredId: binding.ovoStructuredId?.value, ovoStructuredId: binding.ovoStructuredId?.value,
kboId: binding.kboId?.value, kboId: binding.kboId?.value,
adminUnit: binding.bestuurseenheid.value, adminUnit: binding.organization.value,
}; };
} }
return null; return null;
} }
export async function getKboOrgnizationInfo(administrativeUnit) { export async function getKboOrganizationInfo(administrativeUnit) {
const queryStr = ` const queryStr = `
SELECT DISTINCT ?kboUnit ?abbUnit ?changeTime ?contactPointUri ?addressUri WHERE { SELECT DISTINCT ?kboOrg ?abbUnit ?changeTime ?contactPointUri ?addressUri WHERE {
VALUES ?g { VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit> <http://mu.semte.ch/graphs/administrative-unit>
<http://mu.semte.ch/graphs/worship-service> <http://mu.semte.ch/graphs/worship-service>
} }
GRAPH ?g { 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://mu.semte.ch/vocabularies/core/uuid> ?uuid ;
<http://schema.org/contactPoint> ?contactPointUri ; <http://schema.org/contactPoint> ?contactPointUri ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime . <https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime .
?contactPointUri <http://www.w3.org/ns/locn#address> ?addressUri . ?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)}) FILTER(?abbUnit = ${sparqlEscapeUri(administrativeUnit)})
} }
@@ -79,7 +79,7 @@ export async function getKboOrgnizationInfo(administrativeUnit) {
if (result.results.bindings.length) { if (result.results.bindings.length) {
const binding = result.results.bindings[0]; const binding = result.results.bindings[0];
return { return {
kboUnit: binding.kboUnit?.value, kboOrg: binding.kboOrg?.value,
abbUnit: binding.abbUnit?.value, abbUnit: binding.abbUnit?.value,
changeTime: binding.changeTime?.value, changeTime: binding.changeTime?.value,
contactPointUri: binding.contactPointUri?.value, contactPointUri: binding.contactPointUri?.value,
@@ -98,7 +98,7 @@ export async function constructOvoStructure(kboStructuredId) {
const updateStr = ` const updateStr = `
INSERT { INSERT {
GRAPH ?g { GRAPH ?g {
?bestuurseenheid <http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri( ?organization <http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri(
idUri idUri
)} . )} .
@@ -134,7 +134,7 @@ export async function constructOvoStructure(kboStructuredId) {
)} ; )} ;
<http://www.w3.org/2004/02/skos/core#notation> ?notation . <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")) 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 . ?abbOrg <http://www.w3.org/ns/adms#identifier> ?kboId .
FILTER (?kboNotation IN ("KBO nummer"@nl, "KBO nummer")) FILTER (?kboNotation IN ("KBO nummer"@nl, "KBO nummer"))
FILTER (!regex(?abbOrg, "kboBestuurseenheden","i")) FILTER (!regex(?abbOrg, "kboOrganisaties","i"))
OPTIONAL{ OPTIONAL{
?kboOrg owl:sameAs ?abbOrg . ?kboOrg owl:sameAs ?abbOrg .
@@ -276,9 +276,9 @@ export async function getAllAbbKboOrganizations() {
return null; return null;
} }
export async function createNewKboOrg(kboOrg, kboId) { export async function createNewKboOrg(kboOrg, kboId, kboStructuredId) {
const newKboOrgIdUuId = uuid(); 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 contactPointUuidId = uuid();
const contactPointUri = `http://data.lblod.info/id/contact-punten/${contactPointUuidId}`; const contactPointUri = `http://data.lblod.info/id/contact-punten/${contactPointUuidId}`;
@@ -328,7 +328,7 @@ export async function createNewKboOrg(kboOrg, kboId) {
updateStr += ` ${sparqlEscapeUri( updateStr += ` ${sparqlEscapeUri(
newKboIdUri 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( <http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(
newKboOrgIdUuId newKboOrgIdUuId
)}`; )}`;
@@ -377,8 +377,11 @@ export async function createNewKboOrg(kboOrg, kboId) {
<http://mu.semte.ch/graphs/administrative-unit> <http://mu.semte.ch/graphs/administrative-unit>
<http://mu.semte.ch/graphs/worship-service> <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 //update ContactPoint
await updateKboContact(newKboInfo, identifiers); await updateKboContact(newKboInfo, identifiers);
//update kboUnit //update kboOrg
await updateKboAdministrativeUnit(newKboInfo, identifiers); await updateKboOrganization(newKboInfo, identifiers);
} }
export async function linkAbbOrgToKboOrg(abbOrgUri, kboOrgUri) { export async function linkAbbOrgToKboOrg(abbOrgUri, kboOrgUri) {
@@ -414,7 +417,7 @@ export async function linkAbbOrgToKboOrg(abbOrgUri, kboOrgUri) {
${sparqlEscapeUri( ${sparqlEscapeUri(
kboOrgUri 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); await update(updateStr);
} }
async function updateKboAdministrativeUnit(newKboInfo, identifiers) { async function updateKboOrganization(newKboInfo, identifiers) {
let updateStr = ` let updateStr = `
DELETE{ DELETE{
GRAPH ?g{ 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://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ; <http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ;
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ; <http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
@@ -530,7 +533,7 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) {
} }
INSERT{ INSERT{
graph ?g{ graph ?g{
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ?kboOrg a <http://mu.semte.ch/vocabularies/ext/KboOrganisatie>
`; `;
if (newKboInfo.rechtsvorm) { if (newKboInfo.rechtsvorm) {
updateStr += ` updateStr += `
@@ -585,7 +588,7 @@ async function updateKboAdministrativeUnit(newKboInfo, identifiers) {
<http://mu.semte.ch/graphs/administrative-unit> <http://mu.semte.ch/graphs/administrative-unit>
} }
GRAPH ?g { 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://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ; <http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ;
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ; <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 ; <https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
<http://www.w3.org/ns/regorg#orgStatus> ?activeState . <http://www.w3.org/ns/regorg#orgStatus> ?activeState .
FILTER(?kboUnit = ${sparqlEscapeUri(identifiers.kboUnit)}) FILTER(?kboOrg = ${sparqlEscapeUri(identifiers.kboOrg)})
} }
} }
`; `;