From 0bc12e07731a2466eff12e90c5a47d95de49a80f Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Tue, 21 Nov 2023 12:32:41 +0100 Subject: [PATCH] Preselect process in title record link tab --- .../createprocess/TitleRecordLinkTab.java | 27 ++++++++++--------- .../resources/messages/messages_de.properties | 1 + .../resources/messages/messages_en.properties | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/TitleRecordLinkTab.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/TitleRecordLinkTab.java index 2709d7a951d..dfa31ef9b5a 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/TitleRecordLinkTab.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/TitleRecordLinkTab.java @@ -34,7 +34,6 @@ import org.kitodo.api.dataformat.LogicalDivision; import org.kitodo.api.dataformat.Workpiece; import org.kitodo.data.database.beans.Process; -import org.kitodo.data.database.beans.User; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.exceptions.DataException; import org.kitodo.production.dto.ProcessDTO; @@ -320,7 +319,7 @@ public void searchForParentProcesses() { selectItem.setDisabled(!(processInAssignedProject(process.getId()) || ServiceManager.getSecurityAccessService().hasAuthorityToLinkToProcessesOfUnassignedProjects())); if (!processInAssignedProject(process.getId())) { - String problem = "Project not assigned to current user!"; + String problem = Helper.getTranslation("projectNotAssignedToCurrentUser", process.getProject().getTitle()); selectItem.setDescription(problem); selectItem.setLabel(selectItem.getLabel() + " (" + problem + ")"); } @@ -332,6 +331,17 @@ public void searchForParentProcesses() { indicationOfMoreHitsVisible = false; possibleParentProcesses = Collections.emptyList(); } + for (SelectItem selectItem : possibleParentProcesses) { + if (!selectItem.isDisabled()) { + int processId = Integer.parseInt(selectItem.getValue().toString()); + try { + setParentAsTitleRecord(ServiceManager.getProcessService().getById(processId)); + break; + } catch (DAOException e) { + logger.error(e); + } + } + } } /** @@ -442,10 +452,7 @@ public void setTitleRecordProcess(Process titleRecordProcess) { */ public void setParentAsTitleRecord(Process parentProcess) { createProcessForm.setEditActiveTabIndex(CreateProcessForm.TITLE_RECORD_LINK_TAB_INDEX); - ArrayList parentCandidates = new ArrayList<>(); - parentCandidates.add(new SelectItem(parentProcess.getId().toString(), parentProcess.getTitle())); - createProcessForm.getTitleRecordLinkTab().setPossibleParentProcesses(parentCandidates); - createProcessForm.getTitleRecordLinkTab().setChosenParentProcess((String)parentCandidates.get(0).getValue()); + createProcessForm.getTitleRecordLinkTab().setChosenParentProcess(String.valueOf(parentProcess.getId())); createProcessForm.getTitleRecordLinkTab().chooseParentProcess(); Ajax.update(INSERTION_TREE); } @@ -453,13 +460,7 @@ public void setParentAsTitleRecord(Process parentProcess) { private Boolean processInAssignedProject(int processId) throws DAOException { Process process = ServiceManager.getProcessService().getById(processId); if (Objects.nonNull(process)) { - User currentUser = ServiceManager.getUserService().getCurrentUser(); - if (currentUser.getProjects().contains(process.getProject())) { - System.out.println("Current user has access to project of selected parent process!"); - } else { - System.out.println("Current user does NOT have access to project of selected parent process!"); - } - return currentUser.getProjects().contains(process.getProject()); + return ServiceManager.getUserService().getCurrentUser().getProjects().contains(process.getProject()); } return false; } diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index 43be7e28d89..f9f50553c7c 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -925,6 +925,7 @@ projectConfiguration=Projektkonfiguration projectIsActive=Projekt ist aktiv projectIsArchived=Projekt ist inaktiv projectList=Projektliste +projectNotAssignedToCurrentUser=Das Projekt "{0}" ist Ihnen nicht zugewiesen! projectProgress=Projektentwicklung projects=Projekte projectsForMigration=Bitte Projekte f\u00FCr die Migration ausw\u00E4hlen diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index 310a09a79eb..bcffe03d9cc 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -926,6 +926,7 @@ projectConfiguration=Project configuration projectIsActive=project active projectIsArchived=project inactive projectList=Projects list +projectNotAssignedToCurrentUser=Project "{0}" not assigned to current user! projectProgress=Project progress projects=Projects projectsForMigration=Please select projects for migration