SimpleActionProcessor implements ActionProcessor { private Map<String, Object> completeTask(Action action, Object payload, TaskDetails taskDetails, Status status, String event, String messageId) { Map<String, Object> input = new HashMap<>(); input.put("workflowId", taskDetails.getWorkflowId()); input.put("taskId", taskDetails.getTaskId()); input.put("taskRefName", taskDetails.getTaskRefName()); input.putAll(taskDetails.getOutput()); Map<String, Object> replaced = parametersUtils.replace(input, payload); String workflowId = (String) replaced.get("workflowId"); String taskId = (String) replaced.get("taskId"); String taskRefName = (String) replaced.get("taskRefName"); Task task = null; if (StringUtils.isNotEmpty(taskId)) { task = executor.getTask(taskId); } else if (StringUtils.isNotEmpty(workflowId) && StringUtils.isNotEmpty(taskRefName)) { Workflow workflow = executor.getWorkflow(workflowId, true); if (workflow == null) { replaced.put("error", "No workflow found with ID: " + workflowId); return replaced; } task = workflow.getTaskByRefName(taskRefName); } if (task == null) { replaced.put("error", "No task found with taskId: " + taskId + ", reference name: " + taskRefName + ", workflowId: " + workflowId); return replaced; } task.setStatus(status); task.setOutputData(replaced); task.setOutputMessage(taskDetails.getOutputMessage()); task.getOutputData().put("conductor.event.messageId", messageId); task.getOutputData().put("conductor.event.name", event); try { executor.updateTask(new TaskResult(task)); logger.debug("Updated task: {} in workflow:{} with status: {} for event: {} for message:{}", taskId, workflowId, status, event, messageId); } catch (RuntimeException e) { Monitors.recordEventActionError(action.getAction().name(), task.getTaskType(), event); logger.error("Error updating task: {} in workflow: {} in action: {} for event: {} for message: {}", taskDetails.getTaskRefName(), taskDetails.getWorkflowId(), action.getAction(), event, messageId, e); replaced.put("error", e.getMessage()); throw e; } return replaced; } @Inject  SimpleActionProcessor(WorkflowExecutor executor, ParametersUtils parametersUtils, JsonUtils jsonUtils); Map<String, Object> execute(Action action, Object payloadObject, String event, String messageId);  }
@Test public void testCompleteTask() throws Exception { TaskDetails taskDetails = new TaskDetails(); taskDetails.setWorkflowId("${workflowId}"); taskDetails.setTaskRefName("testTask"); taskDetails.getOutput().put("someNEKey", "${Message.someNEKey}"); taskDetails.getOutput().put("someKey", "${Message.someKey}"); taskDetails.getOutput().put("someNullKey", "${Message.someNullKey}"); Action action = new Action(); action.setAction(Type.complete_task); action.setComplete_task(taskDetails); String payloadJson = "{\"workflowId\":\"workflow_1\",\"Message\":{\"someKey\":\"someData\",\"someNullKey\":null}}"; Object payload = objectMapper.readValue(payloadJson, Object.class); Task task = new Task(); task.setReferenceTaskName("testTask"); Workflow workflow = new Workflow(); workflow.getTasks().add(task); when(workflowExecutor.getWorkflow(eq("workflow_1"), anyBoolean())).thenReturn(workflow); actionProcessor.execute(action, payload, "testEvent", "testMessage"); ArgumentCaptor<TaskResult> argumentCaptor = ArgumentCaptor.forClass(TaskResult.class); verify(workflowExecutor).updateTask(argumentCaptor.capture()); assertEquals(Status.COMPLETED, argumentCaptor.getValue().getStatus()); assertEquals("testMessage", argumentCaptor.getValue().getOutputData().get("conductor.event.messageId")); assertEquals("testEvent", argumentCaptor.getValue().getOutputData().get("conductor.event.name")); assertEquals("workflow_1", argumentCaptor.getValue().getOutputData().get("workflowId")); assertEquals("testTask", argumentCaptor.getValue().getOutputData().get("taskRefName")); assertEquals("someData", argumentCaptor.getValue().getOutputData().get("someKey")); assertTrue("testTask", argumentCaptor.getValue().getOutputData().containsKey("someNEKey")); assertTrue("testTask", argumentCaptor.getValue().getOutputData().containsKey("someNullKey")); assertNull("testTask", argumentCaptor.getValue().getOutputData().get("someNullKey")); }