-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1295 from libris/feature/lxl-4230
Add a cleanup script
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
whelktool/scripts/cleanups/2023/08/lxl-4230-move-more-bad-identifiedby.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
String where = "collection = 'bib' and data#>>'{@graph,1,identifiedBy}' like '%MTM medietyp%'" | ||
|
||
selectBySqlWhere(where) { data -> | ||
|
||
// Find the two relevant identifiers | ||
List identifiedBys = asList(data.graph[1].identifiedBy) | ||
Map medieTypIdentifier = identifiedBys.find { identifiedBy -> | ||
identifiedBy["typeNote"] == "MTM medietyp" | ||
} | ||
Map medieNummerIdentifier = identifiedBys.find { identifiedBy -> | ||
identifiedBy["typeNote"] == "MTM medienummer" | ||
} | ||
if (medieNummerIdentifier == null || medieTypIdentifier == null || medieTypIdentifier.value == null) | ||
return | ||
|
||
// Make sure there's a qualifier list in medieNummerIdentifier to put stuff in | ||
if (medieNummerIdentifier.qualifier == null) | ||
medieNummerIdentifier.put("qualifier", []) | ||
if (! medieNummerIdentifier.qualifier instanceof List) | ||
medieNummerIdentifier.put("qualifier", [medieNummerIdentifier.qualifier]) | ||
|
||
// Make the switch and drop the "medietyp" | ||
List qualifiers = medieNummerIdentifier.qualifier | ||
qualifiers.add(medieTypIdentifier.value) | ||
identifiedBys.remove(medieTypIdentifier) | ||
|
||
//System.err.println("ID by after change: " + identifiedBys) | ||
data.scheduleSave() | ||
} | ||
|
||
private List asList(Object o) { | ||
if (o == null) | ||
return [] | ||
if (o instanceof List) | ||
return o | ||
return [o] | ||
} |