SubWorkflowTaskMapper implements TaskMapper { @Override public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) { logger.debug("TaskMapperContext {} in SubWorkflowTaskMapper", taskMapperContext); WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule(); Workflow workflowInstance = taskMapperContext.getWorkflowInstance(); String taskId = taskMapperContext.getTaskId(); SubWorkflowParams subWorkflowParams = getSubWorkflowParams(taskToSchedule); Map<String, Object> resolvedParams = getSubWorkflowInputParameters(workflowInstance, subWorkflowParams); String subWorkflowName = resolvedParams.get("name").toString(); Integer subWorkflowVersion = getSubWorkflowVersion(resolvedParams, subWorkflowName); Object subWorkflowDefinition = resolvedParams.get("workflowDefinition"); Map subWorkflowTaskToDomain = null; Object uncheckedTaskToDomain = resolvedParams.get("taskToDomain"); if (uncheckedTaskToDomain instanceof Map) { subWorkflowTaskToDomain = (Map) uncheckedTaskToDomain; } Task subWorkflowTask = new Task(); subWorkflowTask.setTaskType(SubWorkflow.NAME); subWorkflowTask.setTaskDefName(taskToSchedule.getName()); subWorkflowTask.setReferenceTaskName(taskToSchedule.getTaskReferenceName()); subWorkflowTask.setWorkflowInstanceId(workflowInstance.getWorkflowId()); subWorkflowTask.setWorkflowType(workflowInstance.getWorkflowName()); subWorkflowTask.setCorrelationId(workflowInstance.getCorrelationId()); subWorkflowTask.setScheduledTime(System.currentTimeMillis()); subWorkflowTask.getInputData().put("subWorkflowName", subWorkflowName); subWorkflowTask.getInputData().put("subWorkflowVersion", subWorkflowVersion); subWorkflowTask.getInputData().put("subWorkflowTaskToDomain", subWorkflowTaskToDomain); subWorkflowTask.getInputData().put("subWorkflowDefinition", subWorkflowDefinition); subWorkflowTask.getInputData().put("workflowInput", taskMapperContext.getTaskInput()); subWorkflowTask.setTaskId(taskId); subWorkflowTask.setStatus(Task.Status.SCHEDULED); subWorkflowTask.setWorkflowTask(taskToSchedule); subWorkflowTask.setWorkflowPriority(workflowInstance.getPriority()); logger.debug("SubWorkflowTask {} created to be Scheduled", subWorkflowTask); return Collections.singletonList(subWorkflowTask); } @Inject  SubWorkflowTaskMapper(ParametersUtils parametersUtils, MetadataDAO metadataDAO); @Override List<Task> getMappedTasks(TaskMapperContext taskMapperContext);  }
@SuppressWarnings("unchecked") @Test public void getMappedTasks() { WorkflowDef workflowDef = new WorkflowDef(); Workflow workflowInstance = new Workflow(); workflowInstance.setWorkflowDefinition(workflowDef); WorkflowTask taskToSchedule = new WorkflowTask(); SubWorkflowParams subWorkflowParams = new SubWorkflowParams(); subWorkflowParams.setName("Foo"); subWorkflowParams.setVersion(2); taskToSchedule.setSubWorkflowParam(subWorkflowParams); Map<String, Object> taskInput = new HashMap<>(); Map<String, String> taskToDomain = new HashMap<String, String>() {{put("*", "unittest"); }}; Map<String, Object> subWorkflowParamMap = new HashMap<>(); subWorkflowParamMap.put("name", "FooWorkFlow"); subWorkflowParamMap.put("version", 2); subWorkflowParamMap.put("taskToDomain", taskToDomain); when(parametersUtils.getTaskInputV2(anyMap(), any(Workflow.class), any(), any())) .thenReturn(subWorkflowParamMap); TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder() .withWorkflowDefinition(workflowDef) .withWorkflowInstance(workflowInstance) .withTaskToSchedule(taskToSchedule) .withTaskInput(taskInput) .withRetryCount(0) .withTaskId(IDGenerator.generate()) .withDeciderService(deciderService) .build(); List<Task> mappedTasks = subWorkflowTaskMapper.getMappedTasks(taskMapperContext); assertTrue(!mappedTasks.isEmpty()); assertEquals(1, mappedTasks.size()); Task subWorkFlowTask = mappedTasks.get(0); assertEquals(Task.Status.SCHEDULED, subWorkFlowTask.getStatus()); assertEquals(SubWorkflow.NAME, subWorkFlowTask.getTaskType()); assertEquals(taskToDomain, subWorkFlowTask.getInputData().get("subWorkflowTaskToDomain")); }
@SuppressWarnings("unchecked") @Test public void testTaskToDomain() { WorkflowDef workflowDef = new WorkflowDef(); Workflow workflowInstance = new Workflow(); workflowInstance.setWorkflowDefinition(workflowDef); WorkflowTask taskToSchedule = new WorkflowTask(); Map<String, String> taskToDomain = new HashMap<String, String>() {{put("*", "unittest"); }}; SubWorkflowParams subWorkflowParams = new SubWorkflowParams(); subWorkflowParams.setName("Foo"); subWorkflowParams.setVersion(2); subWorkflowParams.setTaskToDomain(taskToDomain); taskToSchedule.setSubWorkflowParam(subWorkflowParams); Map<String, Object> taskInput = new HashMap<>(); Map<String, Object> subWorkflowParamMap = new HashMap<>(); subWorkflowParamMap.put("name", "FooWorkFlow"); subWorkflowParamMap.put("version", 2); when(parametersUtils.getTaskInputV2(anyMap(), any(Workflow.class), any(), any())) .thenReturn(subWorkflowParamMap); TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder() .withWorkflowDefinition(workflowDef) .withWorkflowInstance(workflowInstance) .withTaskToSchedule(taskToSchedule) .withTaskInput(taskInput) .withRetryCount(0) .withTaskId(IDGenerator.generate()) .withDeciderService(deciderService) .build(); List<Task> mappedTasks = subWorkflowTaskMapper.getMappedTasks(taskMapperContext); assertTrue(!mappedTasks.isEmpty()); assertEquals(1, mappedTasks.size()); Task subWorkFlowTask = mappedTasks.get(0); assertEquals(Task.Status.SCHEDULED, subWorkFlowTask.getStatus()); assertEquals(SubWorkflow.NAME, subWorkFlowTask.getTaskType()); }