Search in sources :

Example 1 with StartFormData

use of org.camunda.bpm.engine.form.StartFormData in project camunda-bpm-platform by camunda.

the class ProcessDefinitionRestServiceInteractionTest method testGetStartForm_shouldReturnKeyContainingTaskId.

@Test
public void testGetStartForm_shouldReturnKeyContainingTaskId() {
    ProcessDefinition mockDefinition = MockProvider.createMockDefinition();
    StartFormData mockStartFormData = MockProvider.createMockStartFormDataUsingFormFieldsWithoutFormKey(mockDefinition);
    when(formServiceMock.getStartFormData(mockDefinition.getId())).thenReturn(mockStartFormData);
    given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID).then().expect().statusCode(Status.OK.getStatusCode()).body("key", equalTo("embedded:engine://engine/:engine/process-definition/" + mockDefinition.getId() + "/rendered-form")).body("contextPath", equalTo(MockProvider.EXAMPLE_PROCESS_APPLICATION_CONTEXT_PATH)).when().get(START_FORM_URL);
}
Also used : StartFormData(org.camunda.bpm.engine.form.StartFormData) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) Test(org.junit.Test)

Example 2 with StartFormData

use of org.camunda.bpm.engine.form.StartFormData in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method getStartForm.

@Override
public FormDto getStartForm() {
    final FormService formService = engine.getFormService();
    final StartFormData formData;
    try {
        formData = formService.getStartFormData(processDefinitionId);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, "Cannot get start form data for process definition " + processDefinitionId);
    }
    FormDto dto = FormDto.fromFormData(formData);
    if (dto.getKey() == null || dto.getKey().isEmpty()) {
        if (formData != null && formData.getFormFields() != null && !formData.getFormFields().isEmpty()) {
            dto.setKey("embedded:engine://engine/:engine/process-definition/" + processDefinitionId + "/rendered-form");
        }
    }
    dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByProcessDefinitionId(engine, processDefinitionId));
    return dto;
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) FormService(org.camunda.bpm.engine.FormService) StartFormData(org.camunda.bpm.engine.form.StartFormData) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) FormDto(org.camunda.bpm.engine.rest.dto.task.FormDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with StartFormData

use of org.camunda.bpm.engine.form.StartFormData in project camunda-bpm-platform by camunda.

the class DelegationAuthorizationTest method testCustomStartFormHandlerExecutesQuery.

@Deployment
public void testCustomStartFormHandlerExecutesQuery() {
    // given
    startProcessInstancesByKey(DEFAULT_PROCESS_KEY, 5);
    String processDefinitionId = selectProcessDefinitionByKey(DEFAULT_PROCESS_KEY).getId();
    createGrantAuthorization(PROCESS_DEFINITION, DEFAULT_PROCESS_KEY, userId, READ);
    // when
    StartFormData startFormData = formService.getStartFormData(processDefinitionId);
    // then
    assertNotNull(startFormData);
    assertNotNull(MyDelegationService.CURRENT_AUTHENTICATION);
    assertEquals(userId, MyDelegationService.CURRENT_AUTHENTICATION.getUserId());
    assertEquals(Long.valueOf(5), MyDelegationService.INSTANCES_COUNT);
}
Also used : StartFormData(org.camunda.bpm.engine.form.StartFormData) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with StartFormData

use of org.camunda.bpm.engine.form.StartFormData in project camunda-bpm-platform by camunda.

the class FormServiceTest method testTaskFormPropertyDefaultsAndFormRendering.

@Test
public void testTaskFormPropertyDefaultsAndFormRendering() {
    final String deploymentId = testRule.deploy("org/camunda/bpm/engine/test/api/form/FormsProcess.bpmn20.xml", "org/camunda/bpm/engine/test/api/form/start.form", "org/camunda/bpm/engine/test/api/form/task.form").getId();
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    StartFormData startForm = formService.getStartFormData(procDefId);
    assertNotNull(startForm);
    assertEquals(deploymentId, startForm.getDeploymentId());
    assertEquals("org/camunda/bpm/engine/test/api/form/start.form", startForm.getFormKey());
    assertEquals(new ArrayList<FormProperty>(), startForm.getFormProperties());
    assertEquals(procDefId, startForm.getProcessDefinition().getId());
    Object renderedStartForm = formService.getRenderedStartForm(procDefId, "juel");
    assertEquals("start form content", renderedStartForm);
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("room", "5b");
    properties.put("speaker", "Mike");
    String processInstanceId = formService.submitStartFormData(procDefId, properties).getId();
    Map<String, Object> expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("speaker", "Mike");
    Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
    Task task = taskService.createTaskQuery().singleResult();
    String taskId = task.getId();
    TaskFormData taskForm = formService.getTaskFormData(taskId);
    assertEquals(deploymentId, taskForm.getDeploymentId());
    assertEquals("org/camunda/bpm/engine/test/api/form/task.form", taskForm.getFormKey());
    assertEquals(new ArrayList<FormProperty>(), taskForm.getFormProperties());
    assertEquals(taskId, taskForm.getTask().getId());
    assertEquals("Mike is speaking in room 5b", formService.getRenderedTaskForm(taskId, "juel"));
    properties = new HashMap<String, String>();
    properties.put("room", "3f");
    formService.submitTaskFormData(taskId, properties);
    expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "3f");
    expectedVariables.put("speaker", "Mike");
    variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
}
Also used : Task(org.camunda.bpm.engine.task.Task) FormProperty(org.camunda.bpm.engine.form.FormProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StartFormData(org.camunda.bpm.engine.form.StartFormData) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) Test(org.junit.Test)

Example 5 with StartFormData

use of org.camunda.bpm.engine.form.StartFormData in project camunda-bpm-platform by camunda.

the class FormServiceTest method testBusinessKey.

@Deployment
@Test
public void testBusinessKey() {
    // given
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    // when
    StartFormData startFormData = formService.getStartFormData(procDefId);
    // then
    FormField formField = startFormData.getFormFields().get(0);
    assertTrue(formField.isBusinessKey());
}
Also used : StartFormData(org.camunda.bpm.engine.form.StartFormData) FormField(org.camunda.bpm.engine.form.FormField) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

StartFormData (org.camunda.bpm.engine.form.StartFormData)19 Test (org.junit.Test)10 Deployment (org.camunda.bpm.engine.test.Deployment)5 FormField (org.camunda.bpm.engine.form.FormField)4 FormProperty (org.camunda.bpm.engine.form.FormProperty)4 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 VariableMap (org.camunda.bpm.engine.variable.VariableMap)3 LinkedHashMap (java.util.LinkedHashMap)2 FormType (org.camunda.bpm.engine.form.FormType)2 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)2 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 FormService (org.camunda.bpm.engine.FormService)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ScriptEvaluationException (org.camunda.bpm.engine.ScriptEvaluationException)1 TaskFormData (org.camunda.bpm.engine.form.TaskFormData)1