Search in sources :

Example 6 with FormValue

use of org.activiti.bpmn.model.FormValue in project Activiti by Activiti.

the class BaseStepDefinitionConverter method convertProperties.

/**
   * Converts form properties. Multiple step types can contain forms,
   * hence why it it a shared method here.
   */
protected List<FormProperty> convertProperties(FormDefinition formDefinition) {
    List<FormProperty> formProperties = new ArrayList<FormProperty>();
    for (FormPropertyDefinition propertyDefinition : formDefinition.getFormPropertyDefinitions()) {
        FormProperty formProperty = new FormProperty();
        formProperties.add(formProperty);
        formProperty.setId(propertyDefinition.getName());
        formProperty.setName(propertyDefinition.getName());
        formProperty.setRequired(propertyDefinition.isMandatory());
        String type = null;
        if (propertyDefinition instanceof NumberPropertyDefinition) {
            type = "long";
        } else if (propertyDefinition instanceof DatePropertyDefinition) {
            type = "date";
        } else if (propertyDefinition instanceof BooleanPropertyDefinition) {
            type = "boolean";
        } else if (propertyDefinition instanceof ListPropertyDefinition) {
            type = "enum";
            ListPropertyDefinition listDefinition = (ListPropertyDefinition) propertyDefinition;
            if (!listDefinition.getEntries().isEmpty()) {
                List<FormValue> formValues = new ArrayList<FormValue>(listDefinition.getEntries().size());
                for (ListPropertyEntry entry : listDefinition.getEntries()) {
                    FormValue formValue = new FormValue();
                    // We're using same value for id and name for the moment
                    formValue.setId(entry.getValue());
                    formValue.setName(entry.getName());
                    formValues.add(formValue);
                }
                formProperty.setFormValues(formValues);
            }
        } else {
            // Fallback to simple text
            type = "string";
        }
        formProperty.setType(type);
    }
    return formProperties;
}
Also used : ListPropertyEntry(org.activiti.workflow.simple.definition.form.ListPropertyEntry) BooleanPropertyDefinition(org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition) FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) ArrayList(java.util.ArrayList) FormPropertyDefinition(org.activiti.workflow.simple.definition.form.FormPropertyDefinition) NumberPropertyDefinition(org.activiti.workflow.simple.definition.form.NumberPropertyDefinition) ListPropertyDefinition(org.activiti.workflow.simple.definition.form.ListPropertyDefinition) ArrayList(java.util.ArrayList) List(java.util.List) DatePropertyDefinition(org.activiti.workflow.simple.definition.form.DatePropertyDefinition)

Example 7 with FormValue

use of org.activiti.bpmn.model.FormValue in project Activiti by Activiti.

