Search in sources :

Example 1 with ProcessRuntimeServiceProvider

use of io.automatiko.engine.workflow.base.instance.ProcessRuntimeServiceProvider in project automatiko-engine by automatiko-io.

the class AbstractProtobufProcessInstanceMarshaller method readVariableScope.

protected void readVariableScope(MarshallerReaderContext context, Process process, WorkflowProcessInstanceImpl processInstance, AutomatikoMessages.ProcessInstance _instance) throws IOException {
    if (_instance.getVariableCount() > 0) {
        VariableScope variableScope = (VariableScope) ((io.automatiko.engine.workflow.base.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(variableScope);
        for (AutomatikoMessages.Variable _variable : _instance.getVariableList()) {
            try {
                Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
                if ((boolean) context.env.getOrDefault("_import_", false)) {
                    VariableInitializer initializer = ((ProcessRuntimeServiceProvider) context.env.get("_services_")).getVariableInitializer();
                    for (VariableAugmentor augmentor : initializer.augmentors()) {
                        Variable var = variableScope.findVariable(_variable.getName());
                        if (augmentor.accept(var, _value)) {
                            _value = augmentor.augmentOnCreate(process.getId(), process.getVersion(), _instance.getId(), var, _value);
                        }
                    }
                }
                variableScopeInstance.internalSetVariable(_variable.getName(), _value);
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
            }
        }
    }
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) VariableAugmentor(io.automatiko.engine.api.workflow.VariableAugmentor) ProcessRuntimeServiceProvider(io.automatiko.engine.workflow.base.instance.ProcessRuntimeServiceProvider) VariableInitializer(io.automatiko.engine.api.workflow.VariableInitializer) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Aggregations

VariableAugmentor (io.automatiko.engine.api.workflow.VariableAugmentor)1 VariableInitializer (io.automatiko.engine.api.workflow.VariableInitializer)1 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)1 ProcessRuntimeServiceProvider (io.automatiko.engine.workflow.base.instance.ProcessRuntimeServiceProvider)1 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)1