Search in sources :

Example 11 with VariableScopeInstance

use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.

the class WorkflowProcessInstanceImpl method getVariables.

@Override
public Map<String, Object> getVariables() {
    // be null and the associated working memory is no longer accessible)
    if (getProcessRuntime() == null) {
        List<ContextInstance> variableScopeInstances = getContextInstances(VariableScope.VARIABLE_SCOPE);
        if (variableScopeInstances == null) {
            return Collections.emptyMap();
        }
        Map<String, Object> result = new HashMap<>();
        for (ContextInstance contextInstance : variableScopeInstances) {
            Map<String, Object> variables = ((VariableScopeInstance) contextInstance).getVariables();
            result.putAll(variables);
        }
        return result;
    }
    // else retrieve the variable scope
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) getContextInstance(VariableScope.VARIABLE_SCOPE);
    if (variableScopeInstance == null) {
        return null;
    }
    return variableScopeInstance.getVariables();
}
Also used : VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) HashMap(java.util.HashMap) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance)

Example 12 with VariableScopeInstance

use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.

the class CompositeContextNodeInstance method processInputMappings.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void processInputMappings() {
    VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
    for (DataAssociation association : getCompositeContextNode().getInAssociations()) {
        if (association.getTransformation() != null) {
            Transformation transformation = association.getTransformation();
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            if (transformer != null) {
                Object parameterValue = transformer.transform(transformation.getCompiledExpression(), getProcessInstance().getVariables());
                if (parameterValue != null) {
                    compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
                }
            }
        } else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
            Object parameterValue = null;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getSources().get(0));
            if (variableScopeInstance != null) {
                parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
            } else {
                try {
                    ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                    parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
                } catch (Throwable t) {
                    logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
                    logger.error("Continuing without setting parameter.");
                }
            }
            if (parameterValue != null) {
                compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
            }
        } else {
            association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
        }
    }
}
Also used : Context(io.automatiko.engine.workflow.base.core.Context) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) ContextInstanceFactoryRegistry(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactoryRegistry) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) ContextInstanceFactory(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory) VARIABLE_SCOPE(io.automatiko.engine.workflow.base.core.context.variable.VariableScope.VARIABLE_SCOPE) Logger(org.slf4j.Logger) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) List(java.util.List) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) ContextableInstance(io.automatiko.engine.workflow.base.instance.ContextableInstance) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess)

Example 13 with VariableScopeInstance

use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.

the class CompositeContextNodeInstance method triggerCompleted.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void triggerCompleted(String outType) {
    VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
    for (DataAssociation association : getCompositeContextNode().getOutAssociations()) {
        if (association.getTransformation() != null) {
            Transformation transformation = association.getTransformation();
            DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
            if (transformer != null) {
                Object parameterValue = transformer.transform(transformation.getCompiledExpression(), compositeVariableScopeInstance.getVariables());
                if (parameterValue != null) {
                    getProcessInstance().setVariable(association.getTarget(), parameterValue);
                }
            }
        } else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
            Object parameterValue = null;
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VARIABLE_SCOPE, association.getSources().get(0));
            if (variableScopeInstance != null) {
                parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
            } else {
                try {
                    ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                    parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
                } catch (Throwable t) {
                    logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
                    logger.error("Continuing without setting parameter.");
                }
            }
            if (parameterValue != null) {
                getProcessInstance().setVariable(association.getTarget(), parameterValue);
            }
        } else {
            association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
        }
    }
    super.triggerCompleted(outType);
}
Also used : Context(io.automatiko.engine.workflow.base.core.Context) Assignment(io.automatiko.engine.workflow.process.core.node.Assignment) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) ArrayList(java.util.ArrayList) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) ContextInstanceFactoryRegistry(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactoryRegistry) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) Map(java.util.Map) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) ContextInstanceFactory(io.automatiko.engine.workflow.base.instance.impl.ContextInstanceFactory) VARIABLE_SCOPE(io.automatiko.engine.workflow.base.core.context.variable.VariableScope.VARIABLE_SCOPE) Logger(org.slf4j.Logger) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) DataTransformerRegistry(io.automatiko.engine.workflow.base.core.impl.DataTransformerRegistry) List(java.util.List) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) ContextableInstance(io.automatiko.engine.workflow.base.instance.ContextableInstance) Transformation(io.automatiko.engine.workflow.process.core.node.Transformation) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) DataTransformer(io.automatiko.engine.api.runtime.process.DataTransformer) DataAssociation(io.automatiko.engine.workflow.process.core.node.DataAssociation) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess)

Example 14 with VariableScopeInstance

use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.

the class WorkflowProcessInstanceImpl method setVariable.

@Override
public void setVariable(String name, Object value) {
    VariableScope variableScope = (VariableScope) ((ContextContainer) getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
    VariableScopeInstance variableScopeInstance = (VariableScopeInstance) getContextInstance(VariableScope.VARIABLE_SCOPE);
    if (variableScopeInstance == null) {
        throw new IllegalArgumentException("No variable scope found.");
    }
    variableScope.validateVariable(getProcessName(), name, value);
    variableScopeInstance.setVariable(name, value);
}
Also used : VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope)

Example 15 with VariableScopeInstance

use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.

the class NodeInstanceImpl method setVariable.

public void setVariable(String variableName, Object value) {
    VariableScopeInstance variableScope = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
    if (variableScope == null) {
        variableScope = (VariableScopeInstance) getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
        if (variableScope.getVariableScope().findVariable(variableName) == null) {
            variableScope = null;
        }
    }
    if (variableScope == null) {
        logger.error("Could not find variable {}", variableName);
        logger.error("Using process-level scope");
        variableScope = (VariableScopeInstance) getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
    }
    variableScope.setVariable(this, variableName, value);
}
Also used : VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)

Aggregations

VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)44 HashMap (java.util.HashMap)26 ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)20 NodeInstanceResolverFactory (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory)18 Map (java.util.Map)16 Matcher (java.util.regex.Matcher)12 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)11 DataAssociation (io.automatiko.engine.workflow.process.core.node.DataAssociation)11 DataTransformer (io.automatiko.engine.api.runtime.process.DataTransformer)10 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)9 Transformation (io.automatiko.engine.workflow.process.core.node.Transformation)9 WorkflowProcess (io.automatiko.engine.workflow.process.core.WorkflowProcess)7 ArrayList (java.util.ArrayList)7 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)6 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)6 Serializable (java.io.Serializable)6 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)5 Process (io.automatiko.engine.api.definition.process.Process)4 DataType (io.automatiko.engine.api.workflow.datatype.DataType)4 Context (io.automatiko.engine.workflow.base.core.Context)4