Skip to content

Commit

Permalink
initial version of new besluit handling, tested with the cases in the…
Browse files Browse the repository at this point in the history
… mock route
  • Loading branch information
karel kremer committed Sep 13, 2024
1 parent ed6f824 commit aad1bbf
Show file tree
Hide file tree
Showing 23 changed files with 1,826 additions and 119 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM semtech/mu-javascript-template:feature-node-18
FROM semtech/mu-javascript-template:1.8.0
LABEL maintainer="[email protected]"
7 changes: 6 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/intallatievergadering';
import { mandatenRouter } from './routes/mandaten';
import { mockRouter } from './routes/mock';
import { cronjob } from './cron/handle-decision-queue';

app.use(
bodyParser.json({
Expand All @@ -33,6 +35,7 @@ app.use('/personen', personenRouter);
app.use('/mandaten', mandatenRouter);
app.use('/burgemeester-benoeming', burgemeesterRouter);
app.use('/installatievergadering-api', installatievergaderingRouter);
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 @@ -43,3 +46,5 @@ const errorHandler: ErrorRequestHandler = function (err, _req, res, _next) {
};

app.use(errorHandler);

setTimeout(() => cronjob.start(), 10000);
4 changes: 2 additions & 2 deletions config/custom-dispatching/delta-context-config.js
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#>
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
137 changes: 137 additions & 0 deletions controllers/mandataris-besluit/beleidsdomein.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
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 met uri ${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];
await insertTriplesInGraph(allTriples, graph);
}
Loading

0 comments on commit aad1bbf

Please sign in to comment.