Search in sources :

Example 1 with ProcessEventSupport

use of io.automatiko.engine.workflow.base.core.event.ProcessEventSupport in project automatiko-engine by automatiko-io.

the class DynamicUtils method executeWorkItem.

private static void executeWorkItem(InternalProcessRuntime runtime, WorkItemImpl workItem, WorkItemNodeInstance workItemNodeInstance) {
    ProcessEventSupport eventSupport = runtime.getProcessEventSupport();
    eventSupport.fireBeforeNodeTriggered(workItemNodeInstance, runtime);
    ((DefaultWorkItemManager) runtime.getWorkItemManager()).internalExecuteWorkItem(workItem);
    workItemNodeInstance.internalSetWorkItemId(workItem.getId());
    eventSupport.fireAfterNodeTriggered(workItemNodeInstance, runtime);
}
Also used : ProcessEventSupport(io.automatiko.engine.workflow.base.core.event.ProcessEventSupport) DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)

Example 2 with ProcessEventSupport

use of io.automatiko.engine.workflow.base.core.event.ProcessEventSupport in project automatiko-engine by automatiko-io.

the class DynamicUtils method executeSubProcess.

private static String executeSubProcess(InternalProcessRuntime runtime, String processId, Map<String, Object> parameters, ProcessInstance processInstance, SubProcessNodeInstance subProcessNodeInstance) {
    Process process = runtime.getProcess(processId);
    if (process == null) {
        logger.error("Could not find process {}", processId);
        throw new IllegalArgumentException("No process definition found with id: " + processId);
    } else {
        ProcessEventSupport eventSupport = runtime.getProcessEventSupport();
        eventSupport.fireBeforeNodeTriggered(subProcessNodeInstance, runtime);
        ProcessInstance subProcessInstance = null;
        if (((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey() != null) {
            List<String> businessKeys = new ArrayList<>();
            businessKeys.add(((WorkflowProcessInstanceImpl) processInstance).getCorrelationKey());
            businessKeys.add(processId);
            businessKeys.add(String.valueOf(System.currentTimeMillis()));
            CorrelationKey subProcessCorrelationKey = new StringCorrelationKey(businessKeys.stream().collect(Collectors.joining(":")));
            subProcessInstance = (ProcessInstance) runtime.createProcessInstance(processId, subProcessCorrelationKey, parameters);
        } else {
            subProcessInstance = (ProcessInstance) runtime.createProcessInstance(processId, parameters);
        }
        ((ProcessInstanceImpl) subProcessInstance).setMetaData("ParentProcessInstanceId", processInstance.getId());
        ((ProcessInstanceImpl) subProcessInstance).setParentProcessInstanceId(processInstance.getId());
        subProcessInstance = (ProcessInstance) runtime.startProcessInstance(subProcessInstance.getId());
        subProcessNodeInstance.internalSetProcessInstanceId(subProcessInstance.getId());
        eventSupport.fireAfterNodeTriggered(subProcessNodeInstance, runtime);
        if (subProcessInstance.getState() == io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED) {
            subProcessNodeInstance.triggerCompleted();
        } else {
            subProcessNodeInstance.addEventListeners();
        }
        return subProcessInstance.getId();
    }
}
Also used : ProcessEventSupport(io.automatiko.engine.workflow.base.core.event.ProcessEventSupport) StringCorrelationKey(io.automatiko.engine.services.correlation.StringCorrelationKey) CorrelationKey(io.automatiko.engine.services.correlation.CorrelationKey) StringCorrelationKey(io.automatiko.engine.services.correlation.StringCorrelationKey) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ArrayList(java.util.ArrayList) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.definition.process.Process) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)

Example 3 with ProcessEventSupport

use of io.automatiko.engine.workflow.base.core.event.ProcessEventSupport in project automatiko-engine by automatiko-io.

the class VariableScopeInstance method setVariable.

