@Test public void testGenerateDefaultFormWithVariables() { DefinitionService definitionService = mock(DefinitionService.class); UserTaskService userTaskService = mock(UserTaskService.class); FormManagerService formManagerService = mock(FormManagerService.class); CaseRuntimeDataService caseRuntimeDataService = mock(CaseRuntimeDataService.class); KieServerRegistry registry = mock(KieServerRegistry.class); ProcessDefinition processDefinition = mock(ProcessDefinition.class); when(processDefinition.getId()).thenReturn("testprocess"); when(processDefinition.getName()).thenReturn("Test Process"); Map<String, String> variables = new HashMap<>(); variables.put("name", "java.lang.String"); variables.put("age", "java.lang.Integer"); variables.put("maried", "java.lang.Boolean"); when(processDefinition.getProcessVariables()).thenReturn(variables); FormRendererBase rendererBase = new FormRendererBase(definitionService, userTaskService, formManagerService, caseRuntimeDataService, registry); when(registry.getContainerId(any(), any())).thenReturn("test"); when(definitionService.getProcessDefinition(eq("test"), eq("test-process"))).thenReturn(processDefinition); String result = rendererBase.getProcessRenderedForm("patternfly", "test", "test-process"); assertThat(result).contains("/files/patternfly/css/patternfly.min.css\" rel=\"stylesheet\">"); assertThat(result).contains("/files/patternfly/css/patternfly-additions.min.css\" rel=\"stylesheet\">"); assertThat(result).contains("/files/patternfly/js/jquery.min.js\"></script>"); assertThat(result).contains("/files/patternfly/js/patternfly.min.js\"></script>"); assertThat(result).contains("/files/js/kieserver-ui.js\"></script>"); assertThat(result).contains("<h3 class=\"panel-title\">Default form - Test Process</h3>"); assertThat(result).contains("<input name=\"maried\" type=\"checkbox\" class=\"form-control\" "); assertThat(result).contains("<input name=\"name\" type=\"text\" class=\"form-control\" "); assertThat(result).contains("<input name=\"age\" type=\"text\" class=\"form-control\" "); assertThat(result).contains("<button type=\"button\" class=\"btn btn-primary\" onclick=\"startProcess(this);\">Submit</button>"); }
public String getProcessRenderedForm(String renderer, String containerId, String processId) { String resolvedContainerId = registry.getContainerId(containerId, ContainerLocatorProvider.get().getLocator()); ProcessDefinition processDesc = definitionService.getProcessDefinition(resolvedContainerId, processId); if (processDesc == null) { throw new ProcessDefinitionNotFoundException("Process definition " + resolvedContainerId + " : " + processId + " not found"); } String formStructure = formManagerService.getFormByKey(resolvedContainerId, processId + SUPPORTED_FORM_SUFFIX); FormInstance form = formReader.readFromString(formStructure); if (form == null) { form = generateDefaultProcessForm(processDesc); } form.setNestedFormsLookup(formId -> { Map<String, String> forms = indexedForms.get(resolvedContainerId); String formStructureNested = forms.get(formId); return formReader.readFromString(formStructureNested); }); FormRenderer formRenderer = renderers.get(renderer); if (formRenderer == null) { throw new IllegalArgumentException("Form renderer with name " + renderer + " not found"); } String output = formRenderer.renderProcess(resolvedContainerId, processDesc, form); return output; }
FormRendererBase { public String getProcessRenderedForm(String renderer, String containerId, String processId) { String resolvedContainerId = registry.getContainerId(containerId, ContainerLocatorProvider.get().getLocator()); ProcessDefinition processDesc = definitionService.getProcessDefinition(resolvedContainerId, processId); if (processDesc == null) { throw new ProcessDefinitionNotFoundException("Process definition " + resolvedContainerId + " : " + processId + " not found"); } String formStructure = formManagerService.getFormByKey(resolvedContainerId, processId + SUPPORTED_FORM_SUFFIX); FormInstance form = formReader.readFromString(formStructure); if (form == null) { form = generateDefaultProcessForm(processDesc); } form.setNestedFormsLookup(formId -> { Map<String, String> forms = indexedForms.get(resolvedContainerId); String formStructureNested = forms.get(formId); return formReader.readFromString(formStructureNested); }); FormRenderer formRenderer = renderers.get(renderer); if (formRenderer == null) { throw new IllegalArgumentException("Form renderer with name " + renderer + " not found"); } String output = formRenderer.renderProcess(resolvedContainerId, processDesc, form); return output; } }
FormRendererBase { public String getProcessRenderedForm(String renderer, String containerId, String processId) { String resolvedContainerId = registry.getContainerId(containerId, ContainerLocatorProvider.get().getLocator()); ProcessDefinition processDesc = definitionService.getProcessDefinition(resolvedContainerId, processId); if (processDesc == null) { throw new ProcessDefinitionNotFoundException("Process definition " + resolvedContainerId + " : " + processId + " not found"); } String formStructure = formManagerService.getFormByKey(resolvedContainerId, processId + SUPPORTED_FORM_SUFFIX); FormInstance form = formReader.readFromString(formStructure); if (form == null) { form = generateDefaultProcessForm(processDesc); } form.setNestedFormsLookup(formId -> { Map<String, String> forms = indexedForms.get(resolvedContainerId); String formStructureNested = forms.get(formId); return formReader.readFromString(formStructureNested); }); FormRenderer formRenderer = renderers.get(renderer); if (formRenderer == null) { throw new IllegalArgumentException("Form renderer with name " + renderer + " not found"); } String output = formRenderer.renderProcess(resolvedContainerId, processDesc, form); return output; } FormRendererBase(DefinitionService definitionService, UserTaskService userTaskService, FormManagerService formManagerService, CaseRuntimeDataService caseRuntimeDataService, KieServerRegistry registry); }
FormRendererBase { public String getProcessRenderedForm(String renderer, String containerId, String processId) { String resolvedContainerId = registry.getContainerId(containerId, ContainerLocatorProvider.get().getLocator()); ProcessDefinition processDesc = definitionService.getProcessDefinition(resolvedContainerId, processId); if (processDesc == null) { throw new ProcessDefinitionNotFoundException("Process definition " + resolvedContainerId + " : " + processId + " not found"); } String formStructure = formManagerService.getFormByKey(resolvedContainerId, processId + SUPPORTED_FORM_SUFFIX); FormInstance form = formReader.readFromString(formStructure); if (form == null) { form = generateDefaultProcessForm(processDesc); } form.setNestedFormsLookup(formId -> { Map<String, String> forms = indexedForms.get(resolvedContainerId); String formStructureNested = forms.get(formId); return formReader.readFromString(formStructureNested); }); FormRenderer formRenderer = renderers.get(renderer); if (formRenderer == null) { throw new IllegalArgumentException("Form renderer with name " + renderer + " not found"); } String output = formRenderer.renderProcess(resolvedContainerId, processDesc, form); return output; } FormRendererBase(DefinitionService definitionService, UserTaskService userTaskService, FormManagerService formManagerService, CaseRuntimeDataService caseRuntimeDataService, KieServerRegistry registry); void indexDeploymentForms(String containerId); void dropDeploymentForms(String containerId); String getProcessRenderedForm(String renderer, String containerId, String processId); String getTaskRenderedForm(String renderer, String containerId, long taskId); String getCaseRenderedForm(String renderer, String containerId, String caseDefinitionId); InputStream readResources(String resourcePath); }
FormRendererBase { public String getProcessRenderedForm(String renderer, String containerId, String processId) { String resolvedContainerId = registry.getContainerId(containerId, ContainerLocatorProvider.get().getLocator()); ProcessDefinition processDesc = definitionService.getProcessDefinition(resolvedContainerId, processId); if (processDesc == null) { throw new ProcessDefinitionNotFoundException("Process definition " + resolvedContainerId + " : " + processId + " not found"); } String formStructure = formManagerService.getFormByKey(resolvedContainerId, processId + SUPPORTED_FORM_SUFFIX); FormInstance form = formReader.readFromString(formStructure); if (form == null) { form = generateDefaultProcessForm(processDesc); } form.setNestedFormsLookup(formId -> { Map<String, String> forms = indexedForms.get(resolvedContainerId); String formStructureNested = forms.get(formId); return formReader.readFromString(formStructureNested); }); FormRenderer formRenderer = renderers.get(renderer); if (formRenderer == null) { throw new IllegalArgumentException("Form renderer with name " + renderer + " not found"); } String output = formRenderer.renderProcess(resolvedContainerId, processDesc, form); return output; } FormRendererBase(DefinitionService definitionService, UserTaskService userTaskService, FormManagerService formManagerService, CaseRuntimeDataService caseRuntimeDataService, KieServerRegistry registry); void indexDeploymentForms(String containerId); void dropDeploymentForms(String containerId); String getProcessRenderedForm(String renderer, String containerId, String processId); String getTaskRenderedForm(String renderer, String containerId, long taskId); String getCaseRenderedForm(String renderer, String containerId, String caseDefinitionId); InputStream readResources(String resourcePath);  }