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

Handle logical file uris with no related physical file information #114

Merged
merged 3 commits into from
Sep 20, 2024
Merged
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
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