From 2e196a694e18dfb3ade55af054d1796c4f436994 Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Fri, 6 Oct 2023 15:32:52 +0200 Subject: [PATCH] Sort projects by title in row expansion and popup dialog --- .../forms/createprocess/SelectProjectDialogView.java | 5 ++++- .../kitodo/production/services/data/TemplateService.java | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/SelectProjectDialogView.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/SelectProjectDialogView.java index 5f0e37652e3..97f59cf7800 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/SelectProjectDialogView.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/SelectProjectDialogView.java @@ -14,7 +14,9 @@ import java.io.IOException; import java.io.Serializable; import java.util.Collections; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; import javax.faces.context.FacesContext; import javax.faces.view.ViewScoped; @@ -85,7 +87,8 @@ public void setSelectedProjectId(int projectId) { public List getTemplateProjects() { try { Template template = ServiceManager.getTemplateService().getById(this.templateDTO.getId()); - return template.getProjects(); + return template.getProjects().stream().sorted(Comparator.comparing(Project::getTitle)) + .collect(Collectors.toList()); } catch (DAOException e) { Helper.setErrorMessage(ERROR_LOADING_ONE, new Object[] {ObjectType.TEMPLATE.getTranslationSingular(), this.templateDTO.getId()}, logger, e); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/TemplateService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/TemplateService.java index b196f66d095..cdb2be13383 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/TemplateService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/TemplateService.java @@ -17,11 +17,13 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -41,6 +43,7 @@ import org.kitodo.data.elasticsearch.search.Searcher; import org.kitodo.data.exceptions.DataException; import org.kitodo.exceptions.ProcessGenerationException; +import org.kitodo.production.dto.ProjectDTO; import org.kitodo.production.dto.TaskDTO; import org.kitodo.production.dto.TemplateDTO; import org.kitodo.production.dto.WorkflowDTO; @@ -204,7 +207,8 @@ public TemplateDTO convertJSONObjectToDTO(Map jsonObject, boolea private void convertRelatedJSONObjects(Map jsonObject, TemplateDTO templateDTO) throws DataException { templateDTO.setProjects(convertRelatedJSONObjectToDTO(jsonObject, TemplateTypeField.PROJECTS.getKey(), - ServiceManager.getProjectService())); + ServiceManager.getProjectService()).stream().sorted(Comparator.comparing(ProjectDTO::getTitle)) + .collect(Collectors.toList())); } /**