Search in sources :

Example 1 with BooleanPropertyDefinition

use of org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition in project Activiti by Activiti.

the class AlfrescoBooleanPropertyConverter method convertProperty.

@Override
public void convertProperty(M2Type contentType, String formSet, Form form, FormPropertyDefinition propertyDefinition, WorkflowDefinitionConversion conversion) {
    BooleanPropertyDefinition booleanDefinition = (BooleanPropertyDefinition) propertyDefinition;
    String propertyName = getPropertyName(propertyDefinition, conversion);
    // Add to content model
    M2Property property = new M2Property();
    property.setMandatory(new M2Mandatory(booleanDefinition.isMandatory()));
    property.setName(propertyName);
    property.setPropertyType(AlfrescoConversionConstants.PROPERTY_TYPE_BOOLEAN);
    M2Model model = AlfrescoConversionUtil.getContentModel(conversion);
    M2Aspect aspect = model.getAspect(propertyName);
    if (aspect != null) {
        // do this here
        if (aspect.getProperties().isEmpty()) {
            aspect.getProperties().add(property);
        }
        contentType.getMandatoryAspects().add(propertyName);
    } else {
        contentType.getProperties().add(property);
    }
    // Add form configuration
    form.getFormFieldVisibility().addShowFieldElement(propertyName);
    FormField formField = form.getFormAppearance().addFormField(propertyName, booleanDefinition.getName(), formSet);
    if (!booleanDefinition.isWritable()) {
        // Read-only properties should always be rendered using an info-template
        FormFieldControl control = new FormFieldControl();
        control.setTemplate(AlfrescoConversionConstants.FORM_READONLY_TEMPLATE);
        formField.setControl(control);
    }
    if (!form.isStartForm()) {
        // Add to output properties, if needed
        addOutputProperty(propertyDefinition, propertyName, contentType.getName(), conversion);
    }
}
Also used : BooleanPropertyDefinition(org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition) M2Property(org.activiti.workflow.simple.alfresco.model.M2Property) FormFieldControl(org.activiti.workflow.simple.alfresco.model.config.FormFieldControl) M2Model(org.activiti.workflow.simple.alfresco.model.M2Model) M2Aspect(org.activiti.workflow.simple.alfresco.model.M2Aspect) M2Mandatory(org.activiti.workflow.simple.alfresco.model.M2Mandatory) FormField(org.activiti.workflow.simple.alfresco.model.config.FormField)

Example 2 with BooleanPropertyDefinition

use of org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition 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 BooleanPropertyDefinition

use of org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition 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)

Aggregations

BooleanPropertyDefinition (org.activiti.workflow.simple.definition.form.BooleanPropertyDefinition)3 FormProperty (org.activiti.bpmn.model.FormProperty)2 FormValue (org.activiti.bpmn.model.FormValue)2 ListPropertyDefinition (org.activiti.workflow.simple.definition.form.ListPropertyDefinition)2 ListPropertyEntry (org.activiti.workflow.simple.definition.form.ListPropertyEntry)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 M2Aspect (org.activiti.workflow.simple.alfresco.model.M2Aspect)1 M2Mandatory (org.activiti.workflow.simple.alfresco.model.M2Mandatory)1 M2Model (org.activiti.workflow.simple.alfresco.model.M2Model)1 M2Property (org.activiti.workflow.simple.alfresco.model.M2Property)1 FormField (org.activiti.workflow.simple.alfresco.model.config.FormField)1 FormFieldControl (org.activiti.workflow.simple.alfresco.model.config.FormFieldControl)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 Test (org.junit.Test)1