Search in sources :

Example 1 with FormValue

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

the class BaseStepDefinitionConverterTest method testCovertFormPropertiesWithListValues.

@Test
public void testCovertFormPropertiesWithListValues() {
    TestStepDefinitionConverter converter = new TestStepDefinitionConverter();
    // Create a form with two properties, one of which is a ListProperty
    FormDefinition formDefinition = new FormDefinition();
    ListPropertyDefinition approveEnum = new ListPropertyDefinition();
    approveEnum.setName("Approval");
    approveEnum.setType("enum");
    approveEnum.addEntry(new ListPropertyEntry("true", "Approve"));
    approveEnum.addEntry(new ListPropertyEntry("false", "Reject"));
    formDefinition.addFormProperty(approveEnum);
    TextPropertyDefinition reason = new TextPropertyDefinition();
    reason.setName("Reason");
    reason.setType("string");
    formDefinition.addFormProperty(reason);
    BooleanPropertyDefinition validate = new BooleanPropertyDefinition();
    validate.setName("Validate");
    validate.setType("boolean");
    formDefinition.addFormProperty(validate);
    List<FormProperty> properties = converter.convertProperties(formDefinition);
    assertTrue(properties.size() == 3);
    FormProperty firstProperty = properties.get(0);
    assertNotNull(firstProperty);
    assertEquals("Approval", firstProperty.getName());
    assertEquals("enum", firstProperty.getType());
    // Assert the values are set
    List<FormValue> values = firstProperty.getFormValues();
    assertTrue(values.size() == 2);
    FormValue firstValue = values.get(0);
    assertEquals("Approve", firstValue.getName());
    assertEquals("true", firstValue.getId());
    FormValue secondValue = values.get(1);
    assertEquals("Reject", secondValue.getName());
    assertEquals("false", secondValue.getId());
    // Now confirm the second property, a non list property, is well formed as well.
    FormProperty secondProperty = properties.get(1);
    assertNotNull(secondProperty);
    assertTrue(secondProperty.getFormValues().isEmpty());
    assertEquals("Reason", secondProperty.getName());
    assertEquals("string", secondProperty.getType());
    FormProperty thirdProperty = properties.get(2);
    assertNotNull(thirdProperty);
    assertTrue(thirdProperty.getFormValues().isEmpty());
    assertEquals("Validate", thirdProperty.getName());
    assertEquals("boolean", thirdProperty.getType());
}
Also used : ListPropertyEntry(org.activiti.workflow.simple.definition.form.ListPropertyEntry) BooleanPropertyDefinition(org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition) FormValue(org.activiti.bpmn.model.FormValue) TextPropertyDefinition(org.activiti.workflow.simple.definition.form.TextPropertyDefinition) FormProperty(org.activiti.bpmn.model.FormProperty) ListPropertyDefinition(org.activiti.workflow.simple.definition.form.ListPropertyDefinition) FormDefinition(org.activiti.workflow.simple.definition.form.FormDefinition) Test(org.junit.Test)

Example 2 with FormValue

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

the class BaseBpmnXMLConverter method writeFormProperties.

