diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java index 9f304372706..823e92782fd 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java @@ -1428,23 +1428,20 @@ public Collection getDetailsOfRecordIdentifierMis * @param maxNumber limit * @return list of "SelectItem" objects corresponding to given "ProcessDTO" objects. * @throws DAOException when checking whether user can link to given "ProcessDTO"s fails - * @throws IOException when opening ruleset file fails */ public ArrayList getPotentialParentProcesses(List parentCandidates, int maxNumber) - throws DAOException, IOException { + throws DAOException { ArrayList possibleParentProcesses = new ArrayList<>(); for (ProcessDTO process : parentCandidates.subList(0, Math.min(parentCandidates.size(), maxNumber))) { - if (ProcessService.canCreateChildProcess(process) || ProcessService.canCreateProcessWithCalendar(process)) { - SelectItem selectItem = new SelectItem(process.getId().toString(), process.getTitle()); - selectItem.setDisabled(!userMayLinkToParent(process.getId())); - if (!processInAssignedProject(process.getId())) { - String problem = Helper.getTranslation("projectNotAssignedToCurrentUser", process.getProject() - .getTitle()); - selectItem.setDescription(problem); - selectItem.setLabel(selectItem.getLabel() + " (" + problem + ")"); - } - possibleParentProcesses.add(selectItem); + SelectItem selectItem = new SelectItem(process.getId().toString(), process.getTitle()); + selectItem.setDisabled(!userMayLinkToParent(process.getId())); + if (!processInAssignedProject(process.getId())) { + String problem = Helper.getTranslation("projectNotAssignedToCurrentUser", process.getProject() + .getTitle()); + selectItem.setDescription(problem); + selectItem.setLabel(selectItem.getLabel() + " (" + problem + ")"); } + possibleParentProcesses.add(selectItem); } return possibleParentProcesses; } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java index 798c876e555..9ec0f5fba6f 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java @@ -818,11 +818,12 @@ public List findLinkableChildProcesses(String searchInput, int rules * @param rulesetId * the id of the allowed ruleset * @return found processes - * @throws DataException - * if the search engine fails + * @throws DataException if the search engine fails + * @throws DAOException when loading ruleset from database fails + * @throws IOException when opening ruleset file fails */ public List findLinkableParentProcesses(String searchInput, int rulesetId) - throws DataException { + throws DataException, DAOException, IOException { BoolQueryBuilder processQuery = new BoolQueryBuilder() .should(createSimpleWildcardQuery(ProcessTypeField.TITLE.getKey(), searchInput)); @@ -831,7 +832,13 @@ public List findLinkableParentProcesses(String searchInput, int rule } BoolQueryBuilder query = new BoolQueryBuilder().must(processQuery) .must(new MatchQueryBuilder(ProcessTypeField.RULESET.getKey(), rulesetId)); - return findByQueryInAllProjects(query, false); + List filteredProcesses = new ArrayList<>(); + for (ProcessDTO process : findByQueryInAllProjects(query, false)) { + if (ProcessService.canCreateChildProcess(process) || ProcessService.canCreateProcessWithCalendar(process)) { + filteredProcesses.add(process); + } + } + return filteredProcesses; } /** diff --git a/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceIT.java b/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceIT.java index effadfd5462..d9647d9a2f9 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/data/ProcessServiceIT.java @@ -317,7 +317,7 @@ public void shouldNotFindByTokenizedPropertyTitleAndWrongValue() throws DataExce } @Test - public void shouldFindLinkableParentProcesses() throws DataException { + public void shouldFindLinkableParentProcesses() throws DataException, DAOException, IOException { assertEquals("Processes were not found in index!", 1, processService.findLinkableParentProcesses("HierarchyParent", 1).size()); }