use of com.axelor.apps.bpm.db.WkfTaskConfig in project axelor-open-suite by axelor.
the class WkfDisplayServiceImpl method addActiveNodes.
private void addActiveNodes(List<Map<String, Object>> statusList, WkfInstance wkfInstance, String klassName) {
HistoryService historyService = engineService.getEngine().getHistoryService();
List<HistoricActivityInstance> activeNodes = historyService.createHistoricActivityInstanceQuery().processInstanceId(wkfInstance.getInstanceId()).unfinished().list();
if (activeNodes.isEmpty()) {
List<String> terminatedNodeIds = getTerminatedActivityIds(wkfInstance.getInstanceId());
if (!terminatedNodeIds.isEmpty()) {
activeNodes = historyService.createHistoricActivityInstanceQuery().activityId(terminatedNodeIds.get(0)).processInstanceId(wkfInstance.getInstanceId()).list();
}
}
User activeUser = AuthUtils.getUser();
for (HistoricActivityInstance node : activeNodes) {
boolean valid = isValidNode(node.getActivityId(), wkfInstance.getWkfProcess(), klassName);
if (!valid) {
continue;
}
String title = node.getActivityName();
if (title == null) {
title = node.getActivityId();
}
String color = wkfInstance.getWkfProcess().getWkfModel().getWkfStatusColor();
if (color == null) {
color = "green";
}
Map<String, Object> statusMap = new HashMap<>();
statusMap.put("name", node.getActivityId());
statusMap.put("title", title);
statusMap.put("color", color);
if (!activeUser.getNoHelp()) {
WkfTaskConfig config = wkfTaskConfigRepository.all().filter("self.name = ? and self.wkfModel.id = ?", node.getActivityId(), wkfInstance.getWkfProcess().getWkfModel().getId()).fetchOne();
if (config != null) {
statusMap.put("help", config.getHelpText());
}
}
statusList.add(statusMap);
}
}
use of com.axelor.apps.bpm.db.WkfTaskConfig in project axelor-open-suite by axelor.
the class WkfTaskServiceImpl method runTasks.
@Override
public String runTasks(ProcessEngine engine, WkfInstance instance, ProcessInstance processInstance, String signal) throws ClassNotFoundException, AxelorException {
WkfProcess wkfProcess = instance.getWkfProcess();
List<Task> tasks = getActiveTasks(engine, processInstance.getId());
boolean taskExecuted = false;
String helpText = null;
Map<String, Object> context = getContext(instance);
// TODO: Check if its required both variables from context and from processInstance, if
Map<String, Object> processVariables = engine.getRuntimeService().getVariables(processInstance.getId());
processVariables.entrySet().removeIf(it -> Strings.isNullOrEmpty(it.getKey()));
Map<String, Object> expressionVariables = null;
Map<String, Object> ctxVariables = wkfService.createVariables(context);
for (Task task : tasks) {
WkfTaskConfig config = wkfTaskConfigRepository.all().filter("self.name = ? and self.wkfModel.id = ?", task.getTaskDefinitionKey(), wkfProcess.getWkfModel().getId()).fetchOne();
if (config == null) {
continue;
}
List<String> validButtons = getValidButtons(signal, config.getButton());
if (validButtons == null) {
continue;
}
if (expressionVariables == null) {
expressionVariables = new HashMap<String, Object>();
expressionVariables.putAll(processVariables);
expressionVariables.putAll(context);
}
if (!validButtons.isEmpty() || config.getExpression() != null) {
Map<String, Object> btnVariables = new HashMap<String, Object>();
for (String button : validButtons) {
btnVariables.put(button, button.equals(signal));
}
Map<String, Object> variables = wkfService.createVariables(btnVariables);
variables.putAll(ctxVariables);
if (config.getExpression() != null) {
expressionVariables.putAll(engine.getTaskService().getVariables(task.getId()));
expressionVariables.entrySet().removeIf(it -> Strings.isNullOrEmpty(it.getKey()));
Boolean validExpr = (Boolean) wkfService.evalExpression(expressionVariables, config.getExpression());
if (validExpr == null || !validExpr) {
log.debug("Not a valid expr: {}", config.getExpression());
if (!validButtons.isEmpty()) {
helpText = config.getHelpText();
}
continue;
}
log.debug("Valid expr: {}", config.getExpression());
}
User user = AuthUtils.getUser();
if (user != null) {
engine.getTaskService().setAssignee(task.getId(), user.getId().toString());
} else {
engine.getTaskService().setAssignee(task.getId(), "0");
}
engine.getTaskService().complete(task.getId(), variables);
taskExecuted = true;
}
}
Execution execution = engine.getRuntimeService().createExecutionQuery().active().executionId(processInstance.getId()).singleResult();
if (execution != null) {
engine.getRuntimeService().setVariables(execution.getId(), ctxVariables);
}
recursiveTaskExecutionCount++;
if (recursiveTaskExecutionCount >= RECURSIVE_TASK_EXECUTION_COUNT_LIMIT && ChronoUnit.SECONDS.between(recursiveTaskExecutionTime, LocalTime.now()) <= RECURSIVE_TASK_EXECUTION_SECONDS_LIMIT) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(ITranslation.INFINITE_EXECUTION));
}
if (taskExecuted && wkfInstanceService.isActiveProcessInstance(processInstance.getId(), engine.getRuntimeService())) {
log.debug("Check tasks again");
runTasks(engine, instance, processInstance, signal);
}
return helpText;
}
Aggregations