Search in sources :

Example 1 with FormProperty

use of org.activiti.bpmn.model.FormProperty 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.put(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.put("formProperties", propertiesArrayNode);
    propertiesNode.put(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 2 with FormProperty

use of org.activiti.bpmn.model.FormProperty 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 3 with FormProperty

use of org.activiti.bpmn.model.FormProperty 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 == false) {
                    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() == false) {
                    writeDefaultAttribute(ATTRIBUTE_FORM_READABLE, ATTRIBUTE_VALUE_FALSE, xtw);
                }
                if (property.isWriteable() == false) {
                    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 4 with FormProperty

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

the class UserTaskConverterTest method validateModel.

private void validateModel(BpmnModel model) {
    FlowElement flowElement = model.getMainProcess().getFlowElement("usertask");
    assertNotNull(flowElement);
    assertTrue(flowElement instanceof UserTask);
    assertEquals("usertask", flowElement.getId());
    UserTask userTask = (UserTask) flowElement;
    assertEquals("usertask", userTask.getId());
    assertEquals("User task", userTask.getName());
    assertEquals("Test Category", userTask.getCategory());
    assertEquals("testKey", userTask.getFormKey());
    assertEquals("40", userTask.getPriority());
    assertEquals("2012-11-01", userTask.getDueDate());
    assertEquals("customCalendarName", userTask.getBusinessCalendarName());
    assertEquals("kermit", userTask.getAssignee());
    assertEquals(2, userTask.getCandidateUsers().size());
    assertTrue(userTask.getCandidateUsers().contains("kermit"));
    assertTrue(userTask.getCandidateUsers().contains("fozzie"));
    assertEquals(2, userTask.getCandidateGroups().size());
    assertTrue(userTask.getCandidateGroups().contains("management"));
    assertTrue(userTask.getCandidateGroups().contains("sales"));
    assertEquals(1, userTask.getCustomUserIdentityLinks().size());
    assertEquals(2, userTask.getCustomGroupIdentityLinks().size());
    assertTrue(userTask.getCustomUserIdentityLinks().get("businessAdministrator").contains("kermit"));
    assertTrue(userTask.getCustomGroupIdentityLinks().get("manager").contains("management"));
    assertTrue(userTask.getCustomGroupIdentityLinks().get("businessAdministrator").contains("management"));
    List<FormProperty> formProperties = userTask.getFormProperties();
    assertEquals(3, formProperties.size());
    FormProperty formProperty = formProperties.get(0);
    assertEquals("formId", formProperty.getId());
    assertEquals("formName", formProperty.getName());
    assertEquals("string", formProperty.getType());
    assertEquals("variable", formProperty.getVariable());
    assertEquals("${expression}", formProperty.getExpression());
    formProperty = formProperties.get(1);
    assertEquals("formId2", formProperty.getId());
    assertEquals("anotherName", formProperty.getName());
    assertEquals("long", formProperty.getType());
    assertTrue(StringUtils.isEmpty(formProperty.getVariable()));
    assertTrue(StringUtils.isEmpty(formProperty.getExpression()));
    formProperty = formProperties.get(2);
    assertEquals("formId3", formProperty.getId());
    assertEquals("enumName", formProperty.getName());
    assertEquals("enum", formProperty.getType());
    assertTrue(StringUtils.isEmpty(formProperty.getVariable()));
    assertTrue(StringUtils.isEmpty(formProperty.getExpression()));
    assertEquals(2, formProperty.getFormValues().size());
    List<ActivitiListener> listeners = userTask.getTaskListeners();
    assertEquals(3, listeners.size());
    ActivitiListener listener = listeners.get(0);
    assertTrue(ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType()));
    assertEquals("org.test.TestClass", listener.getImplementation());
    assertEquals("create", listener.getEvent());
    listener = listeners.get(1);
    assertTrue(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equals(listener.getImplementationType()));
    assertEquals("${someExpression}", listener.getImplementation());
    assertEquals("assignment", listener.getEvent());
    listener = listeners.get(2);
    assertTrue(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equals(listener.getImplementationType()));
    assertEquals("${someDelegateExpression}", listener.getImplementation());
    assertEquals("complete", listener.getEvent());
    List<ActivitiListener> executionListeners = userTask.getExecutionListeners();
    assertEquals(1, executionListeners.size());
    ActivitiListener executionListener = executionListeners.get(0);
    assertEquals("end", executionListener.getEvent());
}
Also used : FormProperty(org.activiti.bpmn.model.FormProperty) FlowElement(org.activiti.bpmn.model.FlowElement) UserTask(org.activiti.bpmn.model.UserTask) ActivitiListener(org.activiti.bpmn.model.ActivitiListener)

Example 5 with FormProperty

use of org.activiti.bpmn.model.FormProperty 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() == false && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME) != null && enumNode.get(PROPERTY_FORM_ENUM_VALUES_NAME).isNull() == false) {
                                    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() == false) {
                                    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

FormProperty (org.activiti.bpmn.model.FormProperty)11 FormValue (org.activiti.bpmn.model.FormValue)7 UserTask (org.activiti.bpmn.model.UserTask)7 StartEvent (org.activiti.bpmn.model.StartEvent)6 FlowElement (org.activiti.bpmn.model.FlowElement)5 ArrayList (java.util.ArrayList)4 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)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 FieldExtension (org.activiti.bpmn.model.FieldExtension)1 SequenceFlow (org.activiti.bpmn.model.SequenceFlow)1 DatePropertyDefinition (org.activiti.workflow.simple.definition.form.DatePropertyDefinition)1 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)1