updating/cron job fixed

This commit is contained in:
Elias Papanikitas
2024-02-23 08:30:56 +01:00
parent 9c421e426b
commit c0f99d7621
2 changed files with 396 additions and 85 deletions

129
app.js
View File

@@ -6,10 +6,11 @@ import {
constructOvoStructure,
updateOvoNumberAndUri,
getAllOvoAndKboCouples,
createKboOrganisation,
createNewKboOrg,
linkAbbOrgToKboOrg,
getKboIdentifiers,
updateKboOrg,
getAllAbbKboOrganizations,
} from "./lib/queries";
import { CRON_PATTERN, ORGANIZATION_STATUS } from "./config";
@@ -40,19 +41,34 @@ app.post(
if (createKbo && kboObject) {
//create kbo organisation
let kboOrg = null;
let kboOrg = null;
const kboIdentifiers = await getKboIdentifiers(identifiers.adminUnit);
let update = false;
if (kboIdentifiers) {
update = new Date(kboObject.changeTime).getTime() < new Date(kboIdentifiers.changeTime).getTime() ? true : false;
}
if(!kboIdentifiers || update){
update =
new Date(kboObject.changeTime).getTime() >
new Date(kboIdentifiers.changeTime).getTime()
? true
: false;
}
if (!kboIdentifiers) {
kboOrg = await createNewKboOrg(kboObject, identifiers.kboId);
await linkAbbOrgToKboOrg(identifiers.adminUnit, kboOrg);
}
if (update) {
updateKboOrg(kboObject, kboIdentifiers);
}
return res.status(200).send();
}
console.log("testing healing of kbo organizations");
await healKboUnits();
console.log("end of test");
//Update Ovo Number
if (wegwijsOvo && wegwijsOvo != identifiers.ovo) {
console.log(identifiers.ovo);
@@ -95,10 +111,14 @@ function getKboFields(data) {
return fields.labelTypeId === "83c1c22a-6776-0ad6-68d2-819e1c6eec66";
})
.pop()?.validity?.start;
let activeState = (data.labels
?.filter((fields) => {
return fields.labelTypeId === "83c1c22a-6776-0ad6-68d2-819e1c6eec66" && !fields.validity.hasOwnProperty("end");
}) ? ORGANIZATION_STATUS.ACTIVE : ORGANIZATION_STATUS.INACTIVE)
let activeState = data.labels?.filter((fields) => {
return (
fields.labelTypeId === "83c1c22a-6776-0ad6-68d2-819e1c6eec66" &&
!fields.validity.hasOwnProperty("end")
);
})
? ORGANIZATION_STATUS.ACTIVE
: ORGANIZATION_STATUS.INACTIVE;
let email = data.contacts
?.filter((fields) => {
return (
@@ -147,28 +167,34 @@ function getKboFields(data) {
let adressComponent = data.locations
?.filter((fields) => {
return (
fields.locationTypeId === '537c0b5b-8ab8-fc3d-0b37-f8249cbdd3ba' &&
fields.locationTypeId === "537c0b5b-8ab8-fc3d-0b37-f8249cbdd3ba" &&
!fields.validity?.hasOwnProperty("end")
);
})
.pop()?.components;
return {
changeTime: (changeTime ? changeTime : " "),
organisationName: (organisationName ? organisationName : " "),
shortName: (shortName ? shortName : organisationName),
ovoNumber: (ovoNumber ? ovoNumber : " "),
kboNumber: (kboNumber ? kboNumber : " "),
formalName: (formalName ? formalName : " "),
startDate: (startDate ? startDate : " "),
changeTime: changeTime ? changeTime : " ",
organisationName: organisationName
? organisationName
: "Geen gegevens opgenomen in KBO",
shortName: shortName ? shortName : organisationName,
ovoNumber: ovoNumber ? ovoNumber : "Geen gegevens opgenomen in KBO",
kboNumber: kboNumber ? kboNumber : "Geen gegevens opgenomen in KBO",
formalName: formalName ? formalName : "Geen gegevens opgenomen in KBO",
startDate: startDate ? startDate : "Geen gegevens opgenomen in KBO",
activeState: activeState,
rechtsvorm: (rechtsvorm ? rechtsvorm : " "),
email: (email ? email : " "),
phone: (phone ? phone : " "),
website: (website ? website : " "),
province: (province ? province : " "),
formattedAddress: (formattedAddress ? formattedAddress : " "),
adressComponent: (adressComponent ? adressComponent : " "),
rechtsvorm: rechtsvorm ? rechtsvorm : "Geen gegevens opgenomen in KBO",
email: email ? email : "Geen gegevens opgenomen in KBO",
phone: phone ? phone : "Geen gegevens opgenomen in KBO",
website: website ? website : "Geen gegevens opgenomen in KBO",
province: province ? province : "Geen gegevens opgenomen in KBO",
formattedAddress: formattedAddress
? formattedAddress
: "Geen gegevens opgenomen in KBO",
adressComponent: adressComponent
? adressComponent
: "Geen gegevens opgenomen in KBO",
};
}
@@ -179,6 +205,7 @@ new CronJob(
console.log(`OVO numbers healing triggered by cron job at ${now}`);
try {
await healOvoNumbers();
await healKboUnits();
} catch (err) {
console.log(
`An error occurred during OVO numbers healing at ${now}: ${err}`
@@ -191,9 +218,11 @@ new CronJob(
async function healOvoNumbers() {
try {
console.log("Healing starting...");
console.log("Healing ovo starting...");
const identifiersCouplesOP = await getAllOvoAndKboCouples();
const identifiersCouplesWegwijs = await getAllOvoAndKboCouplesWegwijs();
const identifiersCouplesWegwijs = await getAllOvoAndKboCouplesWegwijs(
false
);
for (const identifiersCoupleOP of identifiersCouplesOP) {
const wegwijsOvo = identifiersCouplesWegwijs[identifiersCoupleOP.kbo];
@@ -217,11 +246,48 @@ async function healOvoNumbers() {
}
}
async function getAllOvoAndKboCouplesWegwijs() {
async function healKboUnits() {
try {
console.log("Healing kbo starting...");
const kboIdentifiersOP = await getAllAbbKboOrganizations();
const kboIdentifiersWegwijs = await getAllOvoAndKboCouplesWegwijs(true);
let update = false;
for (const kboIdentifierOP of kboIdentifiersOP) {
const wegwijsKboOrg = kboIdentifiersWegwijs[kboIdentifierOP.kbo];
if (wegwijsKboOrg) {
if (!kboIdentifierOP.kboOrg) {
console.log("creating new kbo unit");
let newKboOrgUri = await createNewKboOrg(wegwijsKboOrg, kboIdentifierOP.kboId);
console.log("linking kbo to abb unit");
await linkAbbOrgToKboOrg(kboIdentifierOP.abbOrg, newKboOrgUri);
}
if (kboIdentifierOP.changeTime) {
update = new Date(kboObject.changeTime).getTime() > new Date(kboIdentifiers.changeTime).getTime() ? true : false;
}
if (update) {
const kboIdentifiers = await getKboIdentifiers(identifiers.adminUnit);
updateKboOrg(wegwijsKboOrg, kboIdentifiers);
}
}
}
console.log("Healing complete!");
} catch (err) {
console.log(`An error occurred during KBO organization healing: ${err}`);
}
}
async function getAllOvoAndKboCouplesWegwijs(healKboUnit) {
let couples = {};
const response = await fetch(
`https://api.wegwijs.vlaanderen.be/v1/search/organisations?q=kboNumber:/.*[0-9].*/&fields=ovoNumber,kboNumber&scroll=true`
`https://api.wegwijs.vlaanderen.be/v1/search/organisations?q=kboNumber:/.*[0-9].*/&changeTime,name,shortName,ovoNumber,kboNumber,labels,contacts,organisationClassifications,locations,parents&scroll=true`
);
const scrollId = JSON.parse(
response.headers.get("x-search-metadata")
@@ -230,7 +296,12 @@ async function getAllOvoAndKboCouplesWegwijs() {
do {
data.forEach((unit) => {
couples[unit.kboNumber] = unit.ovoNumber;
const wegwijsUnit = getKboFields(unit);
if (healKboUnit) {
couples[wegwijsUnit.kboNumber] = wegwijsUnit;
} else {
couples[wegwijsUnit.kboNumber] = wegwijsUnit.ovoNumber;
}
});
const response = await fetch(

View File

@@ -1,5 +1,5 @@
import { uuid, sparqlEscapeUri, sparqlEscapeString } from "mu";
import { querySudo as query, updateSudo as update } from '@lblod/mu-auth-sudo';
import { querySudo as query, updateSudo as update } from "@lblod/mu-auth-sudo";
export async function getIdentifiers(kboStructuredIdUuid) {
const queryStr = `
@@ -10,7 +10,9 @@ export async function getIdentifiers(kboStructuredIdUuid) {
}
GRAPH ?g {
?kboStructuredId a <https://data.vlaanderen.be/ns/generiek#GestructureerdeIdentificator> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(kboStructuredIdUuid)} ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(
kboStructuredIdUuid
)} ;
<https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ?kbo .
?kboId <https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ?kboStructuredId ;
@@ -46,13 +48,13 @@ export async function getIdentifiers(kboStructuredIdUuid) {
ovoStructuredId: binding.ovoStructuredId?.value,
kboId: binding.kboId?.value,
adminUnit: binding.bestuurseenheid.value,
kboUnit: binding.kboOrganisation?.value
}
kboUnit: binding.kboOrganisation?.value,
};
}
return null;
}
export async function getKboIdentifiers(administrativeUnit, changeTime) {
export async function getKboIdentifiers(administrativeUnit) {
const queryStr = `
SELECT DISTINCT ?kboUnit ?abbUnit ?changeTime ?contactPointUri ?addressUri WHERE {
VALUES ?g {
@@ -67,7 +69,7 @@ export async function getKboIdentifiers(administrativeUnit, changeTime) {
?contactPointUri <http://www.w3.org/ns/locn#address> ?addressUri .
?kboUnit owl:sameAs ?abbUnit
?kboUnit <http://www.w3.org/2002/07/owl#sameAs> ?abbUnit
FILTER(?abbUnit = ${sparqlEscapeUri(administrativeUnit)})
}
@@ -84,29 +86,39 @@ export async function getKboIdentifiers(administrativeUnit, changeTime) {
changeTime: binding.changeTime?.value,
contactPointUri: binding.contactPointUri?.value,
addressUri: binding.addressUri?.value,
}
};
}
return null;
}
export async function constructOvoStructure(kboStructuredId) {
const idUuid = uuid();
const idUri = `http://data.lblod.info/id/identificatoren/${idUuid}`
const idUri = `http://data.lblod.info/id/identificatoren/${idUuid}`;
const structuredIdUuid = uuid();
const structuredIdUri = `http://data.lblod.info/id/gestructureerdeIdentificatoren/${structuredIdUuid}`
const structuredIdUri = `http://data.lblod.info/id/gestructureerdeIdentificatoren/${structuredIdUuid}`;
const updateStr = `
INSERT {
GRAPH ?g {
?bestuurseenheid <http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri(idUri)} .
?bestuurseenheid <http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri(
idUri
)} .
${sparqlEscapeUri(idUri)} a <http://www.w3.org/ns/adms#Identifier> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(idUuid)} ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(
idUuid
)} ;
<http://www.w3.org/2004/02/skos/core#notation> "OVO-nummer" ;
<https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ${sparqlEscapeUri(structuredIdUri)} .
<https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ${sparqlEscapeUri(
structuredIdUri
)} .
${sparqlEscapeUri(structuredIdUri)} a <https://data.vlaanderen.be/ns/generiek#GestructureerdeIdentificator> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(structuredIdUuid)} .
${sparqlEscapeUri(
structuredIdUri
)} a <https://data.vlaanderen.be/ns/generiek#GestructureerdeIdentificator> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(
structuredIdUuid
)} .
}
} WHERE {
VALUES ?g {
@@ -114,10 +126,14 @@ export async function constructOvoStructure(kboStructuredId) {
<http://mu.semte.ch/graphs/worship-service>
}
GRAPH ?g {
${sparqlEscapeUri(kboStructuredId)} a <https://data.vlaanderen.be/ns/generiek#GestructureerdeIdentificator> ;
${sparqlEscapeUri(
kboStructuredId
)} a <https://data.vlaanderen.be/ns/generiek#GestructureerdeIdentificator> ;
<https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ?kbo .
?kboId <https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ${sparqlEscapeUri(kboStructuredId)} ;
?kboId <https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ${sparqlEscapeUri(
kboStructuredId
)} ;
<http://www.w3.org/2004/02/skos/core#notation> ?notation .
?bestuurseenheid <http://www.w3.org/ns/adms#identifier> ?kboId .
@@ -136,7 +152,9 @@ export async function updateOvoNumberAndUri(ovoStructuredIdUri, wegwijsOvo) {
DELETE {
GRAPH ?g {
?bestuureseenheid <http://www.w3.org/2002/07/owl#sameAs> ?ovoUri .
${sparqlEscapeUri(ovoStructuredIdUri)} <https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ?ovo .
${sparqlEscapeUri(
ovoStructuredIdUri
)} <https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ?ovo .
}
}
`;
@@ -145,8 +163,14 @@ export async function updateOvoNumberAndUri(ovoStructuredIdUri, wegwijsOvo) {
updateStr += `
INSERT {
GRAPH ?g {
?bestuureseenheid <http://www.w3.org/2002/07/owl#sameAs> ${sparqlEscapeUri(`http://data.vlaanderen.be/id/organisatie/${wegwijsOvo}`)} .
${sparqlEscapeUri(ovoStructuredIdUri)} <https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ${sparqlEscapeString(wegwijsOvo)} .
?bestuureseenheid <http://www.w3.org/2002/07/owl#sameAs> ${sparqlEscapeUri(
`http://data.vlaanderen.be/id/organisatie/${wegwijsOvo}`
)} .
${sparqlEscapeUri(
ovoStructuredIdUri
)} <https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ${sparqlEscapeString(
wegwijsOvo
)} .
}
}
`;
@@ -160,19 +184,25 @@ export async function updateOvoNumberAndUri(ovoStructuredIdUri, wegwijsOvo) {
}
GRAPH ?g {
${sparqlEscapeUri(ovoStructuredIdUri)} a <https://data.vlaanderen.be/ns/generiek#GestructureerdeIdentificator> .
${sparqlEscapeUri(
ovoStructuredIdUri
)} a <https://data.vlaanderen.be/ns/generiek#GestructureerdeIdentificator> .
OPTIONAL {
?bestuureseenheid
<http://www.w3.org/ns/adms#identifier>/<https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ${sparqlEscapeUri(ovoStructuredIdUri)} ;
<http://www.w3.org/ns/adms#identifier>/<https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ${sparqlEscapeUri(
ovoStructuredIdUri
)} ;
<http://www.w3.org/2002/07/owl#sameAs> ?ovoUri .
}
OPTIONAL { ${sparqlEscapeUri(ovoStructuredIdUri)} <https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ?ovo . }
OPTIONAL { ${sparqlEscapeUri(
ovoStructuredIdUri
)} <https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ?ovo . }
}
}
`;
await update(updateStr);
}
@@ -212,19 +242,60 @@ export async function getAllOvoAndKboCouples() {
if (result.results.bindings.length) {
const bindings = result.results.bindings;
return bindings.map(binding => {
return bindings.map((binding) => {
return {
kbo: binding.kbo.value,
kboStructuredId: binding.kboStructuredId.value,
ovo: binding.ovo?.value,
ovoStructuredId: binding.ovoStructuredId?.value,
}
};
});
}
return null;
}
export async function createNewKboOrg(kboOrg, kboId, isUpdate, oldKbo){
export async function getAllAbbKboOrganizations(){
let queryStr = `
SELECT ?kbo ?abbOrg ?kboOrg ?changeTime ?kboId where {
GRAPH ?g {
?kboId <https://data.vlaanderen.be/ns/generiek#gestructureerdeIdentificator> ?kboStructuredId ;
<http://www.w3.org/2004/02/skos/core#notation> ?kboNotation .
?kboStructuredId a <https://data.vlaanderen.be/ns/generiek#GestructureerdeIdentificator> ;
<https://data.vlaanderen.be/ns/generiek#lokaleIdentificator> ?kbo .
?abbOrg <http://www.w3.org/ns/adms#identifier> ?kboId .
FILTER (?kboNotation IN ("KBO nummer"@nl, "KBO nummer"))
OPTIONAL{
?kboOrg owl:sameAs ?abbOrg .
?kboOrg <https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime .
}
}
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
}
`
const result = await query(queryStr);
if (result.results.bindings.length) {
const bindings = result.results.bindings;
return bindings.map((binding) => {
return {
kbo: binding.kbo.value,
abbOrg: binding.abbOrg.value,
kboOrg: binding.kboOrg?.value,
kboId: binding.kboId?.value,
changeTime: binding.changeTime?.value,
};
});
}
return null;
}
export async function createNewKboOrg(kboOrg, kboId) {
const newKboOrgIdUuId = uuid();
const newKboIdUri = `http://data.lblod.info/id/kboBestuurseenheden/${newKboOrgIdUuId}`;
@@ -234,69 +305,238 @@ export async function createNewKboOrg(kboOrg, kboId, isUpdate, oldKbo){
const adressUuidId = uuid();
const adressUri = `http://data.lblod.info/id/adressen/${adressUuidId}`;
let updateStr = "";
updateStr += `
console.log("creating:" + kboOrg);
console.log("with:" + kboId);
let updateStr = `
INSERT {
GRAPH ?g {
${sparqlEscapeUri(adressUri)} a <http://www.w3.org/ns/locn#Address> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(adressUuidId)} ;
<http://www.w3.org/ns/locn#fullAddress> ${sparqlEscapeString(kboOrg.formattedAddress)} .
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(
adressUuidId
)} ;
<http://www.w3.org/ns/locn#fullAddress> ${sparqlEscapeString(
kboOrg.formattedAddress
)} .
${sparqlEscapeUri(contactPointUri)} a <http://schema.org/ContactPoint> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(contactPointUuidId)} ;
<http://schema.org/email> ${sparqlEscapeString(kboOrg.email)} ;
<http://schema.org/telephone> ${sparqlEscapeString(kboOrg.phone)} ;
<http://schema.org/contactType> ${sparqlEscapeString("Kbocontact")} ;
<http://xmlns.com/foaf/0.1/page> ${sparqlEscapeString(kboOrg.website)} ;
<http://www.w3.org/ns/locn#address> ${sparqlEscapeUri(adressUri)}.
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(
contactPointUuidId
)} ;
<http://schema.org/email> ${sparqlEscapeString(
kboOrg.email
)} ;
<http://schema.org/telephone> ${sparqlEscapeString(
kboOrg.phone
)} ;
<http://schema.org/contactType> ${sparqlEscapeString(
"Kbocontact"
)} ;
<http://xmlns.com/foaf/0.1/page> ${sparqlEscapeString(
kboOrg.website
)} ;
<http://www.w3.org/ns/locn#address> ${sparqlEscapeUri(
adressUri
)}.
${sparqlEscapeUri(newKboIdUri)} a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(newKboOrgIdUuId)} ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ${sparqlEscapeString(kboOrg.rechtsvorm)} ;
<http://mu.semte.ch/vocabularies/ext/shortName> ${sparqlEscapeString(kboOrg.shortName)} ;
<http://mu.semte.ch/vocabularies/ext/startDate> ${sparqlEscapeString(kboOrg.startDate)} ;
<http://www.w3.org/2004/02/skos/core#prefLabel> ${sparqlEscapeString(kboOrg.organisationName)} ;
<http://www.w3.org/2004/02/skos/core#altLabel> ${sparqlEscapeString(kboOrg.formalName)} ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ${sparqlEscapeString(kboOrg.changeTime)} ;
<http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri(kboId)} ;
<http://www.w3.org/ns/regorg#orgStatus> ${sparqlEscapeUri(kboOrg.activeState)} ;
<http://schema.org/contactPoint> ${sparqlEscapeUri(contactPointUri)} .
${sparqlEscapeUri(
newKboIdUri
)} a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/core/uuid> ${sparqlEscapeString(
newKboOrgIdUuId
)} ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ${sparqlEscapeString(
kboOrg.rechtsvorm
)} ;
<http://mu.semte.ch/vocabularies/ext/shortName> ${sparqlEscapeString(
kboOrg.shortName
)} ;
<http://mu.semte.ch/vocabularies/ext/startDate> ${sparqlEscapeString(
kboOrg.startDate
)} ;
<http://www.w3.org/2004/02/skos/core#prefLabel> ${sparqlEscapeString(
kboOrg.organisationName
)} ;
<http://www.w3.org/2004/02/skos/core#altLabel> ${sparqlEscapeString(
kboOrg.formalName
)} ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ${sparqlEscapeString(
kboOrg.changeTime
)} ;
<http://www.w3.org/ns/adms#identifier> ${sparqlEscapeUri(
kboId
)} ;
<http://www.w3.org/ns/regorg#orgStatus> ${sparqlEscapeUri(
kboOrg.activeState
)} ;
<http://schema.org/contactPoint> ${sparqlEscapeUri(
contactPointUri
)} .
}
}WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
}
`
`;
await update(updateStr);
return newKboIdUri;
}
export async function linkAbbOrgToKboOrg(abbOrgUri ,kboOrgUri){
export async function updateKboOrg(newKboInfo, identifiers) {
//update Adress
let updateStr = `
DELETE{
GRAPH ?g{
?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> ;
<http://www.w3.org/ns/locn#fullAddress> ${sparqlEscapeString(newKboInfo.formattedAddress)} .
}
}
WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
GRAPH ?g {
?adressUri a <http://www.w3.org/ns/locn#Address> ;
<http://www.w3.org/ns/locn#fullAddress> ?fulladdress .
FILTER(?adressUri = ${sparqlEscapeUri(identifiers.addressUri)})
}
}
`;
await update(updateStr);
//update ContactPoint
updateStr = `
DELETE{
GRAPH ?g{
?contact a <http://schema.org/ContactPoint> ;
<http://schema.org/email> ?email ;
<http://schema.org/telephone> ?phone ;
<http://xmlns.com/foaf/0.1/page> ?website .
}
}
INSERT{
graph ?g{
?contact a <http://schema.org/ContactPoint> ;
<http://schema.org/email> ${sparqlEscapeString(
newKboInfo.email
)} ;
<http://schema.org/telephone> ${sparqlEscapeString(
newKboInfo.phone
)} ;
<http://xmlns.com/foaf/0.1/page> ${sparqlEscapeString(
newKboInfo.website
)} .
}
}
WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
GRAPH ?g {
?contact a <http://schema.org/ContactPoint> ;
<http://schema.org/email> ?email ;
<http://schema.org/telephone> ?phone ;
<http://xmlns.com/foaf/0.1/page> ?website .
FILTER(?contact = ${sparqlEscapeUri(identifiers.contactPointUri)})
}
}
`;
await update(updateStr);
//update kboUnit
updateStr = `
DELETE{
GRAPH ?g{
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<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> ?orgName ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?commercialName ;
<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> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ${sparqlEscapeString(
newKboInfo.rechtsvorm
)} ;
<http://mu.semte.ch/vocabularies/ext/shortName> ${sparqlEscapeString(
newKboInfo.shortName
)} ;
<http://mu.semte.ch/vocabularies/ext/startDate> ${sparqlEscapeString(
newKboInfo.startDate
)} ;
<http://www.w3.org/2004/02/skos/core#prefLabel> ${sparqlEscapeString(
newKboInfo.organisationName
)} ;
<http://www.w3.org/2004/02/skos/core#altLabel> ${sparqlEscapeString(
newKboInfo.formalName
)} ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ${sparqlEscapeString(
newKboInfo.changeTime
)} ;
<http://www.w3.org/ns/regorg#orgStatus> ${sparqlEscapeUri(
newKboInfo.activeState
)} .
}
}
WHERE{
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
GRAPH ?g {
?kboUnit a <http://mu.semte.ch/vocabularies/ext/KboEenheid> ;
<http://mu.semte.ch/vocabularies/ext/rechtsvorm> ?rechtsVorm ;
<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> ?orgName ;
<http://www.w3.org/2004/02/skos/core#altLabel> ?commercialName ;
<https://data.lblod.info/vocabularies/generiek/geplandeEindDatum> ?changeTime ;
<http://www.w3.org/ns/regorg#orgStatus> ?activeState .
FILTER(?kboUnit = ${sparqlEscapeUri(identifiers.kboUnit)})
}
}
`;
await update(updateStr);
}
export async function linkAbbOrgToKboOrg(abbOrgUri, kboOrgUri) {
let updateStr = `
INSERT {
GRAPH ?g {
${sparqlEscapeUri(kboOrgUri)} <http://www.w3.org/2002/07/owl#sameAs> ${sparqlEscapeUri(abbOrgUri)} .
${sparqlEscapeUri(
kboOrgUri
)} <http://www.w3.org/2002/07/owl#sameAs> ${sparqlEscapeUri(abbOrgUri)} .
}
}WHERE {
VALUES ?g {
<http://mu.semte.ch/graphs/administrative-unit>
}
${sparqlEscapeUri(kboOrgUri)} a <http://mu.semte.ch/vocabularies/ext/KboEenheid> .
${sparqlEscapeUri(
kboOrgUri
)} a <http://mu.semte.ch/vocabularies/ext/KboEenheid> .
}
`
`;
await update(updateStr);
}
// Update queries: via mu-auth if it comes from the frontend ?