From df72d2ec2c24f9c5f3a4418bbb6ad6724d620687 Mon Sep 17 00:00:00 2001 From: Matthias Lindinger Date: Wed, 8 Jan 2025 13:12:15 +0100 Subject: [PATCH] Fix serialisation of locales --- CHANGELOG.md | 4 ++++ .../dbmdz/cudami/business/i18n/LanguageService.java | 8 ++++++++ .../identifiable/entity/ArticlesController.java | 8 ++++---- .../identifiable/entity/CollectionsController.java | 8 ++++---- .../controller/identifiable/entity/EventsController.java | 8 ++++---- .../identifiable/entity/HeadwordEntriesController.java | 8 ++++---- .../identifiable/entity/ProjectsController.java | 8 ++++---- .../controller/identifiable/entity/TopicsController.java | 8 ++++---- .../identifiable/entity/WebsitesController.java | 8 ++++---- .../entity/agent/CorporateBodiesController.java | 8 ++++---- .../identifiable/entity/agent/PersonsController.java | 8 ++++---- .../identifiable/entity/work/WorksController.java | 6 +----- .../resource/FileResourcesMetadataController.java | 8 ++++---- .../controller/identifiable/web/WebpagesController.java | 8 ++++---- 14 files changed, 57 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a17e43ec4..41ca342cfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added functionality to disable URL aliases at all +### Fixed + +- Fixed serialisation of locales + ## [9.3.0](https://github.com/dbmdz/cudami/releases/tag/9.3.0) – 2025-01-07 ### Changed diff --git a/src/main/java/io/github/dbmdz/cudami/business/i18n/LanguageService.java b/src/main/java/io/github/dbmdz/cudami/business/i18n/LanguageService.java index 4bd909ed2a..5c490a229e 100644 --- a/src/main/java/io/github/dbmdz/cudami/business/i18n/LanguageService.java +++ b/src/main/java/io/github/dbmdz/cudami/business/i18n/LanguageService.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.stream.Collectors; @@ -96,6 +97,13 @@ public String getLocalizedLanguageString(Locale locale, Locale displayLocale) { return localizedLanguageString; } + public List sortAndMapLanguages( + Locale displayLocale, Collection languagesToSortAndMap) { + return sortLanguages(displayLocale, languagesToSortAndMap).stream() + .map(Locale::toLanguageTag) + .collect(Collectors.toCollection(LinkedList::new)); + } + public List sortLanguages(Locale displayLocale, Collection languagesToSort) { List sortedLanguages = prioritisedSortedLanguages.stream() diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/ArticlesController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/ArticlesController.java index 9b1fab0af9..f17219def6 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/ArticlesController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/ArticlesController.java @@ -44,11 +44,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); Article article = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, article.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, article.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/CollectionsController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/CollectionsController.java index 73dd92b0f8..9d056a6d21 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/CollectionsController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/CollectionsController.java @@ -54,11 +54,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); Collection collection = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, collection.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, collection.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/EventsController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/EventsController.java index 3094539361..36475a4d51 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/EventsController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/EventsController.java @@ -40,11 +40,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); Event event = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, event.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, event.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/HeadwordEntriesController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/HeadwordEntriesController.java index 8038bce53d..3163383e5f 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/HeadwordEntriesController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/HeadwordEntriesController.java @@ -45,11 +45,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); HeadwordEntry headwordEntry = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, headwordEntry.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, headwordEntry.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/ProjectsController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/ProjectsController.java index 501b6195d5..ddeee4c414 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/ProjectsController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/ProjectsController.java @@ -44,11 +44,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); Project project = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, project.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, project.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/TopicsController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/TopicsController.java index 51289c5489..d1293bd41c 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/TopicsController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/TopicsController.java @@ -53,11 +53,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); Topic topic = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, topic.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, topic.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/WebsitesController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/WebsitesController.java index 0d60ad1baa..38702f3f15 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/WebsitesController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/WebsitesController.java @@ -79,11 +79,11 @@ public String edit( if (useReact) { final Locale displayLocale = LocaleContextHolder.getLocale(); Website website = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, website.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, website.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/agent/CorporateBodiesController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/agent/CorporateBodiesController.java index 9cf672509c..d3edbf77ff 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/agent/CorporateBodiesController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/agent/CorporateBodiesController.java @@ -46,11 +46,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); CorporateBody corporateBody = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, corporateBody.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, corporateBody.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/agent/PersonsController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/agent/PersonsController.java index 7411e87336..c05ecca7b1 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/agent/PersonsController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/agent/PersonsController.java @@ -45,11 +45,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); Person person = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, person.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, person.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/work/WorksController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/work/WorksController.java index 8131b25f22..75a238aabe 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/work/WorksController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/entity/work/WorksController.java @@ -8,11 +8,9 @@ import io.github.dbmdz.cudami.business.i18n.LanguageService; import io.github.dbmdz.cudami.controller.ParameterHelper; import io.github.dbmdz.cudami.controller.identifiable.entity.AbstractEntitiesController; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.UUID; -import java.util.stream.Collectors; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -48,9 +46,7 @@ public String edit( final Locale displayLocale = LocaleContextHolder.getLocale(); Work work = service.getByUuid(uuid); List existingLanguages = - languageService.sortLanguages(displayLocale, work.getLabel().getLocales()).stream() - .map(Locale::toLanguageTag) - .collect(Collectors.toCollection(ArrayList::new)); + languageService.sortAndMapLanguages(displayLocale, work.getLabel().getLocales()); if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/resource/FileResourcesMetadataController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/resource/FileResourcesMetadataController.java index b22d014b5c..19256df2bb 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/resource/FileResourcesMetadataController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/resource/FileResourcesMetadataController.java @@ -47,11 +47,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); FileResource fileResource = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, fileResource.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, fileResource.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); } diff --git a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/web/WebpagesController.java b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/web/WebpagesController.java index 72a1baac0e..546187f545 100644 --- a/src/main/java/io/github/dbmdz/cudami/controller/identifiable/web/WebpagesController.java +++ b/src/main/java/io/github/dbmdz/cudami/controller/identifiable/web/WebpagesController.java @@ -65,11 +65,11 @@ public String edit( throws TechnicalException { final Locale displayLocale = LocaleContextHolder.getLocale(); Webpage webpage = service.getByUuid(uuid); - List existingLanguages = - languageService.sortLanguages(displayLocale, webpage.getLabel().getLocales()); + List existingLanguages = + languageService.sortAndMapLanguages(displayLocale, webpage.getLabel().getLocales()); - if (activeLanguage != null && existingLanguages.contains(activeLanguage)) { - model.addAttribute("activeLanguage", activeLanguage); + if (activeLanguage != null && existingLanguages.contains(activeLanguage.toLanguageTag())) { + model.addAttribute("activeLanguage", activeLanguage.toLanguageTag()); } else { model.addAttribute("activeLanguage", existingLanguages.get(0)); }