protected boolean writeFormProperties(FlowElement flowElement, boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {
    List<FormProperty> propertyList = null;
    if (flowElement instanceof UserTask) {
        propertyList = ((UserTask) flowElement).getFormProperties();
    } else if (flowElement instanceof StartEvent) {
        propertyList = ((StartEvent) flowElement).getFormProperties();
    }
    if (propertyList != null) {
        for (FormProperty property : propertyList) {
            if (StringUtils.isNotEmpty(property.getId())) {
                if (!didWriteExtensionStartElement) {
                    xtw.writeStartElement(ELEMENT_EXTENSIONS);
                    didWriteExtensionStartElement = true;
                }
                xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FORMPROPERTY, ACTIVITI_EXTENSIONS_NAMESPACE);
                writeDefaultAttribute(ATTRIBUTE_FORM_ID, property.getId(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_NAME, property.getName(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_TYPE, property.getType(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_EXPRESSION, property.getExpression(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_VARIABLE, property.getVariable(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_DEFAULT, property.getDefaultExpression(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_DATEPATTERN, property.getDatePattern(), xtw);
                if (!property.isReadable()) {
                    writeDefaultAttribute(ATTRIBUTE_FORM_READABLE, ATTRIBUTE_VALUE_FALSE, xtw);
                }
                if (!property.isWriteable()) {
                    writeDefaultAttribute(ATTRIBUTE_FORM_WRITABLE, ATTRIBUTE_VALUE_FALSE, xtw);
                }
                if (property.isRequired()) {
                    writeDefaultAttribute(ATTRIBUTE_FORM_REQUIRED, ATTRIBUTE_VALUE_TRUE, xtw);
                }
                for (FormValue formValue : property.getFormValues()) {
                    if (StringUtils.isNotEmpty(formValue.getId())) {
                        xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_VALUE, ACTIVITI_EXTENSIONS_NAMESPACE);
                        xtw.writeAttribute(ATTRIBUTE_ID, formValue.getId());
                        xtw.writeAttribute(ATTRIBUTE_NAME, formValue.getName());
                        xtw.writeEndElement();
                    }
                }
                xtw.writeEndElement();
            }
        }
    }
    return didWriteExtensionStartElement;
}
Also used : FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) UserTask(org.activiti.bpmn.model.UserTask) StartEvent(org.activiti.bpmn.model.StartEvent)

Example 3 with FormValue

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

the class FormPropertyParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (!accepts(parentElement)) {
        return;
    }
    FormProperty property = new FormProperty();
    BpmnXMLUtil.addXMLLocation(property, xtr);
    property.setId(xtr.getAttributeValue(null, ATTRIBUTE_FORM_ID));
    property.setName(xtr.getAttributeValue(null, ATTRIBUTE_FORM_NAME));
    property.setType(xtr.getAttributeValue(null, ATTRIBUTE_FORM_TYPE));
    property.setVariable(xtr.getAttributeValue(null, ATTRIBUTE_FORM_VARIABLE));
    property.setExpression(xtr.getAttributeValue(null, ATTRIBUTE_FORM_EXPRESSION));
    property.setDefaultExpression(xtr.getAttributeValue(null, ATTRIBUTE_FORM_DEFAULT));
    property.setDatePattern(xtr.getAttributeValue(null, ATTRIBUTE_FORM_DATEPATTERN));
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FORM_REQUIRED))) {
        property.setRequired(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_FORM_REQUIRED)));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FORM_READABLE))) {
        property.setReadable(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_FORM_READABLE)));
    }
    if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_FORM_WRITABLE))) {
        property.setWriteable(Boolean.valueOf(xtr.getAttributeValue(null, ATTRIBUTE_FORM_WRITABLE)));
    }
    boolean readyWithFormProperty = false;
    try {
        while (!readyWithFormProperty && xtr.hasNext()) {
            xtr.next();
            if (xtr.isStartElement() && ELEMENT_VALUE.equalsIgnoreCase(xtr.getLocalName())) {
                FormValue value = new FormValue();
                BpmnXMLUtil.addXMLLocation(value, xtr);
                value.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
                value.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
                property.getFormValues().add(value);
            } else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
                readyWithFormProperty = true;
            }
        }
    } catch (Exception e) {
        LOGGER.warn("Error parsing form properties child elements", e);
    }
    if (parentElement instanceof UserTask) {
        ((UserTask) parentElement).getFormProperties().add(property);
    } else {
        ((StartEvent) parentElement).getFormProperties().add(property);
    }
}
Also used : FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) UserTask(org.activiti.bpmn.model.UserTask)

Example 4 with FormValue

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

the class BaseBpmnJsonConverter method addFormProperties.

