Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the update of the workflow state of processes #6228

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(p) 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,14 @@ 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.getParent())) {
process.getParent().setSortHelperStatus(ProcessState.COMPLETED.getValue());
ServiceManager.getProcessService().save(process.getParent());
closeParent(process.getParent());
Expand Down