Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d9fc97995 | ||
|
|
0baaec1614 | ||
|
|
1caab1e7ba | ||
|
|
121a95e8b3 |
11
app.js
11
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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -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,18 +221,17 @@ 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 .
|
||||
?kboOrg <https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
|
||||
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVrom ;
|
||||
<http://mu.semte.ch/vocabularies/ext/shortName> ?shortName ;
|
||||
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
|
||||
<http://www.w3.org/2004/02/skos/core#prefLabel> ?commercialName ;
|
||||
<http://www.w3.org/2004/02/skos/core#altLabel> ?legalName ;
|
||||
<http://www.w3.org/ns/regorg#orgStatus> ?activeState ;
|
||||
<http://schema.org/contactPoint> ?contact .
|
||||
<http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ;
|
||||
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
|
||||
<http://www.w3.org/ns/regorg#legalName> ?legalName ;
|
||||
<http://www.w3.org/ns/regorg#orgStatus> ?activeState ;
|
||||
<http://schema.org/contactPoint> ?contact .
|
||||
|
||||
?contact <http://schema.org/email> ?email ;
|
||||
<http://schema.org/telephone> ?phone ;
|
||||
@@ -277,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}`;
|
||||
@@ -329,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
|
||||
)}`;
|
||||
@@ -378,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
|
||||
)}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -394,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) {
|
||||
@@ -415,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> .
|
||||
|
||||
}
|
||||
`;
|
||||
@@ -431,6 +433,7 @@ async function updateKboAddress(newKboInfo, identifiers) {
|
||||
?adressUri a <http://www.w3.org/ns/locn#Address> ;
|
||||
<http://www.w3.org/ns/locn#fullAddress> ?fulladdress .
|
||||
}
|
||||
}
|
||||
INSERT{
|
||||
graph ?g{
|
||||
?adressUri a <http://www.w3.org/ns/locn#Address>
|
||||
@@ -515,23 +518,22 @@ 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://mu.semte.ch/vocabularies/ext/shortName> ?shortName ;
|
||||
<http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ;
|
||||
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
|
||||
<http://www.w3.org/2004/02/skos/core#prefLabel> ?orgName ;
|
||||
<http://www.w3.org/2004/02/skos/core#altLabel> ?commercialName ;
|
||||
<http://www.w3.org/ns/regorg#legalName> ?orgName ;
|
||||
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
|
||||
<http://www.w3.org/ns/regorg#orgStatus> ?activeState .
|
||||
}
|
||||
}
|
||||
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 += `
|
||||
@@ -586,16 +588,15 @@ 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://mu.semte.ch/vocabularies/ext/shortName> ?shortName ;
|
||||
<http://www.w3.org/2004/02/skos/core#altLabel> ?shortName ;
|
||||
<http://mu.semte.ch/vocabularies/ext/startDate> ?startDate ;
|
||||
<http://www.w3.org/2004/02/skos/core#prefLabel> ?orgName ;
|
||||
<http://www.w3.org/2004/02/skos/core#altLabel> ?commercialName ;
|
||||
<http://www.w3.org/ns/regorg#legalName> ?orgName ;
|
||||
<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)})
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user