Skip to content

Commit

Permalink
Fix serialisation of locales
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheus-87 committed Jan 8, 2025
1 parent 6622a68 commit df72d2e
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,6 +97,13 @@ public String getLocalizedLanguageString(Locale locale, Locale displayLocale) {
return localizedLanguageString;
}

public List<String> sortAndMapLanguages(
Locale displayLocale, Collection<Locale> languagesToSortAndMap) {
return sortLanguages(displayLocale, languagesToSortAndMap).stream()
.map(Locale::toLanguageTag)
.collect(Collectors.toCollection(LinkedList::new));
}

public List<Locale> sortLanguages(Locale displayLocale, Collection<Locale> languagesToSort) {
List<Locale> sortedLanguages =
prioritisedSortedLanguages.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
Article article = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, article.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
Collection collection = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, collection.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
Event event = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, event.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
HeadwordEntry headwordEntry = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, headwordEntry.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
Project project = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, project.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
Topic topic = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, topic.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public String edit(
if (useReact) {
final Locale displayLocale = LocaleContextHolder.getLocale();
Website website = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, website.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
CorporateBody corporateBody = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, corporateBody.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
Person person = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, person.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,9 +46,7 @@ public String edit(
final Locale displayLocale = LocaleContextHolder.getLocale();
Work work = service.getByUuid(uuid);
List<String> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
FileResource fileResource = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, fileResource.getLabel().getLocales());
List<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public String edit(
throws TechnicalException {
final Locale displayLocale = LocaleContextHolder.getLocale();
Webpage webpage = service.getByUuid(uuid);
List<Locale> existingLanguages =
languageService.sortLanguages(displayLocale, webpage.getLabel().getLocales());
List<String> 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));
}
Expand Down

0 comments on commit df72d2e

Please sign in to comment.