Skip to content

Commit

Permalink
Merge pull request #114 from lblod/fix/signing-fail
Browse files Browse the repository at this point in the history
Handle logical file uris with no related physical file information
  • Loading branch information
abeforgit authored Sep 20, 2024
2 parents c4b427e + 8632d66 commit 46d3bac
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 33 deletions.
23 changes: 17 additions & 6 deletions models/versioned-notulen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class VersionedNotulen {
${prefixMap.get('prov').toSparqlString()}
${prefixMap.get('nie').toSparqlString()}
SELECT ?uri ?html
SELECT ?uri ?html ?fileUri
WHERE {
?uri a ext:VersionedNotulen;
ext:notulenKind ${sparqlEscapeString(kind)}.
Expand Down Expand Up @@ -52,19 +52,26 @@ export default class VersionedNotulen {

/**
* @typedef {Object} Params
* @property {string} [notulenUri]
* @property {string} kind
* @property {Meeting} meeting
* @property {string} html
* @property {[]} publicTreatments
* @property {PublicTreatment[]} publicTreatments
*/
/**
* create a new versioned notulen
* @param {Params} args
* @returns {Promise<VersionedNotulen>}
*/
static async create({ kind, meeting, html, publicTreatments }) {
const versionedNotulenUuid = uuid();
const versionedNotulenUri = `http://data.lblod.info/versioned-notulen/${versionedNotulenUuid}`;
static async create({ notulenUri, kind, meeting, html, publicTreatments }) {
let versionedNotulenUuid;
let versionedNotulenUri;
if (!notulenUri) {
versionedNotulenUuid = uuid();
versionedNotulenUri = `http://data.lblod.info/versioned-notulen/${versionedNotulenUuid}`;
} else {
versionedNotulenUri = notulenUri;
}
const fileInfo = await persistContentToFile(html);
const logicalFileUri = await writeFileMetadataToDb(fileInfo);
await update(`
Expand All @@ -78,7 +85,11 @@ export default class VersionedNotulen {
a ext:VersionedNotulen;
prov:generated ${sparqlEscapeUri(logicalFileUri)};
ext:notulenKind ${sparqlEscapeString(kind)};
mu:uuid ${sparqlEscapeString(versionedNotulenUuid)};
${
versionedNotulenUuid
? `mu:uuid ${sparqlEscapeString(versionedNotulenUuid)};`
: ''
}
ext:deleted "false"^^<http://mu.semte.ch/vocabularies/typed-literals/boolean>.
${publicTreatments
.map(
Expand Down
57 changes: 33 additions & 24 deletions support/notulen-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,42 +111,51 @@ export async function ensureVersionedNotulen(
kind,
publicTreatments = []
) {
const versionedNotulen = await VersionedNotulen.query({ meeting, kind });
let versionedNotulen = await VersionedNotulen.query({ meeting, kind });
let notulenUri;
if (versionedNotulen) {
console.log(
`Reusing versioned notulen ${versionedNotulen.uri} of kind ${kind}`
);
return versionedNotulen.uri;
notulenUri = versionedNotulen.uri;
if (versionedNotulen.html) {
return versionedNotulen.uri;
} else {
console.warn(
`Versioned notulen for ${meeting.uri} (kind ${kind}) has no content, recreating...`
);
}
} else {
console.log(
`Creating a new versioned notulen of kind ${kind} for ${meeting.uri}`
);
let html;
if (kind === NOTULEN_KIND_FULL) {
const data = await buildDataForMeetingNotes({
meeting,
treatments,
previewType: IS_FINAL,
allPublic: true,
});
html = constructHtmlForMeetingNotesFromData(data);
} else {
const data = await buildDataForMeetingNotes({
meeting,
treatments,
previewType: IS_FINAL,
publicTreatments,
});
html = constructHtmlForMeetingNotesFromData(data);
}
const versionedNotulen = await VersionedNotulen.create({
}
let html;
if (kind === NOTULEN_KIND_FULL) {
const data = await buildDataForMeetingNotes({
meeting,
treatments,
previewType: IS_FINAL,
allPublic: true,
});
html = constructHtmlForMeetingNotesFromData(data);
} else {
const data = await buildDataForMeetingNotes({
meeting,
html,
kind,
treatments,
previewType: IS_FINAL,
publicTreatments,
});
return versionedNotulen.uri;
html = constructHtmlForMeetingNotesFromData(data);
}
versionedNotulen = await VersionedNotulen.create({
notulenUri,
meeting,
html,
kind,
publicTreatments,
});
return versionedNotulen.uri;
}

export async function generateNotulenPreview(
Expand Down
5 changes: 2 additions & 3 deletions support/pre-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ async function getVersionedContent(uri, contentPredicate) {
const binding = result.results.bindings[0];
if (binding.content) {
return binding.content.value;
} else {
} else if (binding.physicalFileUri) {
const content = await getFileContentForUri(binding.physicalFileUri.value);
return content;
}
} else {
throw 'could not retrieve content';
}
throw new Error('could not retrieve content');
}

async function handleVersionedResource(
Expand Down

0 comments on commit 46d3bac

Please sign in to comment.