Search in sources :

Example 1 with AbstractFormFieldType

use of org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType in project camunda-bpm-platform by camunda.

the class DefaultFormHandler method parseFormField.

protected void parseFormField(Element formField, BpmnParse bpmnParse, ExpressionManager expressionManager) {
    FormFieldHandler formFieldHandler = new FormFieldHandler();
    // parse Id
    String id = formField.attribute("id");
    if (id == null || id.isEmpty()) {
        bpmnParse.addError("attribute id must be set for FormFieldGroup and must have a non-empty value", formField);
    } else {
        formFieldHandler.setId(id);
    }
    if (id.equals(businessKeyFieldId)) {
        formFieldHandler.setBusinessKey(true);
    }
    // parse name
    String name = formField.attribute("label");
    if (name != null) {
        Expression nameExpression = expressionManager.createExpression(name);
        formFieldHandler.setLabel(nameExpression);
    }
    // parse properties
    parseProperties(formField, formFieldHandler, bpmnParse, expressionManager);
    // parse validation
    parseValidation(formField, formFieldHandler, bpmnParse, expressionManager);
    // parse type
    FormTypes formTypes = getFormTypes();
    AbstractFormFieldType formType = formTypes.parseFormPropertyType(formField, bpmnParse);
    formFieldHandler.setType(formType);
    // parse default value
    String defaultValue = formField.attribute("defaultValue");
    if (defaultValue != null) {
        Expression defaultValueExpression = expressionManager.createExpression(defaultValue);
        formFieldHandler.setDefaultValueExpression(defaultValueExpression);
    }
    formFieldHandlers.add(formFieldHandler);
}
Also used : FormTypes(org.camunda.bpm.engine.impl.form.type.FormTypes) Expression(org.camunda.bpm.engine.delegate.Expression) AbstractFormFieldType(org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType)

Example 2 with AbstractFormFieldType

use of org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType in project camunda-bpm-platform by camunda.

the class DefaultFormHandler method parseFormProperties.

