Skip to content

Commit

Permalink
Save before reporting to make sure no data is changed before saving
Browse files Browse the repository at this point in the history
  • Loading branch information
kwahlin committed Nov 15, 2023
1 parent 3756a0e commit 7f90c3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
41 changes: 23 additions & 18 deletions librisworks/scripts/merge-works.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,26 @@ new File(System.getProperty('clusters')).splitEachLine(~/[\t ]+/) { cluster ->
List<String> linkableWorkIris = uniqueWorksAndTheirInstances.findResults { it.getV1().workIri() }

uniqueWorksAndTheirInstances.each { Doc workDoc, List<Doc> instanceDocs ->
if (!workDoc.instanceData) {
if (workDoc.existsInStorage) {
if (instanceDocs) {
replaceWorkData(workDoc, c.merge([workDoc] + instanceDocs))
// TODO: Update adminMetadata? To say that additional instances may have contributed to the linked work.
writeWorkReport(docs, workDoc, instanceDocs, WorkStatus.UPDATED)
}
} else {
addAdminMetadata(workDoc, instanceDocs.collect { ['@id': it.recordIri()] })
writeWorkReport(docs, workDoc, instanceDocs, WorkStatus.NEW)
}
// Link more instances to existing linked work
if (workDoc.existsInStorage && !workDoc.instanceData && instanceDocs) {
replaceWorkData(workDoc, c.merge([workDoc] + instanceDocs))
// TODO: Update adminMetadata? To say that additional instances may have contributed to the linked work.
addCloseMatch(workDoc, linkableWorkIris)
saveAndLink(workDoc, instanceDocs, workDoc.existsInStorage)
} else {
if (addCloseMatch(workDoc, linkableWorkIris)) {
saveAndLink(workDoc)
}
writeWorkReport(docs, workDoc, instanceDocs, WorkStatus.UPDATED)
return
}
// New merged work
if (!workDoc.existsInStorage && !workDoc.instanceData) {
addAdminMetadata(workDoc, instanceDocs.collect { ['@id': it.recordIri()] })
addCloseMatch(workDoc, linkableWorkIris)
saveAndLink(workDoc, instanceDocs, workDoc.existsInStorage)
writeWorkReport(docs, workDoc, instanceDocs, WorkStatus.NEW)
return
}
// Local work, save if new closeMatch links created
if (workDoc.instanceData && addCloseMatch(workDoc, linkableWorkIris)) {
saveAndLink(workDoc)
}
}

Expand All @@ -96,9 +99,11 @@ void saveAndLink(Doc workDoc, Collection<Doc> instanceDocs = [], boolean existsI
}
}

selectByIds(instanceDocs.collect { it.shortId() }) {
it.graph[1]['instanceOf'] = ['@id': workDoc.thingIri()]
it.scheduleSave(changedBy: changedBy, generationProcess: generationProcess)
if (!instanceDocs.isEmpty()) {
selectByIds(instanceDocs.collect { it.shortId() }) {
it.graph[1]['instanceOf'] = ['@id': workDoc.thingIri()]
it.scheduleSave(changedBy: changedBy, generationProcess: generationProcess)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,9 @@ class DisplayDoc {

Map getFramed() {
if (!framed) {
if (doc.existsInStorage) {
framed = JsonLd.frame(doc.thingIri(), doc.whelk.loadEmbellished(doc.shortId()).data)
} else {
Document copy = doc.document.clone()
doc.whelk.embellish(copy)
framed = JsonLd.frame(doc.thingIri(), copy.data)
}
Document copy = doc.document.clone()
doc.whelk.embellish(copy)
framed = JsonLd.frame(doc.thingIri(), copy.data)
}

return framed
Expand Down

0 comments on commit 7f90c3c

Please sign in to comment.