Skip to content

Commit

Permalink
Preselect process in title record link tab
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Jan 2, 2024
1 parent 81a64f8 commit 0bc12e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 + ")");
}
Expand All @@ -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);
}
}
}
}

/**
Expand Down Expand Up @@ -442,24 +452,15 @@ public void setTitleRecordProcess(Process titleRecordProcess) {
*/
public void setParentAsTitleRecord(Process parentProcess) {
createProcessForm.setEditActiveTabIndex(CreateProcessForm.TITLE_RECORD_LINK_TAB_INDEX);
ArrayList<SelectItem> 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);
}

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;
}
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0bc12e0

Please sign in to comment.