Search in sources :

Example 26 with TypedValue

use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.

the class FormFieldHandler method createFormField.

public FormField createFormField(ExecutionEntity executionEntity) {
    FormFieldImpl formField = new FormFieldImpl();
    // set id
    formField.setId(id);
    // set label (evaluate expression)
    VariableScope variableScope = executionEntity != null ? executionEntity : StartProcessVariableScope.getSharedInstance();
    if (label != null) {
        Object labelValueObject = label.getValue(variableScope);
        if (labelValueObject != null) {
            formField.setLabel(labelValueObject.toString());
        }
    }
    formField.setBusinessKey(businessKey);
    // set type
    formField.setType(type);
    // set default value (evaluate expression)
    Object defaultValue = null;
    if (defaultValueExpression != null) {
        defaultValue = defaultValueExpression.getValue(variableScope);
        if (defaultValue != null) {
            formField.setDefaultValue(type.convertFormValueToModelValue(defaultValue));
        } else {
            formField.setDefaultValue(null);
        }
    }
    // value
    TypedValue value = variableScope.getVariableTyped(id);
    if (value != null) {
        formField.setValue(type.convertToFormValue(value));
    } else {
        // first, need to convert to model value since the default value may be a String Constant specified in the model xml.
        TypedValue typedDefaultValue = type.convertToModelValue(Variables.untypedValue(defaultValue));
        // now convert to form value
        formField.setValue(type.convertToFormValue(typedDefaultValue));
    }
    // properties
    formField.setProperties(properties);
    // validation
    List<FormFieldValidationConstraint> validationConstraints = formField.getValidationConstraints();
    for (FormFieldValidationConstraintHandler validationHandler : validationHandlers) {
        // do not add custom validators
        if (!"validator".equals(validationHandler.name)) {
            validationConstraints.add(validationHandler.createValidationConstraint(executionEntity));
        }
    }
    return formField;
}
Also used : FormFieldValidationConstraint(org.camunda.bpm.engine.form.FormFieldValidationConstraint) FormFieldImpl(org.camunda.bpm.engine.impl.form.FormFieldImpl) VariableScope(org.camunda.bpm.engine.delegate.VariableScope) StartProcessVariableScope(org.camunda.bpm.engine.impl.el.StartProcessVariableScope) TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 27 with TypedValue

use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.

the class FormFieldHandler method handleSubmit.

// submit /////////////////////////////////////////////
public void handleSubmit(VariableScope variableScope, VariableMap values, VariableMap allValues) {
    TypedValue submittedValue = (TypedValue) values.getValueTyped(id);
    values.remove(id);
    // perform validation
    for (FormFieldValidationConstraintHandler validationHandler : validationHandlers) {
        Object value = null;
        if (submittedValue != null) {
            value = submittedValue.getValue();
        }
        validationHandler.validate(value, allValues, this, variableScope);
    }
    // update variable(s)
    TypedValue modelValue = null;
    if (submittedValue != null) {
        if (type != null) {
            modelValue = type.convertToModelValue(submittedValue);
        } else {
            modelValue = submittedValue;
        }
    } else if (defaultValueExpression != null) {
        final TypedValue expressionValue = Variables.untypedValue(defaultValueExpression.getValue(variableScope));
        if (type != null) {
            // first, need to convert to model value since the default value may be a String Constant specified in the model xml.
            modelValue = type.convertToModelValue(Variables.untypedValue(expressionValue));
        } else if (expressionValue != null) {
            modelValue = Variables.stringValue(expressionValue.getValue().toString());
        }
    }
    if (modelValue != null) {
        if (id != null) {
            variableScope.setVariable(id, modelValue);
        }
    }
}
Also used : TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 28 with TypedValue

use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.

the class TaskAuthorizationTest method testProcessTaskGetVariableTypedWithReadPermissionOnTask.

public void testProcessTaskGetVariableTypedWithReadPermissionOnTask() {
    // given
    startProcessInstanceByKey(PROCESS_KEY, getVariables());
    String taskId = selectSingleTask().getId();
    createGrantAuthorization(TASK, taskId, userId, READ);
    // when
    TypedValue typedValue = taskService.getVariableTyped(taskId, VARIABLE_NAME);
    // then
    assertNotNull(typedValue);
    assertEquals(VARIABLE_VALUE, typedValue.getValue());
}
Also used : TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 29 with TypedValue

use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.

the class TaskAuthorizationTest method testProcessTaskGetVariableLocalTypedWithReadPermissionOnAnyTask.

public void testProcessTaskGetVariableLocalTypedWithReadPermissionOnAnyTask() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    String taskId = selectSingleTask().getId();
    createGrantAuthorization(TASK, ANY, userId, READ);
    disableAuthorization();
    taskService.setVariablesLocal(taskId, getVariables());
    enableAuthorization();
    // when
    TypedValue typedValue = taskService.getVariableLocalTyped(taskId, VARIABLE_NAME);
    // then
    assertNotNull(typedValue);
    assertEquals(VARIABLE_VALUE, typedValue.getValue());
}
Also used : TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Example 30 with TypedValue

use of org.camunda.bpm.engine.variable.value.TypedValue in project camunda-bpm-platform by camunda.

the class TaskAuthorizationTest method testProcessTaskGetVariableLocalTypedWithReadInstancePermissionOnProcessDefinition.

public void testProcessTaskGetVariableLocalTypedWithReadInstancePermissionOnProcessDefinition() {
    // given
    startProcessInstanceByKey(PROCESS_KEY);
    String taskId = selectSingleTask().getId();
    createGrantAuthorization(PROCESS_DEFINITION, PROCESS_KEY, userId, READ_TASK);
    disableAuthorization();
    taskService.setVariablesLocal(taskId, getVariables());
    enableAuthorization();
    // when
    TypedValue typedValue = taskService.getVariableLocalTyped(taskId, VARIABLE_NAME);
    // then
    assertNotNull(typedValue);
    assertEquals(VARIABLE_VALUE, typedValue.getValue());
}
Also used : TypedValue(org.camunda.bpm.engine.variable.value.TypedValue)

Aggregations

TypedValue (org.camunda.bpm.engine.variable.value.TypedValue)81 Test (org.junit.Test)25 Deployment (org.camunda.bpm.engine.test.Deployment)15 DmnEngineTest (org.camunda.bpm.dmn.engine.test.DmnEngineTest)14 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)11 DecisionResource (org.camunda.bpm.dmn.engine.test.DecisionResource)8 VariableMap (org.camunda.bpm.engine.variable.VariableMap)7 DmnDataTypeTransformer (org.camunda.bpm.dmn.engine.impl.spi.type.DmnDataTypeTransformer)6 BusinessProcess (org.camunda.bpm.engine.cdi.BusinessProcess)6 DmnDecisionResult (org.camunda.bpm.dmn.engine.DmnDecisionResult)4 DmnDecisionTableResult (org.camunda.bpm.dmn.engine.DmnDecisionTableResult)4 DmnExpressionImpl (org.camunda.bpm.dmn.engine.impl.DmnExpressionImpl)3 DeclarativeProcessController (org.camunda.bpm.engine.cdi.test.impl.beans.DeclarativeProcessController)3 RestException (org.camunda.bpm.engine.rest.exception.RestException)3 Task (org.camunda.bpm.engine.task.Task)3 ArrayList (java.util.ArrayList)2 DmnDecisionResultEntries (org.camunda.bpm.dmn.engine.DmnDecisionResultEntries)2 DmnDecisionRuleResult (org.camunda.bpm.dmn.engine.DmnDecisionRuleResult)2 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2