Skip to content

Commit

Permalink
fix(data): filenames in the change queue are invalid. Soft fix to der…
Browse files Browse the repository at this point in the history
…ived valid name from it. gh-70
  • Loading branch information
geoffroy-noel-ddh committed Sep 10, 2024
1 parent 3ad23a0 commit 9a46c45
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![Collection filtering](https://github.com/kingsdigitallab/crossreads/actions/workflows/subcollection.yml/badge.svg)](https://github.com/kingsdigitallab/crossreads/actions/workflows/subcollection.yml)
[![Annotation indexing](https://github.com/kingsdigitallab/crossreads/actions/workflows/index.yml/badge.svg)](https://github.com/kingsdigitallab/crossreads/actions/workflows/index.yml)
[![Site publication](https://github.com/kingsdigitallab/crossreads/actions/workflows/static.yml/badge.svg)](https://github.com/kingsdigitallab/crossreads/actions/workflows/static.yml)
[![Change queue runner](https://github.com/kingsdigitallab/crossreads/actions/workflows/run-change-queue.yml/badge.svg)](https://github.com/kingsdigitallab/crossreads/actions/workflows/run-change-queue.yml)

KDL codebase for the CROSSREADS research project

Expand Down
33 changes: 31 additions & 2 deletions tools/run-change-queue.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,44 @@ class ChangeQueueRunner {
applyChangeToAnnotationFiles(change) {
// TODO: group by file and write them once
for (let annotationRef of change.annotations) {
let filePath = `${ANNOTATIONS_PATH}/${annotationRef.file}`
let content = utils.readJsonFile(filePath)
let res = this.readAnnotationFile(annotationRef.file)
let filePath = res[0]
let content = res[1]
let found = false
for (let annotation of content) {
if (annotation.id === annotationRef.id) {
this.applyChangeToAnnotation(change, annotation)
found = true
}
}
if (!found) {
// not necessarily an error,
// the ann may have been deleted by user after change was queued
throw new Error(`ERROR: annotation not found. (${filePath})`)
}
utils.writeJsonFile(filePath, content)
}
}

readAnnotationFile(filename) {
let filePath = `${ANNOTATIONS_PATH}/${filename}`
let content = utils.readJsonFile(filePath)
if (!content) {
console.log(`WARNING: annotation file not found. (${filePath})`)
// TODO: fix invalid file name in search.mjs
// gh-70: convert invalid file name
filePath = filePath.replace(
'https-crossreads-web-ox-ac-uk-api-dts-documents-id-',
'http-sicily-classics-ox-ac-uk-inscription-'
)
content = utils.readJsonFile(filePath)
if (!content) {
throw new Error(`ERROR: annotation file not found. (${filePath})`)
}
}
return [filePath, content]
}

applyChangeToAnnotation(change, annotation) {
if (change.tags) {
let annotationValue = annotation.body[0].value
Expand All @@ -55,6 +82,8 @@ class ChangeQueueRunner {
} else {
delete annotationValue.tags
}
} else {
throw new Error('WARNING: no tags in change.')
}
annotation.modifiedBy = change.creator
annotation.modified = change.created
Expand Down

0 comments on commit 9a46c45

Please sign in to comment.