Java Code Examples for org.flowable.engine.delegate.DelegateExecution#setTransientVariable()

The following examples show how to use org.flowable.engine.delegate.DelegateExecution#setTransientVariable() . 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: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
    String varName = (String) dataVariableName.getValue(execution);
    String resultVar = (String) resultVariableName.getValue(execution);

    // Sets the name of the variable as 'resultVar'
    for (String s : ((String) execution.getVariable(varName)).split(";")) {
        String[] data = s.split("=");
        if (data[0].equals("message")) {
            execution.setTransientVariable(resultVar, data[1]);
        }
    }
}
 
Example 2
Source File: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    String varName = (String) dataVariableName.getValue(execution);
    String resultVar = (String) resultVariableName.getValue(execution);

    // Sets the name of the variable as 'resultVar'
    for (String s : ((String) execution.getVariable(varName)).split(";")) {
        String[] data = s.split("=");
        if (data[0].equals("message")) {
            execution.setTransientVariable(resultVar, data[1]);
        }
    }
}
 
Example 3
Source File: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
    execution.setTransientVariable("response", "author=kermit;version=3;message=Hello World");
    execution.setTransientVariable("status", 200);
}
 
Example 4
Source File: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
    String var = (String) variableName.getValue(execution);
    execution.setTransientVariable(var, "author=kermit;version=3;message=" + var);
}
 
Example 5
Source File: ServiceTaskExpressionActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    Object value = null;
    try {
        CommandContext commandContext = CommandContextUtil.getCommandContext();
        String skipExpressionText = null;
        if (skipExpression != null) {
            skipExpressionText = skipExpression.getExpressionText();
        }
        boolean isSkipExpressionEnabled = SkipExpressionUtil.isSkipExpressionEnabled(skipExpressionText, serviceTaskId, execution, commandContext);
        if (!isSkipExpressionEnabled || !SkipExpressionUtil.shouldSkipFlowElement(skipExpressionText, serviceTaskId, execution, commandContext)) {

            if (CommandContextUtil.getProcessEngineConfiguration(commandContext).isEnableProcessDefinitionInfoCache()) {
                ObjectNode taskElementProperties = BpmnOverrideContext.getBpmnOverrideElementProperties(serviceTaskId, execution.getProcessDefinitionId());
                if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SERVICE_TASK_EXPRESSION)) {
                    String overrideExpression = taskElementProperties.get(DynamicBpmnConstants.SERVICE_TASK_EXPRESSION).asText();
                    if (StringUtils.isNotEmpty(overrideExpression) && !overrideExpression.equals(expression.getExpressionText())) {
                        expression = CommandContextUtil.getProcessEngineConfiguration(commandContext).getExpressionManager().createExpression(overrideExpression);
                    }
                }
            }

            value = expression.getValue(execution);
            if (resultVariable != null) {
                if (storeResultVariableAsTransient) {
                    if (useLocalScopeForResultVariable) {
                        execution.setTransientVariableLocal(resultVariable, value);
                    } else {
                        execution.setTransientVariable(resultVariable, value);
                    }
                } else {
                    if (useLocalScopeForResultVariable) {
                        execution.setVariableLocal(resultVariable, value);
                    } else {
                        execution.setVariable(resultVariable, value);
                    }
                }
            }
        }
        if (!this.triggerable) {
            leave(execution);
        }

    } catch (Exception exc) {

        Throwable cause = exc;
        BpmnError error = null;
        while (cause != null) {
            if (cause instanceof BpmnError) {
                error = (BpmnError) cause;
                break;
            } else if (cause instanceof RuntimeException) {
                if (ErrorPropagation.mapException((RuntimeException) cause, (ExecutionEntity) execution, mapExceptions)) {
                    return;
                }
            }
            cause = cause.getCause();
        }

        if (error != null) {
            ErrorPropagation.propagateError(error, execution);
        } else {
            throw exc;
        }
    }
}
 
Example 6
Source File: WebServiceActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(execution.getProcessDefinitionId());
    FlowElement flowElement = execution.getCurrentFlowElement();

    IOSpecification ioSpecification = null;
    String operationRef = null;
    List<DataAssociation> dataInputAssociations = null;
    List<DataAssociation> dataOutputAssociations = null;

    if (flowElement instanceof SendTask) {
        SendTask sendTask = (SendTask) flowElement;
        ioSpecification = sendTask.getIoSpecification();
        operationRef = sendTask.getOperationRef();
        dataInputAssociations = sendTask.getDataInputAssociations();
        dataOutputAssociations = sendTask.getDataOutputAssociations();

    } else if (flowElement instanceof ServiceTask) {
        ServiceTask serviceTask = (ServiceTask) flowElement;
        ioSpecification = serviceTask.getIoSpecification();
        operationRef = serviceTask.getOperationRef();
        dataInputAssociations = serviceTask.getDataInputAssociations();
        dataOutputAssociations = serviceTask.getDataOutputAssociations();

    } else {
        throw new FlowableException("Unsupported flow element type " + flowElement);
    }

    MessageInstance message = null;

    Operation operation = operationMap.get(operationRef);

    try {

        if (ioSpecification != null) {
            initializeIoSpecification(ioSpecification, execution, bpmnModel);
            if (ioSpecification.getDataInputRefs().size() > 0) {
                String firstDataInputName = ioSpecification.getDataInputRefs().get(0);
                ItemInstance inputItem = (ItemInstance) execution.getTransientVariable(firstDataInputName);
                message = new MessageInstance(operation.getInMessage(), inputItem);
            }

        } else {
            message = operation.getInMessage().createInstance();
        }

        execution.setTransientVariable(CURRENT_MESSAGE, message);

        fillMessage(dataInputAssociations, execution);

        ProcessEngineConfigurationImpl processEngineConfig = CommandContextUtil.getProcessEngineConfiguration();
        MessageInstance receivedMessage = operation.sendMessage(message,
                processEngineConfig.getWsOverridenEndpointAddresses());

        execution.setTransientVariable(CURRENT_MESSAGE, receivedMessage);

        if (ioSpecification != null && ioSpecification.getDataOutputRefs().size() > 0) {
            String firstDataOutputName = ioSpecification.getDataOutputRefs().get(0);
            if (firstDataOutputName != null) {
                ItemInstance outputItem = (ItemInstance) execution.getTransientVariable(firstDataOutputName);
                outputItem.getStructureInstance().loadFrom(receivedMessage.getStructureInstance().toArray());
            }
        }

        returnMessage(dataOutputAssociations, execution);

        execution.setTransientVariable(CURRENT_MESSAGE, null);
        leave(execution);
    } catch (Exception exc) {

        Throwable cause = exc;
        BpmnError error = null;
        while (cause != null) {
            if (cause instanceof BpmnError) {
                error = (BpmnError) cause;
                break;
            }
            cause = cause.getCause();
        }

        if (error != null) {
            ErrorPropagation.propagateError(error, execution);
        } else if (exc instanceof RuntimeException) {
            throw (RuntimeException) exc;
        }
    }
}
 
Example 7
Source File: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    execution.setTransientVariable("response", "author=kermit;version=3;message=Hello World");
    execution.setTransientVariable("status", 200);
}
 
Example 8
Source File: TransientVariablesTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    String var = (String) variableName.getValue(execution);
    execution.setTransientVariable(var, "author=kermit;version=3;message=" + var);
}