Search in sources :

Example 6 with FormProperty

use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.

the class FormServiceTest method testFormPropertyDetails.

@SuppressWarnings("unchecked")
@Deployment
public void testFormPropertyDetails() {
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    StartFormData startFormData = formService.getStartFormData(procDefId);
    FormProperty property = startFormData.getFormProperties().get(0);
    assertEquals("speaker", property.getId());
    assertNull(property.getValue());
    assertTrue(property.isReadable());
    assertTrue(property.isWritable());
    assertFalse(property.isRequired());
    assertEquals("string", property.getType().getName());
    property = startFormData.getFormProperties().get(1);
    assertEquals("start", property.getId());
    assertNull(property.getValue());
    assertTrue(property.isReadable());
    assertTrue(property.isWritable());
    assertFalse(property.isRequired());
    assertEquals("date", property.getType().getName());
    assertEquals("dd-MMM-yyyy", property.getType().getInformation("datePattern"));
    property = startFormData.getFormProperties().get(2);
    assertEquals("direction", property.getId());
    assertNull(property.getValue());
    assertTrue(property.isReadable());
    assertTrue(property.isWritable());
    assertFalse(property.isRequired());
    assertEquals("enum", property.getType().getName());
    Map<String, String> values = (Map<String, String>) property.getType().getInformation("values");
    Map<String, String> expectedValues = new LinkedHashMap<String, String>();
    expectedValues.put("left", "Go Left");
    expectedValues.put("right", "Go Right");
    expectedValues.put("up", "Go Up");
    expectedValues.put("down", "Go Down");
    // ACT-1023: check if ordering is retained
    Iterator<Entry<String, String>> expectedValuesIterator = expectedValues.entrySet().iterator();
    for (Entry<String, String> entry : values.entrySet()) {
        Entry<String, String> expectedEntryAtLocation = expectedValuesIterator.next();
        assertEquals(expectedEntryAtLocation.getKey(), entry.getKey());
        assertEquals(expectedEntryAtLocation.getValue(), entry.getValue());
    }
    assertEquals(expectedValues, values);
}
Also used : Entry(java.util.Map.Entry) FormProperty(org.activiti.engine.form.FormProperty) StartFormData(org.activiti.engine.form.StartFormData) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Deployment(org.activiti.engine.test.Deployment)

Example 7 with FormProperty

use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.

the class DefaultFormHandler method initializeFormProperties.

protected void initializeFormProperties(FormDataImpl formData, ExecutionEntity execution) {
    List<FormProperty> formProperties = new ArrayList<FormProperty>();
    for (FormPropertyHandler formPropertyHandler : formPropertyHandlers) {
        if (formPropertyHandler.isReadable()) {
            FormProperty formProperty = formPropertyHandler.createFormProperty(execution);
            formProperties.add(formProperty);
        }
    }
    formData.setFormProperties(formProperties);
}
Also used : FormProperty(org.activiti.engine.form.FormProperty) ArrayList(java.util.ArrayList)

Example 8 with FormProperty

use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.

the class FormPropertyDefaultValueTest method testStartFormDefaultValue.

@Deployment
public void testStartFormDefaultValue() throws Exception {
    String processDefinitionId = repositoryService.createProcessDefinitionQuery().processDefinitionKey("FormPropertyDefaultValueTest.testDefaultValue").latestVersion().singleResult().getId();
    StartFormData startForm = formService.getStartFormData(processDefinitionId);
    List<FormProperty> formProperties = startForm.getFormProperties();
    assertEquals(4, formProperties.size());
    for (FormProperty prop : formProperties) {
        if ("booleanProperty".equals(prop.getId())) {
            assertEquals("true", prop.getValue());
        } else if ("stringProperty".equals(prop.getId())) {
            assertEquals("someString", prop.getValue());
        } else if ("longProperty".equals(prop.getId())) {
            assertEquals("42", prop.getValue());
        } else if ("longExpressionProperty".equals(prop.getId())) {
            assertEquals("23", prop.getValue());
        } else {
            assertTrue("Invalid form property: " + prop.getId(), false);
        }
    }
    // Override 2 properties. The others should pe posted as the default-value
    Map<String, String> formDataUpdate = new HashMap<String, String>();
    formDataUpdate.put("longExpressionProperty", "1");
    formDataUpdate.put("booleanProperty", "false");
    ProcessInstance processInstance = formService.submitStartFormData(processDefinitionId, formDataUpdate);
    assertEquals(false, runtimeService.getVariable(processInstance.getId(), "booleanProperty"));
    assertEquals("someString", runtimeService.getVariable(processInstance.getId(), "stringProperty"));
    assertEquals(42L, runtimeService.getVariable(processInstance.getId(), "longProperty"));
    assertEquals(1L, runtimeService.getVariable(processInstance.getId(), "longExpressionProperty"));
}
Also used : FormProperty(org.activiti.engine.form.FormProperty) HashMap(java.util.HashMap) StartFormData(org.activiti.engine.form.StartFormData) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 9 with FormProperty

use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.

the class FormServiceTest method testFormPropertyHandling.

