TerminateTaskMapper implements TaskMapper { @Override public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) { logger.debug("TaskMapperContext {} in TerminateTaskMapper", taskMapperContext); WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule(); Workflow workflowInstance = taskMapperContext.getWorkflowInstance(); String taskId = taskMapperContext.getTaskId(); Map<String, Object> taskInput = parametersUtils.getTaskInputV2(taskMapperContext.getTaskToSchedule().getInputParameters(), workflowInstance, taskId, null); Task task = new Task(); task.setTaskType(Terminate.TASK_NAME); task.setTaskDefName(taskToSchedule.getName()); task.setReferenceTaskName(taskToSchedule.getTaskReferenceName()); task.setWorkflowInstanceId(workflowInstance.getWorkflowId()); task.setWorkflowType(workflowInstance.getWorkflowName()); task.setCorrelationId(workflowInstance.getCorrelationId()); task.setScheduledTime(System.currentTimeMillis()); task.setStartTime(System.currentTimeMillis()); task.setInputData(taskInput); task.setTaskId(taskId); task.setStatus(Task.Status.IN_PROGRESS); task.setWorkflowTask(taskToSchedule); task.setWorkflowPriority(workflowInstance.getPriority()); return singletonList(task); } TerminateTaskMapper(ParametersUtils parametersUtils); @Override List<Task> getMappedTasks(TaskMapperContext taskMapperContext); static final Logger logger; }
@Test public void getMappedTasks() throws Exception { WorkflowTask taskToSchedule = new WorkflowTask(); taskToSchedule.setType(TaskType.TASK_TYPE_TERMINATE); String taskId = IDGenerator.generate(); WorkflowDef workflowDef = new WorkflowDef(); Workflow workflow = new Workflow(); workflow.setWorkflowDefinition(workflowDef); TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder() .withWorkflowDefinition(workflowDef) .withWorkflowInstance(workflow) .withTaskDefinition(new TaskDef()) .withTaskToSchedule(taskToSchedule) .withRetryCount(0) .withTaskId(taskId) .build(); List<Task> mappedTasks = new TerminateTaskMapper(parametersUtils).getMappedTasks(taskMapperContext); Assert.assertNotNull(mappedTasks); Assert.assertEquals(1, mappedTasks.size()); Assert.assertEquals(TaskType.TASK_TYPE_TERMINATE, mappedTasks.get(0).getTaskType()); }