Skip to content
Open
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
34 changes: 34 additions & 0 deletions whelktool/scripts/cleanups/2020/04/lxl-2963.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
PrintWriter scheduledForUpdating = getReportWriter("scheduled-updates")
PrintWriter failedUpdating = getReportWriter("failed-updates")

String where = "collection = 'bib' and data#>'{@graph,2,hasPart}' is not null"

selectBySqlWhere(where) { data ->
def (record, mainEntity, work) = data.graph

boolean changed = false

Object parts = work.hasPart
if ( parts == null || ! (parts instanceof List) )
return

Iterator it = parts.iterator()
while (it.hasNext()) {
Map part = (Map) it.next()

if (part.get("@type") != null && part.size() == 1) {
changed = true
it.remove()
}
}

if (parts.isEmpty())
work.remove("hasPart")

if (changed) {
scheduledForUpdating.println("${data.doc.getURI()}")
data.scheduleSave(onError: { e ->
failedUpdating.println("Failed to update ${data.doc.shortId} due to: $e")
})
}
}