Skip to content

Commit

Permalink
Add script for moving age from genreForm to intendedAudience (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwahlin authored Nov 30, 2023
1 parent 7d7da17 commit 6b971b0
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Set iaLabels = ['0-3 år', '3-6 år', '6-9 år', '9-12 år', '12-15 år', '15']

def where = """
collection = 'bib'
and deleted = false
and data #>> '{@graph,1,instanceOf,genreForm}' is not null
"""

selectBySqlWhere(where) { bib ->
def work = bib.graph[1].instanceOf
def toIntendedAudience = []
work.genreForm.removeAll { gf ->
if (gf.prefLabel in iaLabels) {
toIntendedAudience.add(gf.prefLabel)
}
}
if (work.genreForm.isEmpty()) {
work.remove('genreForm')
}
if (toIntendedAudience) {
toIntendedAudience.each { label ->
if (!asList(work.intendedAudience).any { ia -> ia.label == label }) {
work['intendedAudience'] = asList(work.intendedAudience) + ['@type': 'IntendedAudience', 'label': label]
}
}
bib.scheduleSave()
}
}

0 comments on commit 6b971b0

Please sign in to comment.