Skip to content

Commit

Permalink
Move filtering of processes from ImportService to ProcessService
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Mar 7, 2024
1 parent da8b16a commit 807b185
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1428,23 +1428,20 @@ public Collection<RecordIdentifierMissingDetail> 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<SelectItem> getPotentialParentProcesses(List<ProcessDTO> parentCandidates, int maxNumber)
throws DAOException, IOException {
throws DAOException {
ArrayList<SelectItem> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,12 @@ public List<ProcessDTO> 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<ProcessDTO> findLinkableParentProcesses(String searchInput, int rulesetId)
throws DataException {
throws DataException, DAOException, IOException {

BoolQueryBuilder processQuery = new BoolQueryBuilder()
.should(createSimpleWildcardQuery(ProcessTypeField.TITLE.getKey(), searchInput));
Expand All @@ -831,7 +832,13 @@ public List<ProcessDTO> findLinkableParentProcesses(String searchInput, int rule
}
BoolQueryBuilder query = new BoolQueryBuilder().must(processQuery)
.must(new MatchQueryBuilder(ProcessTypeField.RULESET.getKey(), rulesetId));
return findByQueryInAllProjects(query, false);
List<ProcessDTO> filteredProcesses = new ArrayList<>();
for (ProcessDTO process : findByQueryInAllProjects(query, false)) {
if (ProcessService.canCreateChildProcess(process) || ProcessService.canCreateProcessWithCalendar(process)) {
filteredProcesses.add(process);
}
}
return filteredProcesses;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 807b185

Please sign in to comment.