the class FormPropertiesConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    assertEquals("formPropertiesProcess", model.getMainProcess().getId());
    assertEquals("User registration", model.getMainProcess().getName());
    assertEquals(true, model.getMainProcess().isExecutable());
    FlowElement startFlowElement = model.getMainProcess().getFlowElement("startNode");
    assertNotNull(startFlowElement);
    assertTrue(startFlowElement instanceof StartEvent);
    StartEvent startEvent = (StartEvent) startFlowElement;
    List<FormProperty> formProperties = startEvent.getFormProperties();
    assertNotNull(formProperties);
    assertEquals("Invalid form properties list: ", 8, formProperties.size());
    for (FormProperty formProperty : formProperties) {
        if (formProperty.getId().equals("new_property_1")) {
            checkFormProperty(formProperty, "v000", true, false, false);
        } else if (formProperty.getId().equals("new_property_2")) {
            checkFormProperty(formProperty, "v001", true, false, true);
        } else if (formProperty.getId().equals("new_property_3")) {
            checkFormProperty(formProperty, "v010", true, true, false);
        } else if (formProperty.getId().equals("new_property_4")) {
            checkFormProperty(formProperty, "v011", true, true, true);
        } else if (formProperty.getId().equals("new_property_5")) {
            checkFormProperty(formProperty, "v100", true, false, false);
            List<Map<String, Object>> formValues = new ArrayList<Map<String, Object>>();
            for (FormValue formValue : formProperty.getFormValues()) {
                Map<String, Object> formValueMap = new HashMap<String, Object>();
                formValueMap.put("id", formValue.getId());
                formValueMap.put("name", formValue.getName());
                formValues.add(formValueMap);
            }
            checkFormPropertyFormValues(formValues);
        } else if (formProperty.getId().equals("new_property_6")) {
            checkFormProperty(formProperty, "v101", true, false, true);
        } else if (formProperty.getId().equals("new_property_7")) {
            checkFormProperty(formProperty, "v110", true, true, false);
        } else if (formProperty.getId().equals("new_property_8")) {
            checkFormProperty(formProperty, "v111", true, true, true);
        } else {
            fail("unexpected form property id " + formProperty.getId());
        }
    }
    FlowElement userFlowElement = model.getMainProcess().getFlowElement("userTask");
    assertNotNull(userFlowElement);
    assertTrue(userFlowElement instanceof UserTask);
    UserTask userTask = (UserTask) userFlowElement;
    formProperties = userTask.getFormProperties();
    assertNotNull(formProperties);
    assertEquals("Invalid form properties list: ", 8, formProperties.size());
    for (FormProperty formProperty : formProperties) {
        if (formProperty.getId().equals("new_property_1")) {
            checkFormProperty(formProperty, "v000", false, false, false);
        } else if (formProperty.getId().equals("new_property_2")) {
            checkFormProperty(formProperty, "v001", false, false, true);
        } else if (formProperty.getId().equals("new_property_3")) {
            checkFormProperty(formProperty, "v010", false, true, false);
        } else if (formProperty.getId().equals("new_property_4")) {
            checkFormProperty(formProperty, "v011", false, true, true);
        } else if (formProperty.getId().equals("new_property_5")) {
            checkFormProperty(formProperty, "v100", true, false, false);
            List<Map<String, Object>> formValues = new ArrayList<Map<String, Object>>();
            for (FormValue formValue : formProperty.getFormValues()) {
                Map<String, Object> formValueMap = new HashMap<String, Object>();
                formValueMap.put("id", formValue.getId());
                formValueMap.put("name", formValue.getName());
                formValues.add(formValueMap);
            }
            checkFormPropertyFormValues(formValues);
        } else if (formProperty.getId().equals("new_property_6")) {
            checkFormProperty(formProperty, "v101", true, false, true);
        } else if (formProperty.getId().equals("new_property_7")) {
            checkFormProperty(formProperty, "v110", true, true, false);
        } else if (formProperty.getId().equals("new_property_8")) {
            checkFormProperty(formProperty, "v111", true, true, true);
        } else {
            fail("unexpected form property id " + formProperty.getId());
        }
    }
}
Also used : FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserTask(org.activiti.bpmn.model.UserTask) FlowElement(org.activiti.bpmn.model.FlowElement) StartEvent(org.activiti.bpmn.model.StartEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FormProperty (org.activiti.bpmn.model.FormProperty)7 FormValue (org.activiti.bpmn.model.FormValue)7 ArrayList (java.util.ArrayList)4 StartEvent (org.activiti.bpmn.model.StartEvent)4 UserTask (org.activiti.bpmn.model.UserTask)4 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 FlowElement (org.activiti.bpmn.model.FlowElement)2 BooleanPropertyDefinition (org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition)2 ListPropertyDefinition (org.activiti.workflow.simple.definition.form.ListPropertyDefinition)2 ListPropertyEntry (org.activiti.workflow.simple.definition.form.ListPropertyEntry)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 DatePropertyDefinition (org.activiti.workflow.simple.definition.form.DatePropertyDefinition)1 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)1 FormPropertyDefinition (org.activiti.workflow.simple.definition.form.FormPropertyDefinition)1 NumberPropertyDefinition (org.activiti.workflow.simple.definition.form.NumberPropertyDefinition)1 TextPropertyDefinition (org.activiti.workflow.simple.definition.form.TextPropertyDefinition)1