DecisionTaskMapper implements TaskMapper { @Override public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) { logger.debug("TaskMapperContext {} in DecisionTaskMapper", taskMapperContext); List<Task> tasksToBeScheduled = new LinkedList<>(); WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule(); Workflow workflowInstance = taskMapperContext.getWorkflowInstance(); Map<String, Object> taskInput = taskMapperContext.getTaskInput(); int retryCount = taskMapperContext.getRetryCount(); String taskId = taskMapperContext.getTaskId(); String caseValue = getEvaluatedCaseValue(taskToSchedule, taskInput); Task decisionTask = new Task(); decisionTask.setTaskType(SystemTaskType.DECISION.name()); decisionTask.setTaskDefName(SystemTaskType.DECISION.name()); decisionTask.setReferenceTaskName(taskToSchedule.getTaskReferenceName()); decisionTask.setWorkflowInstanceId(workflowInstance.getWorkflowId()); decisionTask.setWorkflowType(workflowInstance.getWorkflowName()); decisionTask.setCorrelationId(workflowInstance.getCorrelationId()); decisionTask.setScheduledTime(System.currentTimeMillis()); decisionTask.getInputData().put("case", caseValue); decisionTask.getOutputData().put("caseOutput", Collections.singletonList(caseValue)); decisionTask.setTaskId(taskId); decisionTask.setStartTime(System.currentTimeMillis()); decisionTask.setStatus(Task.Status.IN_PROGRESS); decisionTask.setWorkflowTask(taskToSchedule); decisionTask.setWorkflowPriority(workflowInstance.getPriority()); tasksToBeScheduled.add(decisionTask); List<WorkflowTask> selectedTasks = taskToSchedule.getDecisionCases().get(caseValue); if (selectedTasks == null || selectedTasks.isEmpty()) { selectedTasks = taskToSchedule.getDefaultCase(); } if (selectedTasks != null && !selectedTasks.isEmpty()) { WorkflowTask selectedTask = selectedTasks.get(0); List<Task> caseTasks = taskMapperContext.getDeciderService().getTasksToBeScheduled(workflowInstance, selectedTask, retryCount, taskMapperContext.getRetryTaskId()); tasksToBeScheduled.addAll(caseTasks); decisionTask.getInputData().put("hasChildren", "true"); } return tasksToBeScheduled; }  @Override List<Task> getMappedTasks(TaskMapperContext taskMapperContext);  }
@Test public void getMappedTasks() { TaskDef taskDef = new TaskDef(); Map<String, Object> inputMap = new HashMap<>(); inputMap.put("Id", "${workflow.input.Id}"); List<Map<String, Object>> taskDefinitionInput = new LinkedList<>(); taskDefinitionInput.add(inputMap); WorkflowTask decisionTask = new WorkflowTask(); decisionTask.setType(TaskType.DECISION.name()); decisionTask.setName("Decision"); decisionTask.setTaskReferenceName("decisionTask"); decisionTask.setDefaultCase(Arrays.asList(task1)); decisionTask.setCaseValueParam("case"); decisionTask.getInputParameters().put("Id", "${workflow.input.Id}"); decisionTask.setCaseExpression("if ($.Id == null) 'bad input'; else if ( ($.Id != null && $.Id % 2 == 0)) 'even'; else 'odd'; "); Map<String, List<WorkflowTask>> decisionCases = new HashMap<>(); decisionCases.put("even", Arrays.asList(task2)); decisionCases.put("odd", Arrays.asList(task3)); decisionTask.setDecisionCases(decisionCases); WorkflowDef workflowDef = new WorkflowDef(); workflowDef.setSchemaVersion(2); Workflow workflowInstance = new Workflow(); workflowInstance.setWorkflowDefinition(workflowDef); Map<String, Object> workflowInput = new HashMap<>(); workflowInput.put("Id", "22"); workflowInstance.setInput(workflowInput); Map<String, Object> body = new HashMap<>(); body.put("input", taskDefinitionInput); taskDef.getInputTemplate().putAll(body); Map<String, Object> input = parametersUtils.getTaskInput(decisionTask.getInputParameters(), workflowInstance, null, null); Task theTask = new Task(); theTask.setReferenceTaskName("Foo"); theTask.setTaskId(IDGenerator.generate()); when(deciderService.getTasksToBeScheduled(workflowInstance, task2, 0, null)) .thenReturn(Arrays.asList(theTask)); TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder() .withWorkflowDefinition(workflowDef) .withWorkflowInstance(workflowInstance) .withTaskToSchedule(decisionTask) .withTaskInput(input) .withRetryCount(0) .withTaskId(IDGenerator.generate()) .withDeciderService(deciderService) .build(); List<Task> mappedTasks = decisionTaskMapper.getMappedTasks(taskMapperContext); assertEquals(2, mappedTasks.size()); assertEquals("decisionTask", mappedTasks.get(0).getReferenceTaskName()); assertEquals("Foo", mappedTasks.get(1).getReferenceTaskName()); }