diff --git a/CHANGELOG.md b/CHANGELOG.md index a85894d..2715c5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased - Query to check missing address URI's [OP-3784] +- Create new query 'organisations shown in OP frontend' in Dashboard [OP-3774] ### Deploy notes ``` diff --git a/config/reports/index.js b/config/reports/index.js index 75cc0e6..e3ceb4b 100644 --- a/config/reports/index.js +++ b/config/reports/index.js @@ -6,6 +6,7 @@ import OrganizationsPlatformReport from './organizations-platform-report' import AdministrativeUnitsReport from "./administrative-units-report"; import ChangeEventsReport from "./change-events-report"; import OrganizationsNoAddressReport from "./organizations-no-address-report"; +import OrganizationsInFrontendReport from "./organizations-in-frontend-report"; export default [ OrganizationsReport, @@ -16,4 +17,5 @@ export default [ AdministrativeUnitsReport, ChangeEventsReport, OrganizationsNoAddressReport, + OrganizationsInFrontendReport, ]; diff --git a/config/reports/organizations-in-frontend-report.js b/config/reports/organizations-in-frontend-report.js new file mode 100644 index 0000000..0da92cc --- /dev/null +++ b/config/reports/organizations-in-frontend-report.js @@ -0,0 +1,102 @@ +import { generateReportFromData, batchedQuery } from "../helpers.js"; +import { PREFIXES } from "./utils"; + +export default { + cronPattern: "0 00 23 * * *", + name: "organizationsInFrontend", + execute: async () => { + const reportData = { + title: "organisations in frontend", + description: "List of the Organisations shown in the frontend", + filePrefix: "exports/organizations-in-frontend", + }; + + console.log("Generating organizations in frontend report"); + + const queryString = ` + ${PREFIXES} + PREFIX org: + PREFIX adms: + PREFIX generiek: + PREFIX skos: + PREFIX geosparql: + PREFIX dct: + SELECT DISTINCT + ?bestuur + ?label + ?classification + ?typeEredienst + ?provincie + ?status + WHERE { + ?bestuur a org:Organization . + OPTIONAL { + ?bestuur ?site. + ?site ?address. + ?address ?provincie. + } + OPTIONAL {?bestuur ?typeEredienst.} + OPTIONAL {?bestuur skos:prefLabel ?label} + OPTIONAL { + ?bestuur ?org_classification . + ?org_classification skos:prefLabel ?classification. + } + OPTIONAL { + ?bestuur ?org_status. + ?org_status skos:prefLabel ?status. + } + + FILTER( + NOT EXISTS { + ?bestuur org:classification . + } + || + EXISTS { + ?bestuur besluit:werkingsgebied ?werkingsgebied . + ?werkingsgebied geosparql:sfWithin ?parent . + } + ) + + FILTER( + NOT EXISTS { + ?bestuur org:classification . + } + + ) + } + `; + + const queryResponse = await batchedQuery(queryString); + + const data = queryResponse.results.bindings.map((row) => ({ + bestuur: getSafeValue(row, "bestuur"), + label: getSafeValue(row, "label"), + classification: getSafeValue(row, "classification"), + typeEredienst: getSafeValue(row, "typeEredienst"), + provincie: getSafeValue(row, "provincie"), + status: getSafeValue(row, "status"), + })); + + await generateReportFromData( + data, + [ + "bestuur", + "label", + "classification", + "typeEredienst", + "provincie", + "status", + ], + reportData, + ); + }, +}; + +function getSafeValue(entry, property) { + return entry[property] ? wrapInQuote(entry[property].value) : null; +} + +// Some values might contain commas; wrapping them in escapes quotes doesn't disrupt the columns. +function wrapInQuote(value) { + return `\"${value}\"`; +}