@SuppressWarnings("unchecked")
public void setVariable(NodeInstance nodeInstance, String name, Object value) {
    if (name == null) {
        throw new IllegalArgumentException("The name of a variable may not be null!");
    }
    Variable var = getVariableScope().findVariable(name);
    if (var != null) {
        name = var.getName();
    }
    Object oldValue = getVariable(name);
    if (oldValue == null) {
        if (value == null) {
            return;
        }
    }
    // check if variable that is being set is readonly and has already been set
    if (oldValue != null && getVariableScope().isReadOnly(name)) {
        throw new VariableViolationException(getProcessInstance().getId(), name, "Variable '" + name + "' is already set and is marked as read only");
    }
    // in case variable is marked as notnull (via tag) then null values should be ignored
    if (value == null && getVariableScope().isNullable(name)) {
        return;
    }
    // in case variable is versioned store the old value into versioned variable by variable name
    if (var != null && var.hasTag(Variable.VERSIONED_TAG)) {
        Map<String, List<Object>> versions = (Map<String, List<Object>>) variables.computeIfAbsent(VariableScope.VERSIONED_VARIABLES, key -> new ConcurrentHashMap<>());
        List<Object> varVersions = versions.computeIfAbsent(name, k -> new ArrayList<>());
        int versionLimit = Integer.parseInt(var.getMetaData().getOrDefault(Variable.VAR_VERSIONS_LIMIT, "10").toString());
        if (oldValue != null) {
            varVersions.add(oldValue);
            // and remove the oldest if exceeding
            if (varVersions.size() > versionLimit) {
                varVersions.remove(0);
            }
        }
    }
    if (getProcessInstance().getProcessRuntime().getVariableInitializer() != null) {
        for (VariableAugmentor augmentor : getProcessInstance().getProcessRuntime().getVariableInitializer().augmentors()) {
            if (augmentor.accept(var, value)) {
                // run any of the available augmentors on the value
                if (oldValue != null) {
                    value = augmentor.augmentOnUpdate(getProcessInstance().getProcess().getId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getId(), var, value);
                } else if (value == null) {
                    augmentor.augmentOnDelete(getProcessInstance().getProcess().getId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getId(), var, oldValue);
                } else {
                    value = augmentor.augmentOnCreate(getProcessInstance().getProcess().getId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getId(), var, value);
                }
            }
        }
    }
    ProcessInstance processInstance = getProcessInstance();
    if (nodeInstance != null) {
        processInstance = nodeInstance.getProcessInstance();
    }
    ProcessEventSupport processEventSupport = ((InternalProcessRuntime) getProcessInstance().getProcessRuntime()).getProcessEventSupport();
    processEventSupport.fireBeforeVariableChanged((variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null ? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getVariableScope().tags(name), processInstance, nodeInstance, getProcessInstance().getProcessRuntime());
    internalSetVariable(name, value);
    processEventSupport.fireAfterVariableChanged((variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null ? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getVariableScope().tags(name), processInstance, nodeInstance, getProcessInstance().getProcessRuntime());
    processInstance.signalEvent("variableChanged", value);
}
Also used : AbstractContextInstance(io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) ArrayList(java.util.ArrayList) ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) ContextInstanceContainer(io.automatiko.engine.workflow.base.instance.ContextInstanceContainer) List(java.util.List) VariableAugmentor(io.automatiko.engine.api.workflow.VariableAugmentor) VariableViolationException(io.automatiko.engine.api.workflow.VariableViolationException) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) ProcessEventSupport(io.automatiko.engine.workflow.base.core.event.ProcessEventSupport) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) Collections(java.util.Collections) Node(io.automatiko.engine.workflow.process.core.Node) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) VariableViolationException(io.automatiko.engine.api.workflow.VariableViolationException) ProcessEventSupport(io.automatiko.engine.workflow.base.core.event.ProcessEventSupport) VariableAugmentor(io.automatiko.engine.api.workflow.VariableAugmentor) ArrayList(java.util.ArrayList) List(java.util.List) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ProcessEventSupport (io.automatiko.engine.workflow.base.core.event.ProcessEventSupport)3 ProcessInstanceImpl (io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl)2 ArrayList (java.util.ArrayList)2 Process (io.automatiko.engine.api.definition.process.Process)1 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)1 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)1 VariableAugmentor (io.automatiko.engine.api.workflow.VariableAugmentor)1 VariableViolationException (io.automatiko.engine.api.workflow.VariableViolationException)1 CorrelationKey (io.automatiko.engine.services.correlation.CorrelationKey)1 StringCorrelationKey (io.automatiko.engine.services.correlation.StringCorrelationKey)1 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)1 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)1 ContextInstanceContainer (io.automatiko.engine.workflow.base.instance.ContextInstanceContainer)1 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)1 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)1 AbstractContextInstance (io.automatiko.engine.workflow.base.instance.context.AbstractContextInstance)1 DefaultWorkItemManager (io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)1 Node (io.automatiko.engine.workflow.process.core.Node)1 WorkflowProcess (io.automatiko.engine.workflow.process.core.WorkflowProcess)1 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)1