Search in sources :

Example 1 with FormProperty

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

the class RestResponseFactory method createFormDataResponse.

public FormDataResponse createFormDataResponse(FormData formData) {
    FormDataResponse result = new FormDataResponse();
    result.setDeploymentId(formData.getDeploymentId());
    result.setFormKey(formData.getFormKey());
    if (formData.getFormProperties() != null) {
        for (FormProperty formProp : formData.getFormProperties()) {
            RestFormProperty restFormProp = new RestFormProperty();
            restFormProp.setId(formProp.getId());
            restFormProp.setName(formProp.getName());
            if (formProp.getType() != null) {
                restFormProp.setType(formProp.getType().getName());
            }
            restFormProp.setValue(formProp.getValue());
            restFormProp.setReadable(formProp.isReadable());
            restFormProp.setRequired(formProp.isRequired());
            restFormProp.setWritable(formProp.isWritable());
            if ("enum".equals(restFormProp.getType())) {
                Object values = formProp.getType().getInformation("values");
                if (values != null) {
                    @SuppressWarnings("unchecked") Map<String, String> enumValues = (Map<String, String>) values;
                    for (String enumId : enumValues.keySet()) {
                        RestEnumFormProperty enumProperty = new RestEnumFormProperty();
                        enumProperty.setId(enumId);
                        enumProperty.setName(enumValues.get(enumId));
                        restFormProp.addEnumValue(enumProperty);
                    }
                }
            } else if ("date".equals(restFormProp.getType())) {
                restFormProp.setDatePattern((String) formProp.getType().getInformation("datePattern"));
            }
            result.addFormProperty(restFormProp);
        }
    }
    RestUrlBuilder urlBuilder = createUrlBuilder();
    if (formData instanceof StartFormData) {
        StartFormData startFormData = (StartFormData) formData;
        if (startFormData.getProcessDefinition() != null) {
            result.setProcessDefinitionId(startFormData.getProcessDefinition().getId());
            result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, startFormData.getProcessDefinition().getId()));
        }
    } else if (formData instanceof TaskFormData) {
        TaskFormData taskFormData = (TaskFormData) formData;
        if (taskFormData.getTask() != null) {
            result.setTaskId(taskFormData.getTask().getId());
            result.setTaskUrl(urlBuilder.buildUrl(RestUrls.URL_TASK, taskFormData.getTask().getId()));
        }
    }
    return result;
}
Also used : RestEnumFormProperty(org.activiti.rest.service.api.form.RestEnumFormProperty) RestEnumFormProperty(org.activiti.rest.service.api.form.RestEnumFormProperty) RestFormProperty(org.activiti.rest.service.api.form.RestFormProperty) HistoricFormProperty(org.activiti.engine.history.HistoricFormProperty) FormProperty(org.activiti.engine.form.FormProperty) StartFormData(org.activiti.engine.form.StartFormData) RestFormProperty(org.activiti.rest.service.api.form.RestFormProperty) TaskFormData(org.activiti.engine.form.TaskFormData) Map(java.util.Map) FormDataResponse(org.activiti.rest.service.api.form.FormDataResponse)

Example 2 with FormProperty

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

the class FormPropertyDefaultValueTest method testDefaultValue.

@Deployment
public void testDefaultValue() throws Exception {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("FormPropertyDefaultValueTest.testDefaultValue");
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
    TaskFormData formData = formService.getTaskFormData(task.getId());
    List<FormProperty> formProperties = formData.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);
        }
    }
    Map<String, String> formDataUpdate = new HashMap<String, String>();
    formDataUpdate.put("longExpressionProperty", "1");
    formDataUpdate.put("booleanProperty", "false");
    formService.submitTaskFormData(task.getId(), 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 : Task(org.activiti.engine.task.Task) FormProperty(org.activiti.engine.form.FormProperty) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) TaskFormData(org.activiti.engine.form.TaskFormData) Deployment(org.activiti.engine.test.Deployment)

Example 3 with FormProperty

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

the class FormServiceTest method testFormPropertyExpression.

@Deployment
public void testFormPropertyExpression() {
    Map<String, Object> varMap = new HashMap<String, Object>();
    // variable name mapping
    varMap.put("speaker", "Mike");
    Address address = new Address();
    varMap.put("address", address);
    String procDefId = repositoryService.createProcessDefinitionQuery().singleResult().getId();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, varMap);
    String taskId = taskService.createTaskQuery().singleResult().getId();
    TaskFormData taskFormData = formService.getTaskFormData(taskId);
    List<FormProperty> formProperties = taskFormData.getFormProperties();
    FormProperty propertySpeaker = formProperties.get(0);
    assertEquals("speaker", propertySpeaker.getId());
    assertEquals("Mike", propertySpeaker.getValue());
    assertEquals(2, formProperties.size());
    Map<String, String> properties = new HashMap<String, String>();
    properties.put("street", "Broadway");
    formService.submitTaskFormData(taskId, properties);
    address = (Address) runtimeService.getVariable(processInstance.getId(), "address");
    assertEquals("Broadway", address.getStreet());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormProperty(org.activiti.engine.form.FormProperty) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) TaskFormData(org.activiti.engine.form.TaskFormData) Deployment(org.activiti.engine.test.Deployment)

Example 4 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 5 with FormProperty

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

the class FormPropertiesComponent method getFormPropertyValues.

/**
   * Returns all values filled in in the writable fields on the form.
   * 
   * @throws InvalidValueException when a validation error occurs.
   */
public Map<String, String> getFormPropertyValues() throws InvalidValueException {
    // Commit the form to ensure validation is executed
    form.commit();
    Map<String, String> formPropertyValues = new HashMap<String, String>();
    // Get values from fields defined for each form property
    for (FormProperty formProperty : formProperties) {
        if (formProperty.isWritable()) {
            Field field = form.getField(formProperty.getId());
            FormPropertyRenderer renderer = getRenderer(formProperty);
            String fieldValue = renderer.getFieldValue(formProperty, field);
            formPropertyValues.put(formProperty.getId(), fieldValue);
        }
    }
    return formPropertyValues;
}
Also used : Field(com.vaadin.ui.Field) HashMap(java.util.HashMap) FormProperty(org.activiti.engine.form.FormProperty)

Aggregations

FormProperty (org.activiti.engine.form.FormProperty)19 TaskFormData (org.activiti.engine.form.TaskFormData)10 HashMap (java.util.HashMap)9 StartFormData (org.activiti.engine.form.StartFormData)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Deployment (org.activiti.engine.test.Deployment)6 LinkedHashMap (java.util.LinkedHashMap)4 Task (org.activiti.engine.task.Task)4 IdentityLinkDto (eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto)3 WorkflowProcessDefinitionDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)3 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 Field (com.vaadin.ui.Field)2 FormService (org.activiti.engine.FormService)2 EnumFormType (org.activiti.engine.impl.form.EnumFormType)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1