Skip to content

Commit

Permalink
fix: use template name to select template
Browse files Browse the repository at this point in the history
  • Loading branch information
abeforgit committed Oct 9, 2024
1 parent d2404e8 commit 598529a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-eagles-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'frontend-gelinkt-notuleren': patch
---

Select IV templates based on name so they work in all envs
20 changes: 10 additions & 10 deletions app/controllers/inbox/meetings/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { service } from '@ember/service';
import InstallatieVergaderingModel from '../../../models/installatievergadering';

const IV_AP_MAP = [
'http://data.lblod.info/templates/77eb1d90-6d3b-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/02cee410-6471-11ef-9943-f704da4e6eb6',
'http://data.lblod.info/templates/dcdc22a0-6e2e-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/fc357ed0-6e2e-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/3679b220-6e32-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/b10c53d0-6e32-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/770b2020-6e33-11ef-a3a6-c39998a0026f',
'http://data.lblod.info/templates/8186d760-6e33-11ef-a3a6-c39998a0026f',
'IVGR1 Kennisname van de definitieve verkiezingsluitslag',
'IVGR2 Onderzoek van de geloofsbrieven',
'IVGR3 Eedaflegging van de verkozen gemeenteraadsleden',
'IVGR4 Bepaling van de rangorde van de gemeenteraadsleden',
'IVGR5 Vaststelling van de fracties',
'IVGR6 Verkiezing van de voorzitter van de gemeenteraad',
'IVGR7 Verkiezing van de schepenen',
'IVGR8 Aanduiding en eedaflegging van de aangewezen-burgemeester',
];
const IV_NAME_MAP = [
'Kennisname van de definitieve verkiezingsuitslag',
Expand Down Expand Up @@ -94,8 +94,8 @@ export default class InboxMeetingsNewController extends Controller {
openbaar: true,
onderwerp: agendapoint,
});
const template = await this.templateFetcher.fetchByUri({
uri: IV_AP_MAP[i],
const template = await this.templateFetcher.fetchByTemplateName({
name: IV_AP_MAP[i],
});
await template.loadBody();
promises.push(
Expand Down
50 changes: 50 additions & 0 deletions app/services/template-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,56 @@ export default class TemplateFetcher extends Service {
@tracked user;
@tracked group;
@tracked roles = [];

fetchByTemplateName = async ({ name }) => {
const config = getOwner(this).resolveRegistration('config:environment');
const fileEndpoint = config.regulatoryStatementFileEndpoint;
const sparqlEndpoint = config.regulatoryStatementEndpoint;

const sparqlQuery = `
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
PREFIX pav: <http://purl.org/pav/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX schema: <http://schema.org/>
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
SELECT
?template_version
?title
?fileId
(GROUP_CONCAT(?context;SEPARATOR="|") as ?contexts)
(GROUP_CONCAT(?disabledInContext;SEPARATOR="|") as ?disabledInContexts)
WHERE {
BIND("${name}" as ?title)
?uri mu:uuid ?uuid;
pav:hasCurrentVersion ?template_version.
?template_version mu:uuid ?fileId;
dct:title ?title.
OPTIONAL {
?template_version schema:validThrough ?validThrough.
}
OPTIONAL {
?template_version ext:context ?context.
}
OPTIONAL {
?template_version ext:disabledInContext ?disabledInContext.
}
FILTER( ! BOUND(?validThrough) || ?validThrough > NOW())
}
GROUP BY ?template_version ?title ?fileId
ORDER BY LCASE(REPLACE(STR(?title), '^ +| +$', ''))
`;

const response = await this.sendQuery(sparqlEndpoint, sparqlQuery);
if (response.status === 200) {
const json = await response.json();
const bindings = json.results.bindings;
const templates = bindings.map(this.bindingToTemplate(fileEndpoint));
return templates[0];
} else {
return null;
}
};

fetchByUri = async ({ uri }) => {
const config = getOwner(this).resolveRegistration('config:environment');
const fileEndpoint = config.regulatoryStatementFileEndpoint;
Expand Down

0 comments on commit 598529a

Please sign in to comment.