Skip to content

Commit

Permalink
remove old way of handling decisions
Browse files Browse the repository at this point in the history
  • Loading branch information
karel kremer committed Sep 13, 2024
1 parent aad1bbf commit 593dfca
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 673 deletions.
153 changes: 0 additions & 153 deletions controllers/mandatees-decisions.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
import { findBestuurseenheidForMandaat } from '../data-access/bestuurseenheid';

import {
endExistingMandataris,
findDecisionForMandataris,
findStartDateOfMandataris,
updatePublicationStatusOfMandataris,
} from '../data-access/mandataris';
import {
TERM_MANDATARIS_TYPE,
TERM_STAGING_GRAPH,
checkIfMinimalMandatarisInfoAvailable,
getMandateOfMandataris as findMandateOfMandataris,
findNameOfPersoonFromStaging,
findOverlappingMandataris,
findPersoonForMandatarisInGraph,
getMandatarisTriplesInStagingGraph,
getQuadsInLmbFromTriples,
getTriplesOfSubject,
insertTriplesInGraph,
isMandatarisInTarget as isMandatarisInLmbDatabase,
isSubjectOfType,
updateDifferencesOfMandataris,
} from '../data-access/mandatees-decisions';
import {
checkPersonExistsAllGraphs,
copyPerson,
createrPersonFromUri,
} from '../data-access/persoon';
import { MandatarisBesluitLookup, MandatarisFullInfo } from '../types';
import { PUBLICATION_STATUS } from '../util/constants';
import { copyBeleidsdomeinInfo } from './mandataris-besluit/beleidsdomein';
Expand Down Expand Up @@ -106,137 +87,3 @@ export async function handleMandatarisSubject(
await copyFractionInfo(mandatarisFullInfo);
await copyBeleidsdomeinInfo(mandatarisFullInfo);
}

export async function oldHandleMandatarisSubject(mandatarisSubject: string) {
console.log(`|> Mandataris uri: ${mandatarisSubject}`);
const isExitingInLmbDatabase =
await isMandatarisInLmbDatabase(mandatarisSubject);
console.log(
`|> Mandataris exists in LMB database? ${isExitingInLmbDatabase}`,
);

const mandaat = await findMandateOfMandataris(mandatarisSubject);
console.log('|> Mandaat for mandataris', mandaat?.value);
if (!mandaat) {
console.log(
`|> No mandaat found for mandataris with subject: ${mandatarisSubject.value} \n|>\n`,
);
mandatarisQueue.addToManualQueue(mandatarisSubject);
return;
}

const mandatarisGraph = await findBestuurseenheidForMandaat(mandaat);
console.log(`|> mandataris graph: ${mandatarisGraph?.value ?? undefined}.`);

if (!mandatarisGraph) {
console.log(
`|> Could not find graph from mandaat: ${mandaat.value}. Continueing to the next subject.\n|>\n`,
);
mandatarisQueue.addToManualQueue(mandatarisSubject);
return;
}

const incomingTriples = await getTriplesOfSubject(
mandatarisSubject,
TERM_STAGING_GRAPH,
);
console.log(
`|> Found ${incomingTriples.length} triples in the staging graph for mandataris.`,
);
if (isExitingInLmbDatabase) {
const currentQuads = await getQuadsInLmbFromTriples(incomingTriples);
console.log('|> Updating mandataris predicate values.');
await updateDifferencesOfMandataris(
currentQuads,
incomingTriples,
mandatarisGraph,
);

console.log(
'|> Going to the next mandataris subeject as triples are updated. \n|>\n',
);
return;
}

// Looking for persoon in graph of the mandataris
const persoonOfMandataris = await findPersoonForMandatarisInGraph(
mandatarisSubject,
TERM_STAGING_GRAPH,
);

if (!persoonOfMandataris) {
console.log(
`|> Could not find person of mandataris: ${mandatarisSubject.value}. Continuing to the next subject.\n|>\n`,
);
mandatarisQueue.addToManualQueue(mandatarisSubject);
return;
}

console.log(
`|> Persoon from mandataris: ${persoonOfMandataris?.value ?? undefined}.`,
);

const persoonInLMBGraph = await findPersoonForMandatarisInGraph(
mandatarisSubject,
mandatarisGraph,
);
console.log(
`|> Is persoon in graph of mandataris (LMB)? ${
persoonInLMBGraph ? true : false
}`,
);
if (persoonInLMBGraph) {
const overlappingMandataris = await findOverlappingMandataris(
persoonOfMandataris,
mandaat,
);
console.log(
`|> Persoon has overlapping mandaat? ${
overlappingMandataris?.value ?? false
}`,
);

if (overlappingMandataris) {
const startDate = await findStartDateOfMandataris(mandatarisSubject);
console.log(`|> Found start date for incoming mandataris? ${startDate}`);
if (startDate) {
await endExistingMandataris(
mandatarisGraph,
overlappingMandataris,
startDate,
);
}
}

console.log('|> Inserting incoming triples');
await insertTriplesInGraph(incomingTriples, mandatarisGraph);

return;
}

// If person exists in another graph, copy that person.
const personInOtherGraph =
await checkPersonExistsAllGraphs(persoonOfMandataris);
console.log(
`|> Is persoon in other graphs of the LMB application?: ${personInOtherGraph}`,
);
if (personInOtherGraph) {
await copyPerson(persoonOfMandataris, mandatarisGraph);
return;
}

// Create new person with given firstname and lastname
const persoon = await findNameOfPersoonFromStaging(mandatarisSubject);
console.log('|> Looking for persoon names', persoon);
if (!persoon) {
mandatarisQueue.addToManualQueue(mandatarisSubject);
return;
}

await createrPersonFromUri(
persoon.persoonUri,
persoon.firstname,
persoon.lastname,
mandatarisGraph,
);
}
40 changes: 0 additions & 40 deletions data-access/bestuurseenheid.ts

This file was deleted.

22 changes: 0 additions & 22 deletions data-access/mandataris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,28 +491,6 @@ export async function endExistingMandataris(
}
}

export async function findStartDateOfMandataris(
mandataris: Term,
): Promise<Date | null> {
const startDateQuery = `
PREFIX mandaat: <http://data.vlaanderen.be/ns/mandaat#>
SELECT ?startDate
WHERE {
${sparqlEscapeTermValue(mandataris)} mandaat:start ?startDate .
}
`;

const dateResult = await querySudo(startDateQuery);
const result = findFirstSparqlResult(dateResult);

if (result) {
return new Date(result.startDate.value);
}

return null;
}

export async function findDecisionForMandataris(
mandataris: string,
): Promise<{ besluit: string; link: string } | null> {
Expand Down
Loading

0 comments on commit 593dfca

Please sign in to comment.