Search in sources :

Example 6 with FormProperty

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

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.camunda.bpm.engine.form.FormProperty) ArrayList(java.util.ArrayList)

Example 7 with FormProperty

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

the class HtmlFormEngine method renderFormData.

protected String renderFormData(FormData formData) {
    if (formData == null || (formData.getFormFields() == null || formData.getFormFields().isEmpty()) && (formData.getFormProperties() == null || formData.getFormProperties().isEmpty())) {
        return null;
    } else {
        HtmlElementWriter formElement = new HtmlElementWriter(FORM_ELEMENT).attribute(NAME_ATTRIBUTE, GENERATED_FORM_NAME).attribute(ROLE_ATTRIBUTE, FORM_ROLE);
        HtmlDocumentBuilder documentBuilder = new HtmlDocumentBuilder(formElement);
        // render fields
        for (FormField formField : formData.getFormFields()) {
            renderFormField(formField, documentBuilder);
        }
        // render deprecated form properties
        for (FormProperty formProperty : formData.getFormProperties()) {
            renderFormField(new FormPropertyAdapter(formProperty), documentBuilder);
        }
        // end document element
        documentBuilder.endElement();
        return documentBuilder.getHtmlString();
    }
}
Also used : FormProperty(org.camunda.bpm.engine.form.FormProperty) FormField(org.camunda.bpm.engine.form.FormField)

Example 8 with FormProperty

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

the class AbstractRenderFormDelegate method renderFormData.

protected String renderFormData(FormData formData) {
    if (formData == null || (formData.getFormFields() == null || formData.getFormFields().isEmpty()) && (formData.getFormProperties() == null || formData.getFormProperties().isEmpty())) {
        return null;
    } else {
        HtmlElementWriter formElement = new HtmlElementWriter(FORM_ELEMENT).attribute(NAME_ATTRIBUTE, GENERATED_FORM_NAME).attribute(ROLE_ATTRIBUTE, FORM_ROLE);
        HtmlDocumentBuilder documentBuilder = new HtmlDocumentBuilder(formElement);
        // render fields
        for (FormField formField : formData.getFormFields()) {
            renderFormField(formField, documentBuilder);
        }
        // render deprecated form properties
        for (FormProperty formProperty : formData.getFormProperties()) {
            renderFormField(new FormPropertyAdapter(formProperty), documentBuilder);
        }
        // end document element
        documentBuilder.endElement();
        return documentBuilder.getHtmlString();
    }
}
Also used : FormProperty(org.camunda.bpm.engine.form.FormProperty) FormField(org.camunda.bpm.engine.form.FormField)

Example 9 with FormProperty

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

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.camunda.bpm.engine.form.FormProperty) HashMap(java.util.HashMap) StartFormData(org.camunda.bpm.engine.form.StartFormData) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with FormProperty

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

the class FormServiceTest method testFormPropertyHandling.

@Deployment
@Test
public void testFormPropertyHandling() {
    Map<String, Object> properties = new HashMap<String, Object>();
    // default
    properties.put("room", "5b");
    // variable name mapping
    properties.put("speaker", "Mike");
    // type conversion
    properties.put("duration", 45L);
    // type conversion
    properties.put("free", "true");
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    String processInstanceId = formService.submitStartForm(procDefId, properties).getId();
    Map<String, Object> expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("SpeakerName", "Mike");
    expectedVariables.put("duration", new Long(45));
    expectedVariables.put("free", Boolean.TRUE);
    Map<String, Object> variables = runtimeService.getVariables(processInstanceId);
    assertEquals(expectedVariables, variables);
    Address address = new Address();
    address.setStreet("broadway");
    runtimeService.setVariable(processInstanceId, "address", address);
    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());
    assertEquals(5, formProperties.size());
    try {
        formService.submitTaskForm(taskId, new HashMap<String, Object>());
        fail("expected exception about required form property 'street'");
    } catch (ProcessEngineException e) {
    // OK
    }
    try {
        properties = new HashMap<String, Object>();
        properties.put("speaker", "its not allowed to update speaker!");
        formService.submitTaskForm(taskId, properties);
        fail("expected exception about a non writable form property 'speaker'");
    } catch (ProcessEngineException e) {
    // OK
    }
    properties = new HashMap<String, Object>();
    properties.put("street", "rubensstraat");
    formService.submitTaskForm(taskId, properties);
    expectedVariables = new HashMap<String, Object>();
    expectedVariables.put("room", "5b");
    expectedVariables.put("SpeakerName", "Mike");
    expectedVariables.put("duration", new Long(45));
    expectedVariables.put("free", Boolean.TRUE);
    variables = runtimeService.getVariables(processInstanceId);
    address = (Address) variables.remove("address");
    assertEquals("rubensstraat", address.getStreet());
    assertEquals(expectedVariables, variables);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormProperty(org.camunda.bpm.engine.form.FormProperty) TaskFormData(org.camunda.bpm.engine.form.TaskFormData) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

FormProperty (org.camunda.bpm.engine.form.FormProperty)11 HashMap (java.util.HashMap)6 TaskFormData (org.camunda.bpm.engine.form.TaskFormData)5 Deployment (org.camunda.bpm.engine.test.Deployment)5 LinkedHashMap (java.util.LinkedHashMap)4 StartFormData (org.camunda.bpm.engine.form.StartFormData)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 FormField (org.camunda.bpm.engine.form.FormField)2 FormType (org.camunda.bpm.engine.form.FormType)2 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)2 Task (org.camunda.bpm.engine.task.Task)2 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 VariableMap (org.camunda.bpm.engine.variable.VariableMap)1