@Deployment
public void testFormPropertyHandling() {
    Map<String, String> properties = new HashMap<String, String>();
    // default
    properties.put("room", "5b");
    // variable name mapping
    properties.put("speaker", "Mike");
    // type conversion
    properties.put("duration", "45");
    // type conversion
    properties.put("free", "true");
    // type conversion
    properties.put("double", "45.5");
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    String processInstanceId = formService.submitStartFormData(procDefId, properties).getId();
    Map<String, Object> expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("SpeakerName", "Mike");
    expectedVariables.put("duration", 45l);
    expectedVariables.put("free", Boolean.TRUE);
    expectedVariables.put("double", 45.5d);
    Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
    Address address = new Address();
    address.setStreet("broadway");
    runtimeService.setVariable(processInstanceId, "address", address);
    runtimeService.signal(runtimeService.createExecutionQuery().processInstanceId(processInstanceId).singleResult().getId());
    String taskId = taskService.createTaskQuery().singleResult().getId();
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    List<FormProperty> formProperties = taskFormData.getFormProperties();
    FormProperty propertyRoom = formProperties.get(0);
    assertEquals("room", propertyRoom.getId());
    assertEquals("5b", propertyRoom.getValue());
    FormProperty propertyDuration = formProperties.get(1);
    assertEquals("duration", propertyDuration.getId());
    assertEquals("45", propertyDuration.getValue());
    FormProperty propertySpeaker = formProperties.get(2);
    assertEquals("speaker", propertySpeaker.getId());
    assertEquals("Mike", propertySpeaker.getValue());
    FormProperty propertyStreet = formProperties.get(3);
    assertEquals("street", propertyStreet.getId());
    assertEquals("broadway", propertyStreet.getValue());
    FormProperty propertyFree = formProperties.get(4);
    assertEquals("free", propertyFree.getId());
    assertEquals("true", propertyFree.getValue());
    FormProperty propertyDouble = formProperties.get(5);
    assertEquals("double", propertyDouble.getId());
    assertEquals("45.5", propertyDouble.getValue());
    assertEquals(6, formProperties.size());
    try {
        formService.submitTaskFormData(taskId, new HashMap<String, String>());
        fail("expected exception about required form property 'street'");
    } catch (ActivitiException e) {
    // OK
    }
    try {
        properties = new HashMap<String, String>();
        properties.put("speaker", "its not allowed to update speaker!");
        formService.submitTaskFormData(taskId, properties);
        fail("expected exception about a non writable form property 'speaker'");
    } catch (ActivitiException e) {
    // OK
    }
    properties = new HashMap<String, String>();
    properties.put("street", "rubensstraat");
    formService.submitTaskFormData(taskId, properties);
    expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("SpeakerName", "Mike");
    expectedVariables.put("duration", 45l);
    expectedVariables.put("free", Boolean.TRUE);
    expectedVariables.put("double", 45.5d);
    variables = runtimeService.getVariables(processInstanceId);
    address = (Address) variables.remove("address");
    assertEquals("rubensstraat", address.getStreet());
    assertEquals(expectedVariables, variables);
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormProperty(org.activiti.engine.form.FormProperty) TaskFormData(org.activiti.engine.form.TaskFormData) Deployment(org.activiti.engine.test.Deployment)

Example 10 with FormProperty

use of org.activiti.engine.form.FormProperty in project Activiti by Activiti.

the class FormServiceTest method testTaskFormPropertyDefaultsAndFormRendering.

@Deployment(resources = { "org/activiti/engine/test/api/form/FormsProcess.bpmn20.xml", "org/activiti/engine/test/api/form/start.form", "org/activiti/engine/test/api/form/task.form" })
public void testTaskFormPropertyDefaultsAndFormRendering() {
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    StartFormData startForm = formService.getStartFormData(procDefId);
    assertNotNull(startForm);
    assertEquals(deploymentIdFromDeploymentAnnotation, startForm.getDeploymentId());
    assertEquals("org/activiti/engine/test/api/form/start.form", startForm.getFormKey());
    assertEquals(new ArrayList<FormProperty>(), startForm.getFormProperties());
    assertEquals(procDefId, startForm.getProcessDefinition().getId());
    Object renderedStartForm = formService.getRenderedStartForm(procDefId);
    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(deploymentIdFromDeploymentAnnotation, taskForm.getDeploymentId());
    assertEquals("org/activiti/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));
    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.activiti.engine.task.Task) FormProperty(org.activiti.engine.form.FormProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StartFormData(org.activiti.engine.form.StartFormData) TaskFormData(org.activiti.engine.form.TaskFormData) Deployment(org.activiti.engine.test.Deployment)

Aggregations

FormProperty (org.activiti.engine.form.FormProperty)11 HashMap (java.util.HashMap)7 Deployment (org.activiti.engine.test.Deployment)6 StartFormData (org.activiti.engine.form.StartFormData)5 TaskFormData (org.activiti.engine.form.TaskFormData)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 Field (com.vaadin.ui.Field)2 Task (org.activiti.engine.task.Task)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 ActivitiException (org.activiti.engine.ActivitiException)1 HistoricFormProperty (org.activiti.engine.history.HistoricFormProperty)1 EnumFormType (org.activiti.engine.impl.form.EnumFormType)1 FormDataResponse (org.activiti.rest.service.api.form.FormDataResponse)1 RestEnumFormProperty (org.activiti.rest.service.api.form.RestEnumFormProperty)1 RestFormProperty (org.activiti.rest.service.api.form.RestFormProperty)1