diff --git a/src/metax_api/migrations/0040_auto_20211006_1116.py b/src/metax_api/migrations/0040_auto_20211006_1116.py new file mode 100644 index 00000000..1256fb18 --- /dev/null +++ b/src/metax_api/migrations/0040_auto_20211006_1116.py @@ -0,0 +1,72 @@ +# Generated by Django 3.1.12 on 2021-10-06 08:16 + +from django.db import migrations + +import logging + +logger = logging.getLogger(__name__) + +def replace_relation_type_labels(cr, language, old_label, new_label): + logger.info(f"replacing relation type label ({language}): {old_label} with {new_label}") + if cr.research_dataset.get("relation"): + for item in cr.research_dataset["relation"]: + if item.get("relation_type"): + if item.get("relation_type").get("pref_label"): + if item.get("relation_type").get("pref_label").get(language): + if item["relation_type"]["pref_label"][language] == old_label: + item["relation_type"]["pref_label"][language] = new_label + logger.info("relation type label changed") + +datasets = [ + "c1974353-a4f6-40c3-9c1c-a7ec99e28ac8", + "7c12b39b-0bd4-4611-a764-85f328450e2b", + "ddd9854f-eb6a-4a8b-8f0d-2d2b9c405436", + "ef224b4b-6f0b-4776-ba33-6f8bd31855cc", + "0cfa3182-48a8-4483-8ebd-2636509b8363", + "0b6cfb0e-ea71-414f-abd3-88bb415b85fe", + "fe5e67ba-fc36-449d-b83e-e1e286cc9dda", + "254acb9a-32c7-45cd-9ac1-e52ef2d6174e", + "69b0360e-2ac8-4008-ac8d-c47b8c76d47e", + "087f9d18-5196-4e6e-83a0-dfe2d94c5aa6", + "a3aa061f-1263-4fb5-887b-a465f4c3a912", + "acf70d04-31f3-4e13-a422-666e39524b71", + "5cf11735-8422-4113-beb0-997c11b7c797", + "a5a04b82-6270-4e44-b357-a1344180bc1f" +] + +def change_relation_type_labels(apps, schema_editor): + CatalogRecord = apps.get_model('metax_api', 'CatalogRecord') + for cr in CatalogRecord.objects.filter(identifier__in=datasets): + try: + logger.info(f"changing relation type labels for cr {cr.identifier}") + replace_relation_type_labels(cr, "fi", "Liittyvä aineisto", "Liittyy") + replace_relation_type_labels(cr, "und", "Liittyvä aineisto", "Liittyy") + replace_relation_type_labels(cr, "en", "Related dataset", "Relation") + cr.save() + logger.info("cr save successful") + except Exception as e: + logger.error(e) + +def revert(apps, schema_editor): + CatalogRecord = apps.get_model('metax_api', 'CatalogRecord') + for cr in CatalogRecord.objects.filter(identifier__in=datasets): + try: + logger.info(f"changing relation type labels for cr {cr.identifier}") + replace_relation_type_labels(cr, "fi", "Liittyy", "Liittyvä aineisto") + replace_relation_type_labels(cr, "und", "Liittyy", "Liittyvä aineisto") + replace_relation_type_labels(cr, "en", "Relation", "Related dataset") + cr.save() + logger.info("cr save successful") + except Exception as e: + logger.error(e) + + +class Migration(migrations.Migration): + + dependencies = [ + ('metax_api', '0039_auto_20210908_1151'), + ] + + operations = [ + migrations.RunPython(change_relation_type_labels, revert), + ] \ No newline at end of file diff --git a/src/metax_api/tasks/refdata/refdata_indexer/resources/local-refdata/relation_type.json b/src/metax_api/tasks/refdata/refdata_indexer/resources/local-refdata/relation_type.json index 66401c9e..a57a2f22 100755 --- a/src/metax_api/tasks/refdata/refdata_indexer/resources/local-refdata/relation_type.json +++ b/src/metax_api/tasks/refdata/refdata_indexer/resources/local-refdata/relation_type.json @@ -1,4 +1,4 @@ -[{"id":"relation", "uri":"http://purl.org/dc/terms/relation", "label":{"fi":"Liittyvä aineisto", "en":"Related dataset"}}, +[{"id":"relation", "uri":"http://purl.org/dc/terms/relation", "label":{"fi":"Liittyy", "en":"Relation"}}, {"id":"cites", "uri":"http://purl.org/spar/cito/cites", "label":{"fi":"Viittaa", "en":"Cites"}}, {"id":"isCitedBy", "uri":"http://purl.org/spar/cito/isCitedBy", "label":{"fi":"Viitattu", "en":"Is cited by"}}, {"id":"isSupplementTo", "uri":"http://purl.org/vocab/frbr/core#isSupplementTo", "label":{"fi":"Viittaus tausta-aineistoon", "en":"Is supplement to"}},