Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new version of handling besluit information #45

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { app } from 'mu';
import express, { Request, ErrorRequestHandler } from 'express';
import bodyParser from 'body-parser';

import { deltaRouter } from './routes/delta';
import { deltaRouter } from './routes/delta-decisions';
import { mandatarissenRouter } from './routes/mandatarissen';
import { fractiesRouter } from './routes/fractie';
import { personenRouter } from './routes/persoon';
import { burgemeesterRouter } from './routes/burgemeester-benoeming';
import { installatievergaderingRouter } from './routes/installatievergadering';
import { mandatenRouter } from './routes/mandaten';
import { mockRouter } from './routes/mock';
import { cronjob } from './cron/handle-decision-queue';

import { cronjob as notificationBekrachtigdMandataris } from './cron/notification-for-bekrachtigde-mandataris';
import { electionResultsRouter } from './routes/verkiezingsresultaten';
Expand Down Expand Up @@ -37,6 +39,7 @@ app.use('/mandaten', mandatenRouter);
app.use('/burgemeester-benoeming', burgemeesterRouter);
app.use('/installatievergadering-api', installatievergaderingRouter);
app.use('/election-results-api', electionResultsRouter);
app.use('/mock', mockRouter);

const errorHandler: ErrorRequestHandler = function (err, _req, res, _next) {
// custom error handler to have a default 500 error code instead of 400 as in the template
Expand All @@ -49,3 +52,4 @@ const errorHandler: ErrorRequestHandler = function (err, _req, res, _next) {
app.use(errorHandler);

notificationBekrachtigdMandataris.start();
setTimeout(() => cronjob.start(), 10000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove this when actually merging this I guess?

4 changes: 2 additions & 2 deletions config/custom-dispatching/delta-context-config.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit confused about these http vs https prefixes, both seem to be in use in our application.

Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ PREFIX euro: <http://data.europa.eu/m8g/>
PREFIX euvoc: <http://publications.europa.eu/ontology/euvoc#>
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX generiek: <https://data.vlaanderen.be/ns/generiek#>
PREFIX generiek: <http://data.vlaanderen.be/ns/generiek#>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this generiek prefix, if I look in the app, sometimes we seem to use http and sometimes https.

PREFIX lblodlg: <https://data.lblod.info/vocabularies/leidinggevenden/>
PREFIX locn: <http://www.w3.org/ns/locn#>
PREFIX mandaat: <http://data.vlaanderen.be/ns/mandaat#>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX org: <http://www.w3.org/ns/org#>
PREFIX organisatie: <https://data.vlaanderen.be/ns/organisatie#>
PREFIX person: <http://www.w3.org/ns/person#>
PREFIX persoon: <https://data.vlaanderen.be/ns/persoon#>
PREFIX persoon: <http://data.vlaanderen.be/ns/persoon#>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX regorg: <https://www.w3.org/ns/regorg#>
Expand Down
138 changes: 138 additions & 0 deletions controllers/mandataris-besluit/beleidsdomein.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import {
copySimpleInstanceToGraph,
getBeleidsdomeinTriplesInStagingGraph,
getGraphsWhereInstanceExists,
insertTriplesInGraph,
} from '../../data-access/mandatees-decisions';
import { MandatarisFullInfo, Triple } from '../../types';
import { createMandatarisBesluitNotification } from '../../util/create-notification';
import { getUuidForUri } from '../../util/uuid-for-uri';

export async function copyBeleidsdomeinInfo(
mandatarisFullInfo: MandatarisFullInfo,
) {
const beleidsDomeinen = mandatarisFullInfo.triples
.filter(
(triple) =>
triple.predicate.value ===
'http://data.vlaanderen.be/ns/mandaat#beleidsdomein',
)
.map((triple) => triple.object.value);

for (const beleidsDomein of beleidsDomeinen) {
await copyBeleidsDomein(
mandatarisFullInfo,
beleidsDomein,
mandatarisFullInfo.graph,
);
}
}

async function copyBeleidsDomein(
mandatarisFullInfo: MandatarisFullInfo,
beleidsDomein: string,
graph: string,
): Promise<void> {
const graphsForBeleidsDomein =
await getGraphsWhereInstanceExists(beleidsDomein);
const inAppropriateGraph = graphsForBeleidsDomein.find((g) =>
['http://mu.semte.ch/graphs/public', graph].includes(g.graph.value),
);
if (graphsForBeleidsDomein.length === 0) {
await createBeleidsDomein(beleidsDomein, graph);
await createMandatarisBesluitNotification({
title: 'Beleidsdomein aangemaakt',
description:
'Een nieuw beleidsdomein werd aangemaakt op basis van de informatie in het Besluit.',
type: 'info',
info: mandatarisFullInfo,
});
} else if (!inAppropriateGraph) {
await copySimpleInstanceToGraph(beleidsDomein, graph);
} else {
// beleidsdomein exists in an appropriate graph. nothing to do
}
}

async function createBeleidsDomein(beleidsdomeinUri: string, graph: string) {
const triplesForBeleidsdomein =
await getBeleidsdomeinTriplesInStagingGraph(beleidsdomeinUri);
const id = await getUuidForUri(beleidsdomeinUri, {
allowCheckingUri: true,
allowGenerateUuid: true,
});
const extraTriples: Triple[] = [
{
subject: {
value: beleidsdomeinUri,
type: 'uri',
},
predicate: {
value: 'http://mu.semte.ch/vocabularies/core/uuid',
type: 'uri',
},
object: {
value: id,
type: 'string',
},
},
{
subject: {
value: beleidsdomeinUri,
type: 'uri',
},
predicate: {
value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
type: 'uri',
},
object: {
value: 'http://mu.semte.ch/vocabularies/ext/BeleidsdomeinCode',
type: 'uri',
},
},
{
subject: {
value: beleidsdomeinUri,
type: 'uri',
},
predicate: {
value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
type: 'uri',
},
object: {
value: 'http://www.w3.org/2004/02/skos/core#Concept',
type: 'uri',
},
},
{
subject: {
value: beleidsdomeinUri,
type: 'uri',
},
predicate: {
value: 'http://www.w3.org/2004/02/skos/core#inScheme',
type: 'uri',
},
object: {
value: 'http://data.vlaanderen.be/id/conceptscheme/BeleidsdomeinCode',
type: 'uri',
},
},
{
subject: {
value: beleidsdomeinUri,
type: 'uri',
},
predicate: {
value: 'http://www.w3.org/2004/02/skos/core#topConceptOf',
type: 'uri',
},
object: {
value: 'http://data.vlaanderen.be/id/conceptscheme/BeleidsdomeinCode',
type: 'uri',
},
},
];
const allTriples = [...triplesForBeleidsdomein, ...extraTriples];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this potentially give duplicate triples? Or is virtuoso smart enough to only write identical triples once?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight not a problem, since getBeleidsdomeinTriplesInStagingGraph only returns the prefLabel, but as mentioned there naming is a bit confusing.

await insertTriplesInGraph(allTriples, graph);
}
Loading