JsonJQTransformTaskMapper implements TaskMapper { @Override public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) { LOGGER.debug("TaskMapperContext {} in JsonJQTransformTaskMapper", taskMapperContext); WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule(); Workflow workflowInstance = taskMapperContext.getWorkflowInstance(); String taskId = taskMapperContext.getTaskId(); TaskDef taskDefinition = Optional.ofNullable(taskMapperContext.getTaskDefinition()) .orElseGet(() -> Optional.ofNullable(metadataDAO.getTaskDef(taskToSchedule.getName())) .orElse(null)); Map<String, Object> taskInput = parametersUtils .getTaskInputV2(taskToSchedule.getInputParameters(), workflowInstance, taskId, taskDefinition); Task jsonJQTransformTask = new Task(); jsonJQTransformTask.setTaskType(taskToSchedule.getType()); jsonJQTransformTask.setTaskDefName(taskToSchedule.getName()); jsonJQTransformTask.setReferenceTaskName(taskToSchedule.getTaskReferenceName()); jsonJQTransformTask.setWorkflowInstanceId(workflowInstance.getWorkflowId()); jsonJQTransformTask.setWorkflowType(workflowInstance.getWorkflowName()); jsonJQTransformTask.setCorrelationId(workflowInstance.getCorrelationId()); jsonJQTransformTask.setStartTime(System.currentTimeMillis()); jsonJQTransformTask.setScheduledTime(System.currentTimeMillis()); jsonJQTransformTask.setInputData(taskInput); jsonJQTransformTask.setTaskId(taskId); jsonJQTransformTask.setStatus(Task.Status.IN_PROGRESS); jsonJQTransformTask.setWorkflowTask(taskToSchedule); jsonJQTransformTask.setWorkflowPriority(workflowInstance.getPriority()); return Collections.singletonList(jsonJQTransformTask); } JsonJQTransformTaskMapper(ParametersUtils parametersUtils, MetadataDAO metadataDAO); @Override List<Task> getMappedTasks(TaskMapperContext taskMapperContext); static final Logger LOGGER; }
@Test public void getMappedTasks() throws Exception { WorkflowTask taskToSchedule = new WorkflowTask(); taskToSchedule.setName("json_jq_transform_task"); taskToSchedule.setType(TaskType.JSON_JQ_TRANSFORM.name()); taskToSchedule.setTaskDefinition(new TaskDef("json_jq_transform_task")); Map<String, Object> taskInput = new HashMap<>(); taskInput.put("in1", new String[] {"a", "b"}); taskInput.put("in2", new String[] {"c", "d"}); taskInput.put("queryExpression", "{ out: (.in1 + .in2) }"); taskToSchedule.setInputParameters(taskInput); String taskId = IDGenerator.generate(); WorkflowDef wd = new WorkflowDef(); Workflow w = new Workflow(); w.setWorkflowDefinition(wd); TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder() .withWorkflowDefinition(wd) .withWorkflowInstance(w) .withTaskDefinition(new TaskDef()) .withTaskToSchedule(taskToSchedule) .withTaskInput(taskInput) .withRetryCount(0) .withTaskId(taskId) .build(); List<Task> mappedTasks = new JsonJQTransformTaskMapper(parametersUtils, metadataDAO).getMappedTasks(taskMapperContext); assertEquals(1, mappedTasks.size()); assertNotNull(mappedTasks); assertEquals(TaskType.JSON_JQ_TRANSFORM.name(), mappedTasks.get(0).getTaskType()); }
@Test public void getMappedTasks_WithoutTaskDef() throws Exception { WorkflowTask taskToSchedule = new WorkflowTask(); taskToSchedule.setName("json_jq_transform_task"); taskToSchedule.setType(TaskType.JSON_JQ_TRANSFORM.name()); Map<String, Object> taskInput = new HashMap<>(); taskInput.put("in1", new String[] {"a", "b"}); taskInput.put("in2", new String[] {"c", "d"}); taskInput.put("queryExpression", "{ out: (.in1 + .in2) }"); taskToSchedule.setInputParameters(taskInput); String taskId = IDGenerator.generate(); WorkflowDef wd = new WorkflowDef(); Workflow w = new Workflow(); w.setWorkflowDefinition(wd); TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder() .withWorkflowDefinition(wd) .withWorkflowInstance(w) .withTaskDefinition(null) .withTaskToSchedule(taskToSchedule) .withTaskInput(taskInput) .withRetryCount(0) .withTaskId(taskId) .build(); List<Task> mappedTasks = new JsonJQTransformTaskMapper(parametersUtils, metadataDAO).getMappedTasks(taskMapperContext); assertEquals(1, mappedTasks.size()); assertNotNull(mappedTasks); assertEquals(TaskType.JSON_JQ_TRANSFORM.name(), mappedTasks.get(0).getTaskType()); }