protected void parseFormProperties(BpmnParse bpmnParse, ExpressionManager expressionManager, Element extensionElement) {
    FormTypes formTypes = getFormTypes();
    List<Element> formPropertyElements = extensionElement.elementsNS(BpmnParse.CAMUNDA_BPMN_EXTENSIONS_NS, FORM_PROPERTY_ELEMENT);
    for (Element formPropertyElement : formPropertyElements) {
        FormPropertyHandler formPropertyHandler = new FormPropertyHandler();
        String id = formPropertyElement.attribute("id");
        if (id == null) {
            bpmnParse.addError("attribute 'id' is required", formPropertyElement);
        }
        formPropertyHandler.setId(id);
        String name = formPropertyElement.attribute("name");
        formPropertyHandler.setName(name);
        AbstractFormFieldType type = formTypes.parseFormPropertyType(formPropertyElement, bpmnParse);
        formPropertyHandler.setType(type);
        String requiredText = formPropertyElement.attribute("required", "false");
        Boolean required = bpmnParse.parseBooleanAttribute(requiredText);
        if (required != null) {
            formPropertyHandler.setRequired(required);
        } else {
            bpmnParse.addError("attribute 'required' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
        }
        String readableText = formPropertyElement.attribute("readable", "true");
        Boolean readable = bpmnParse.parseBooleanAttribute(readableText);
        if (readable != null) {
            formPropertyHandler.setReadable(readable);
        } else {
            bpmnParse.addError("attribute 'readable' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
        }
        String writableText = formPropertyElement.attribute("writable", "true");
        Boolean writable = bpmnParse.parseBooleanAttribute(writableText);
        if (writable != null) {
            formPropertyHandler.setWritable(writable);
        } else {
            bpmnParse.addError("attribute 'writable' must be one of {on|yes|true|enabled|active|off|no|false|disabled|inactive}", formPropertyElement);
        }
        String variableName = formPropertyElement.attribute("variable");
        formPropertyHandler.setVariableName(variableName);
        String expressionText = formPropertyElement.attribute("expression");
        if (expressionText != null) {
            Expression expression = expressionManager.createExpression(expressionText);
            formPropertyHandler.setVariableExpression(expression);
        }
        String defaultExpressionText = formPropertyElement.attribute("default");
        if (defaultExpressionText != null) {
            Expression defaultExpression = expressionManager.createExpression(defaultExpressionText);
            formPropertyHandler.setDefaultExpression(defaultExpression);
        }
        formPropertyHandlers.add(formPropertyHandler);
    }
}
Also used : FormTypes(org.camunda.bpm.engine.impl.form.type.FormTypes) Expression(org.camunda.bpm.engine.delegate.Expression) Element(org.camunda.bpm.engine.impl.util.xml.Element) AbstractFormFieldType(org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType)

Example 3 with AbstractFormFieldType

use of org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType in project camunda-bpm-platform by camunda.

the class ProcessEngineConfigurationImpl method initFormTypes.

protected void initFormTypes() {
    if (formTypes == null) {
        formTypes = new FormTypes();
        formTypes.addFormType(new StringFormType());
        formTypes.addFormType(new LongFormType());
        formTypes.addFormType(new DateFormType("dd/MM/yyyy"));
        formTypes.addFormType(new BooleanFormType());
    }
    if (customFormTypes != null) {
        for (AbstractFormFieldType customFormType : customFormTypes) {
            formTypes.addFormType(customFormType);
        }
    }
}
Also used : FormTypes(org.camunda.bpm.engine.impl.form.type.FormTypes) StringFormType(org.camunda.bpm.engine.impl.form.type.StringFormType) DateFormType(org.camunda.bpm.engine.impl.form.type.DateFormType) AbstractFormFieldType(org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType) LongFormType(org.camunda.bpm.engine.impl.form.type.LongFormType) BooleanFormType(org.camunda.bpm.engine.impl.form.type.BooleanFormType)

Example 4 with AbstractFormFieldType

use of org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType in project camunda-bpm-platform by camunda.

the class FormServiceTest method testGetStartFormVariables.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/form/FormServiceTest.startFormFields.bpmn20.xml" })
@Test
public void testGetStartFormVariables() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    VariableMap variables = formService.getStartFormVariables(processDefinition.getId());
    assertEquals(4, variables.size());
    assertEquals("someString", variables.get("stringField"));
    assertEquals("someString", variables.getValueTyped("stringField").getValue());
    assertEquals(ValueType.STRING, variables.getValueTyped("stringField").getType());
    assertEquals(5l, variables.get("longField"));
    assertEquals(5l, variables.getValueTyped("longField").getValue());
    assertEquals(ValueType.LONG, variables.getValueTyped("longField").getType());
    assertNull(variables.get("customField"));
    assertNull(variables.getValueTyped("customField").getValue());
    assertEquals(ValueType.STRING, variables.getValueTyped("customField").getType());
    assertNotNull(variables.get("dateField"));
    assertEquals(variables.get("dateField"), variables.getValueTyped("dateField").getValue());
    assertEquals(ValueType.STRING, variables.getValueTyped("dateField").getType());
    AbstractFormFieldType dateFormType = processEngineConfiguration.getFormTypes().getFormType("date");
    Date dateValue = (Date) dateFormType.convertToModelValue(variables.getValueTyped("dateField")).getValue();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(dateValue);
    assertEquals(10, calendar.get(Calendar.DAY_OF_MONTH));
    assertEquals(Calendar.JANUARY, calendar.get(Calendar.MONTH));
    assertEquals(2013, calendar.get(Calendar.YEAR));
    // get restricted set of variables:
    variables = formService.getStartFormVariables(processDefinition.getId(), Arrays.asList("stringField"), true);
    assertEquals(1, variables.size());
    assertEquals("someString", variables.get("stringField"));
    assertEquals("someString", variables.getValueTyped("stringField").getValue());
    assertEquals(ValueType.STRING, variables.getValueTyped("stringField").getType());
    // request non-existing variable
    variables = formService.getStartFormVariables(processDefinition.getId(), Arrays.asList("non-existing!"), true);
    assertEquals(0, variables.size());
    // null => all
    variables = formService.getStartFormVariables(processDefinition.getId(), null, true);
    assertEquals(4, variables.size());
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) Calendar(java.util.Calendar) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) AbstractFormFieldType(org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType) Date(java.util.Date) Test(org.junit.Test) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

AbstractFormFieldType (org.camunda.bpm.engine.impl.form.type.AbstractFormFieldType)4 FormTypes (org.camunda.bpm.engine.impl.form.type.FormTypes)3 Expression (org.camunda.bpm.engine.delegate.Expression)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 BooleanFormType (org.camunda.bpm.engine.impl.form.type.BooleanFormType)1 DateFormType (org.camunda.bpm.engine.impl.form.type.DateFormType)1 LongFormType (org.camunda.bpm.engine.impl.form.type.LongFormType)1 StringFormType (org.camunda.bpm.engine.impl.form.type.StringFormType)1 Element (org.camunda.bpm.engine.impl.util.xml.Element)1 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)1 Deployment (org.camunda.bpm.engine.test.Deployment)1 VariableMap (org.camunda.bpm.engine.variable.VariableMap)1 Test (org.junit.Test)1