protected void addFormProperties(List<FormProperty> formProperties, ObjectNode propertiesNode) {
    if (CollectionUtils.isEmpty(formProperties)) {
        return;
    }
    ObjectNode formPropertiesNode = objectMapper.createObjectNode();
    ArrayNode propertiesArrayNode = objectMapper.createArrayNode();
    for (FormProperty property : formProperties) {
        ObjectNode propertyItemNode = objectMapper.createObjectNode();
        propertyItemNode.put(PROPERTY_FORM_ID, property.getId());
        propertyItemNode.put(PROPERTY_FORM_NAME, property.getName());
        propertyItemNode.put(PROPERTY_FORM_TYPE, property.getType());
        if (StringUtils.isNotEmpty(property.getExpression())) {
            propertyItemNode.put(PROPERTY_FORM_EXPRESSION, property.getExpression());
        } else {
            propertyItemNode.putNull(PROPERTY_FORM_EXPRESSION);
        }
        if (StringUtils.isNotEmpty(property.getVariable())) {
            propertyItemNode.put(PROPERTY_FORM_VARIABLE, property.getVariable());
        } else {
            propertyItemNode.putNull(PROPERTY_FORM_VARIABLE);
        }
        if (StringUtils.isNotEmpty(property.getDatePattern())) {
            propertyItemNode.put(PROPERTY_FORM_DATE_PATTERN, property.getDatePattern());
        }
        if (CollectionUtils.isNotEmpty(property.getFormValues())) {
            ArrayNode valuesNode = objectMapper.createArrayNode();
            for (FormValue formValue : property.getFormValues()) {
                ObjectNode valueNode = objectMapper.createObjectNode();
                valueNode.put(PROPERTY_FORM_ENUM_VALUES_NAME, formValue.getName());
                valueNode.put(PROPERTY_FORM_ENUM_VALUES_ID, formValue.getId());
                valuesNode.add(valueNode);
            }
            propertyItemNode.set(PROPERTY_FORM_ENUM_VALUES, valuesNode);
        }
        propertyItemNode.put(PROPERTY_FORM_REQUIRED, property.isRequired());
        propertyItemNode.put(PROPERTY_FORM_READABLE, property.isReadable());
        propertyItemNode.put(PROPERTY_FORM_WRITABLE, property.isWriteable());
        propertiesArrayNode.add(propertyItemNode);
    }
    formPropertiesNode.set("formProperties", propertiesArrayNode);
    propertiesNode.set(PROPERTY_FORM_PROPERTIES, formPropertiesNode);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 5 with FormValue

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

the class BaseBpmnJsonConverter method convertJsonToFormProperties.

protected void convertJsonToFormProperties(JsonNode objectNode, BaseElement element) {
    JsonNode formPropertiesNode = getProperty(PROPERTY_FORM_PROPERTIES, objectNode);
    if (formPropertiesNode != null) {
        formPropertiesNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(formPropertiesNode);
        JsonNode propertiesArray = formPropertiesNode.get("formProperties");
        if (propertiesArray != null) {
            for (JsonNode formNode : propertiesArray) {
                JsonNode formIdNode = formNode.get(PROPERTY_FORM_ID);
                if (formIdNode != null && StringUtils.isNotEmpty(formIdNode.asText())) {
                    FormProperty formProperty = new FormProperty();
                    formProperty.setId(formIdNode.asText());
                    formProperty.setName(getValueAsString(PROPERTY_FORM_NAME, formNode));
                    formProperty.setType(getValueAsString(PROPERTY_FORM_TYPE, formNode));
                    formProperty.setExpression(getValueAsString(PROPERTY_FORM_EXPRESSION, formNode));
                    formProperty.setVariable(getValueAsString(PROPERTY_FORM_VARIABLE, formNode));
                    if ("date".equalsIgnoreCase(formProperty.getType())) {
                        formProperty.setDatePattern(getValueAsString(PROPERTY_FORM_DATE_PATTERN, formNode));
                    } else if ("enum".equalsIgnoreCase(formProperty.getType())) {
                        JsonNode enumValuesNode = formNode.get(PROPERTY_FORM_ENUM_VALUES);
                        if (enumValuesNode != null) {
                            List<FormValue> formValueList = new ArrayList<FormValue>();
                            for (JsonNode enumNode : enumValuesNode) {
                                if (enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID) != null && !enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).isNull() && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME) != null && !enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).isNull()) {
                                    FormValue formValue = new FormValue();
                                    formValue.setId(enumNode.get(PROPERTY_FORM_ENUM_VALUES_ID).asText());
                                    formValue.setName(enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).asText());
                                    formValueList.add(formValue);
                                } else if (enumNode.get("value") != null && !enumNode.get("value").isNull()) {
                                    FormValue formValue = new FormValue();
                                    formValue.setId(enumNode.get("value").asText());
                                    formValue.setName(enumNode.get("value").asText());
                                    formValueList.add(formValue);
                                }
                            }
                            formProperty.setFormValues(formValueList);
                        }
                    }
                    formProperty.setRequired(getValueAsBoolean(PROPERTY_FORM_REQUIRED, formNode));
                    formProperty.setReadable(getValueAsBoolean(PROPERTY_FORM_READABLE, formNode));
                    formProperty.setWriteable(getValueAsBoolean(PROPERTY_FORM_WRITABLE, formNode));
                    if (element instanceof StartEvent) {
                        ((StartEvent) element).getFormProperties().add(formProperty);
                    } else if (element instanceof UserTask) {
                        ((UserTask) element).getFormProperties().add(formProperty);
                    }
                }
            }
        }
    }
}
Also used : FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) StartEvent(org.activiti.bpmn.model.StartEvent) UserTask(org.activiti.bpmn.model.UserTask) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

FormValue (org.activiti.bpmn.model.FormValue)9 FormProperty (org.activiti.bpmn.model.FormProperty)8 UserTask (org.activiti.bpmn.model.UserTask)5 ArrayList (java.util.ArrayList)4 StartEvent (org.activiti.bpmn.model.StartEvent)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 LinkedHashMap (java.util.LinkedHashMap)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