Java Code Examples for org.flowable.engine.impl.persistence.entity.ExecutionEntity#setVariable()

The following examples show how to use org.flowable.engine.impl.persistence.entity.ExecutionEntity#setVariable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalWorkerTaskCompleteJobHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(JobEntity job, String configuration, VariableScope variableScope, CommandContext commandContext) {
    ExecutionEntity executionEntity = (ExecutionEntity) variableScope;

    VariableService variableService = CommandContextUtil.getVariableService(commandContext);
    List<VariableInstanceEntity> jobVariables = variableService.findVariableInstanceBySubScopeIdAndScopeType(executionEntity.getId(), ScopeTypes.BPMN_EXTERNAL_WORKER);
    for (VariableInstanceEntity jobVariable : jobVariables) {
        executionEntity.setVariable(jobVariable.getName(), jobVariable.getValue());
        CountingEntityUtil.handleDeleteVariableInstanceEntityCount(jobVariable, false);
        variableService.deleteVariableInstance(jobVariable);
    }

    if (configuration != null && configuration.startsWith("error:")) {
        String errorCode;
        if (configuration.length() > 6) {
            errorCode = configuration.substring(6);
        } else {
            errorCode = null;
        }
        ErrorPropagation.propagateError(errorCode, executionEntity);
    } else {
        CommandContextUtil.getAgenda(commandContext).planTriggerExecutionOperation(executionEntity);
    }
}
 
Example 2
Source File: MyTaskListenerBean.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager().findById(delegateTask.getExecutionId());
    execution.setVariable("taskListenerVar", "working");
    if (someField != null) {
        execution.setVariable("taskListenerField", someField.getValue(delegateTask));
    }
}
 
Example 3
Source File: DefaultFormHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void submitFormProperties(Map<String, String> properties, ExecutionEntity execution) {
    Map<String, String> propertiesCopy = new HashMap<>(properties);
    for (FormPropertyHandler formPropertyHandler : formPropertyHandlers) {
        // submitFormProperty will remove all the keys which it takes care
        // of
        formPropertyHandler.submitFormProperty(execution, propertiesCopy);
    }
    for (String propertyId : propertiesCopy.keySet()) {
        execution.setVariable(propertyId, propertiesCopy.get(propertyId));
    }
}
 
Example 4
Source File: FormPropertyHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void submitFormProperty(ExecutionEntity execution, Map<String, String> properties) {
    if (!isWritable && properties.containsKey(id)) {
        throw new FlowableException("form property '" + id + "' is not writable");
    }

    if (isRequired && !properties.containsKey(id) && defaultExpression == null) {
        throw new FlowableException("form property '" + id + "' is required");
    }
    boolean propertyExists = false;
    Object modelValue = null;
    if (properties.containsKey(id)) {
        propertyExists = true;
        final String propertyValue = properties.remove(id);
        if (type != null) {
            modelValue = type.convertFormValueToModelValue(propertyValue);
        } else {
            modelValue = propertyValue;
        }
    } else if (defaultExpression != null) {
        final Object expressionValue = defaultExpression.getValue(execution);
        if (type != null && expressionValue != null) {
            modelValue = type.convertFormValueToModelValue(expressionValue.toString());
        } else if (expressionValue != null) {
            modelValue = expressionValue.toString();
        } else if (isRequired) {
            throw new FlowableException("form property '" + id + "' is required");
        }
    }
    if (propertyExists || (modelValue != null)) {
        if (variableName != null) {
            execution.setVariable(variableName, modelValue);
        } else if (variableExpression != null) {
            variableExpression.setValue(modelValue, execution);
        } else {
            execution.setVariable(id, modelValue);
        }
    }
}
 
Example 5
Source File: TaskCompleteListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager().findById(delegateTask.getExecutionId());
    execution.setVariable("greeting", "Hello from " + greeter.getValue(execution));
    execution.setVariable("shortName", shortName.getValue(execution));

    delegateTask.setVariableLocal("myTaskVariable", "test");
}
 
Example 6
Source File: SetRandomVariablesTaskListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    String varName;
    for (int i = 0; i < 5; i++) {
        varName = "variable-" + new Random().nextInt(10);
        ExecutionEntity execution = CommandContextUtil.getExecutionEntityManager().findById(delegateTask.getExecutionId());
        execution.setVariable(varName, getRandomValue());
    }

    for (int i = 0; i < 5; i++) {
        varName = "task-variable-" + new Random().nextInt(10);
        delegateTask.setVariableLocal(varName, getRandomValue());
    }
}
 
Example 7
Source File: DefaultContextAssociationManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void setVariable(String variableName, Object value) {
    ExecutionEntity execution = getExecutionFromContext();
    if (execution != null) {
        execution.setVariable(variableName, value);
        execution.getVariable(variableName);
    } else {
        getScopedAssociation().setVariable(variableName, value);
    }
}