FormProviderServiceImpl implements FormProviderService { @Override @SuppressWarnings("unchecked") public String getFormDisplayTask(long taskId) { Task task = taskService.execute(new GetUserTaskCommand(identityProvider.getName(), taskId)); if (task == null) { return ""; } String name = task.getName(); final String deploymentId = task.getTaskData().getDeploymentId(); final String processId = task.getTaskData().getProcessId(); ProcessDefinition processDesc = null; if(deploymentId != null && processId != null) { processDesc = dataService.getProcessesByDeploymentIdProcessId(deploymentId, processId); } Map<String, Object> renderContext = new HashMap<String, Object>(); ContentMarshallerContext marshallerContext = getMarshallerContext(task); Object input = null; long inputContentId = task.getTaskData().getDocumentContentId(); if (inputContentId != -1) { Content content = taskService.getContentById(inputContentId); input = ContentMarshallerHelper.unmarshall(content.getContent(), marshallerContext.getEnvironment(), marshallerContext.getClassloader()); } if (input == null) { input = new HashMap<String, Object>(); } Object output = null; long outputContentId = task.getTaskData().getOutputContentId(); if (outputContentId != -1) { Content content = taskService.getContentById(outputContentId); output = ContentMarshallerHelper.unmarshall(content.getContent(), marshallerContext.getEnvironment(), marshallerContext.getClassloader()); } if (output == null) { output = new HashMap<String, Object>(); } Map<String, Object> finalOutput = new HashMap<String, Object>(); if (processId != null && !processId.equals("")) { Map<String, String> taskOutputMappings = bpmn2Service.getTaskOutputMappings(deploymentId, processId, task.getName()); if (taskOutputMappings == null) { taskOutputMappings = new HashMap<String, String>(); } for (String key : taskOutputMappings.keySet()) { Object value = ((Map<String, Object>) output).get(key); if (value == null) { value = ""; } finalOutput.put(key, value); } } else if (output instanceof Map && !((Map)output).isEmpty()) { finalOutput.putAll( (Map<String, Object>) output ); } renderContext.put("task", task); renderContext.put("marshallerContext", marshallerContext); if (input instanceof Map) { renderContext.put("inputs", input); for (Map.Entry<String, Object> inputVar : ((Map<String, Object>) input).entrySet()) { renderContext.put(inputVar.getKey(), inputVar.getValue()); } } else { renderContext.put("input", input); } renderContext.put("outputs", finalOutput); for (Map.Entry<String, Object> outputVar : ((Map<String, Object>) finalOutput).entrySet()) { renderContext.put(outputVar.getKey(), outputVar.getValue()); } for (FormProvider provider : providers) { String template = provider.render(name, task, processDesc, renderContext); if (!StringUtils.isEmpty(template)) { return template; } } logger.warn("Unable to find form to render for task '{}' on process '{}'", name, processDesc == null ? "" : processDesc.getName()); return ""; }  void setTaskService(TaskService taskService); void setBpmn2Service(DefinitionService bpmn2Service); void setDataService(RuntimeDataService dataService); void setDeploymentService(DeploymentService deploymentService); void setProviders(Set<FormProvider> providers); void setIdentityProvider(IdentityProvider identityProvider); @Override String getFormDisplayProcess(String deploymentId, String processId); @Override @SuppressWarnings("unchecked") String getFormDisplayTask(long taskId);  }
@Test public void testGetFormDisplayTaskWithoutProcess() { long taskId = 1; final TaskImpl task = new TaskImpl(); task.setId(taskId); task.setName("TaskName"); task.setTaskData(new TaskDataImpl()); when(taskService.execute(any(GetUserTaskCommand.class))).thenReturn(task); final String form = formProviderService.getFormDisplayTask(1); assertEquals("", form); verify(dataService, never()).getProcessesByDeploymentIdProcessId(anyString(), anyString()); verify(formProvider).render(eq(task.getName()), eq(task), isNull(ProcessDefinition.class), anyMap()); }
@Test public void testGetFormDisplayTask() { long taskId = 1; final TaskImpl task = new TaskImpl(); task.setId(taskId); task.setName("TaskName"); final TaskDataImpl taskData = new TaskDataImpl(); final String deploymentId = "org.jbpm"; taskData.setDeploymentId(deploymentId); final String processId = "org.jbpm.evaluation"; taskData.setProcessId(processId); task.setTaskData(taskData); when(taskService.execute(any(GetUserTaskCommand.class))).thenReturn(task); final ProcessDefinition processDefinition = mock(ProcessDefinition.class); when(dataService.getProcessesByDeploymentIdProcessId(deploymentId, processId)).thenReturn(processDefinition); final String form = formProviderService.getFormDisplayTask(1); assertEquals("", form); verify(dataService).getProcessesByDeploymentIdProcessId(deploymentId, processId); verify(formProvider).render(eq(task.getName()), eq(task), eq(processDefinition), anyMap()); }