From 6b971b0c98d618dad8a9d6b9c39d84330826fc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kalle=20W=C3=A5hlin?= <72360110+kwahlin@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:39:43 +0100 Subject: [PATCH] Add script for moving age from genreForm to intendedAudience (#1345) --- .../11/lxl-4379-gf-to-intendedAudience.groovy | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 whelktool/scripts/cleanups/2023/11/lxl-4379-gf-to-intendedAudience.groovy diff --git a/whelktool/scripts/cleanups/2023/11/lxl-4379-gf-to-intendedAudience.groovy b/whelktool/scripts/cleanups/2023/11/lxl-4379-gf-to-intendedAudience.groovy new file mode 100644 index 0000000000..893a86569d --- /dev/null +++ b/whelktool/scripts/cleanups/2023/11/lxl-4379-gf-to-intendedAudience.groovy @@ -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() + } +}