Skip to content

Commit

Permalink
Optimize closing of processes
Browse files Browse the repository at this point in the history
  • Loading branch information
BartChris committed Sep 16, 2024
1 parent ec7fc5e commit da355d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,31 @@ public List<ProcessDTO> findLinkableChildProcesses(String searchInput, int rules
return linkableProcesses;
}

/**
* Checks whether all child processes of the given parent process are in a completed state.
*
* @param parentProcess The parent process whose child processes are being checked.
* @return true if all child processes are in a completed state, false otherwise.
*/
public boolean areAllChildProcessesInCompletedState(Process parentProcess) {
String hql = "SELECT count(c) FROM Process p WHERE p.parent = :parent "
+ "AND p.sortHelperStatus NOT IN (:completedStates)";

Map<String, Object> parameters = new HashMap<>();
parameters.put("parent", parentProcess);
parameters.put("completedStates", List.of(
ProcessState.COMPLETED20.getValue(),
ProcessState.COMPLETED.getValue()
));
try {
Long count = countDatabaseRows(hql, parameters);
return count == 0; // If count is 0, all child processes are completed
} catch (DAOException e) {
logger.error(e.getMessage(), e);
return false;
}
}

/**
* Searches for linkable processes based on user input. A process can be
* linked if it has the same rule set, belongs to the same client, and the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,13 @@ private void activateTasksForClosedTask(Task closedTask) throws DataException, I
TaskManager.addTask(thread);
}

closeParent(process);
if (closedTask.isLast()) {
closeParent(process);
}
}

private void closeParent(Process process) throws DataException {
if (Objects.nonNull(process.getParent()) && allChildrenClosed(process.getParent())) {
if (Objects.nonNull(process.getParent()) && ServiceManager.getProcessService().areAllChildProcessesInCompletedState(process)) {
process.getParent().setSortHelperStatus(ProcessState.COMPLETED.getValue());
ServiceManager.getProcessService().save(process.getParent());
closeParent(process.getParent());
Expand Down

0 comments on commit da355d9

Please sign in to comment.