Search in sources :

Example 1 with NodeInstance

use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.

the class AbstractProtobufProcessInstanceMarshaller method writeNodeInstanceContent.

protected AutomatikoMessages.ProcessInstance.NodeInstanceContent writeNodeInstanceContent(AutomatikoMessages.ProcessInstance.NodeInstance.Builder _node, NodeInstance nodeInstance, MarshallerWriteContext context) throws IOException {
    AutomatikoMessages.ProcessInstance.NodeInstanceContent.Builder _content = null;
    if (nodeInstance instanceof RuleSetNodeInstance) {
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.RULE_SET_NODE);
        List<String> timerInstances = ((RuleSetNodeInstance) nodeInstance).getTimerInstances();
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.Builder _ruleSet = AutomatikoMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.newBuilder();
        if (timerInstances != null) {
            for (String id : timerInstances) {
                _ruleSet.addTimerInstanceId(id);
            }
        }
        _content.setRuleSet(_ruleSet.build());
    } else if (nodeInstance instanceof HumanTaskNodeInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.HumanTaskNode.Builder _task = AutomatikoMessages.ProcessInstance.NodeInstanceContent.HumanTaskNode.newBuilder().setWorkItemId(((HumanTaskNodeInstance) nodeInstance).getWorkItemId()).setWorkitem(writeHumanTaskWorkItem(context, (HumanTaskWorkItem) ((HumanTaskNodeInstance) nodeInstance).getWorkItem()));
        List<String> timerInstances = ((HumanTaskNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            for (String id : timerInstances) {
                _task.addTimerInstanceId(id);
            }
        }
        if (((WorkItemNodeInstance) nodeInstance).getExceptionHandlingProcessInstanceId() != null) {
            _task.setErrorHandlingProcessInstanceId(((HumanTaskNodeInstance) nodeInstance).getExceptionHandlingProcessInstanceId());
        }
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.HUMAN_TASK_NODE).setHumanTask(_task.build());
    } else if (nodeInstance instanceof WorkItemNodeInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.WorkItemNode.Builder _wi = AutomatikoMessages.ProcessInstance.NodeInstanceContent.WorkItemNode.newBuilder().setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItemId()).setWorkitem(writeWorkItem(context, ((WorkItemNodeInstance) nodeInstance).getWorkItem()));
        List<String> timerInstances = ((WorkItemNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            for (String id : timerInstances) {
                _wi.addTimerInstanceId(id);
            }
        }
        if (((WorkItemNodeInstance) nodeInstance).getExceptionHandlingProcessInstanceId() != null) {
            _wi.setErrorHandlingProcessInstanceId(((WorkItemNodeInstance) nodeInstance).getExceptionHandlingProcessInstanceId());
        }
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.WORK_ITEM_NODE).setWorkItem(_wi.build());
    } else if (nodeInstance instanceof LambdaSubProcessNodeInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.SubProcessNode.Builder _sp = AutomatikoMessages.ProcessInstance.NodeInstanceContent.SubProcessNode.newBuilder().setProcessInstanceId(((LambdaSubProcessNodeInstance) nodeInstance).getProcessInstanceId()).setProcessInstanceName(((LambdaSubProcessNodeInstance) nodeInstance).getProcessInstanceName());
        List<String> timerInstances = ((LambdaSubProcessNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            for (String id : timerInstances) {
                _sp.addTimerInstanceId(id);
            }
        }
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.SUB_PROCESS_NODE).setSubProcess(_sp.build());
    } else if (nodeInstance instanceof SubProcessNodeInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.SubProcessNode.Builder _sp = AutomatikoMessages.ProcessInstance.NodeInstanceContent.SubProcessNode.newBuilder().setProcessInstanceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
        List<String> timerInstances = ((SubProcessNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            for (String id : timerInstances) {
                _sp.addTimerInstanceId(id);
            }
        }
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.SUBPROCESS_NODE).setSubProcess(_sp.build());
    } else if (nodeInstance instanceof MilestoneNodeInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.MilestoneNode.Builder _ms = AutomatikoMessages.ProcessInstance.NodeInstanceContent.MilestoneNode.newBuilder();
        List<String> timerInstances = ((MilestoneNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            for (String id : timerInstances) {
                _ms.addTimerInstanceId(id);
            }
        }
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.MILESTONE_NODE).setMilestone(_ms.build());
    } else if (nodeInstance instanceof EventNodeInstance) {
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.EVENT_NODE);
    } else if (nodeInstance instanceof TimerNodeInstance) {
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.TIMER_NODE).setTimer(AutomatikoMessages.ProcessInstance.NodeInstanceContent.TimerNode.newBuilder().setTimerId(((TimerNodeInstance) nodeInstance).getTimerId()).build());
    } else if (nodeInstance instanceof JoinInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.JoinNode.Builder _join = AutomatikoMessages.ProcessInstance.NodeInstanceContent.JoinNode.newBuilder();
        Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
        List<Long> keys = new ArrayList<Long>(triggers.keySet());
        Collections.sort(keys, new Comparator<Long>() {

            public int compare(Long o1, Long o2) {
                return o1.compareTo(o2);
            }
        });
        for (Long key : keys) {
            _join.addTrigger(AutomatikoMessages.ProcessInstance.NodeInstanceContent.JoinNode.JoinTrigger.newBuilder().setNodeId(key).setCounter(triggers.get(key)).build());
        }
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.JOIN_NODE).setJoin(_join.build());
    } else if (nodeInstance instanceof StateNodeInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.StateNode.Builder _state = AutomatikoMessages.ProcessInstance.NodeInstanceContent.StateNode.newBuilder();
        List<String> timerInstances = ((StateNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            for (String id : timerInstances) {
                _state.addTimerInstanceId(id);
            }
        }
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.STATE_NODE).setState(_state.build());
    } else if (nodeInstance instanceof ForEachNodeInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.ForEachNode.Builder _foreach = AutomatikoMessages.ProcessInstance.NodeInstanceContent.ForEachNode.newBuilder();
        ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance;
        List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(forEachNodeInstance.getNodeInstances());
        Collections.sort(nodeInstances, new Comparator<NodeInstance>() {

            public int compare(NodeInstance o1, NodeInstance o2) {
                return (int) (o1.getId().compareTo(o2.getId()));
            }
        });
        for (NodeInstance subNodeInstance : nodeInstances) {
            if (subNodeInstance instanceof CompositeContextNodeInstance) {
                _foreach.addNodeInstance(writeNodeInstance(context, subNodeInstance));
            }
        }
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) forEachNodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
        if (variableScopeInstance != null) {
            List<Map.Entry<String, Object>> variables = new ArrayList<Map.Entry<String, Object>>(variableScopeInstance.getVariables().entrySet());
            Collections.sort(variables, new Comparator<Map.Entry<String, Object>>() {

                public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
                    return o1.getKey().compareTo(o2.getKey());
                }
            });
            for (Map.Entry<String, Object> variable : variables) {
                _foreach.addVariable(ProtobufProcessMarshaller.marshallVariable(context, variable.getKey(), variable.getValue(), false));
            }
        }
        List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(forEachNodeInstance.getIterationLevels().entrySet());
        Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {

            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o1.getKey().compareTo(o2.getKey());
            }
        });
        for (Map.Entry<String, Integer> level : iterationlevels) {
            if (level.getKey() != null && level.getValue() != null) {
                _foreach.addIterationLevels(AutomatikoMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
            }
        }
        _foreach.setSequentialCounter(forEachNodeInstance.getSequentialCounter());
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.FOR_EACH_NODE).setForEach(_foreach.build());
    } else if (nodeInstance instanceof CompositeContextNodeInstance) {
        AutomatikoMessages.ProcessInstance.NodeInstanceContent.CompositeContextNode.Builder _composite = AutomatikoMessages.ProcessInstance.NodeInstanceContent.CompositeContextNode.newBuilder();
        AutomatikoMessages.ProcessInstance.NodeInstanceType _type = null;
        if (nodeInstance instanceof DynamicNodeInstance) {
            _type = AutomatikoMessages.ProcessInstance.NodeInstanceType.DYNAMIC_NODE;
        } else if (nodeInstance instanceof EventSubProcessNodeInstance) {
            _type = AutomatikoMessages.ProcessInstance.NodeInstanceType.EVENT_SUBPROCESS_NODE;
        } else {
            _type = AutomatikoMessages.ProcessInstance.NodeInstanceType.COMPOSITE_CONTEXT_NODE;
        }
        CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
        List<String> timerInstances = ((CompositeContextNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            for (String id : timerInstances) {
                _composite.addTimerInstanceId(id);
            }
        }
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
        if (variableScopeInstance != null) {
            List<Map.Entry<String, Object>> variables = new ArrayList<Map.Entry<String, Object>>(variableScopeInstance.getVariables().entrySet());
            Collections.sort(variables, new Comparator<Map.Entry<String, Object>>() {

                public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
                    return o1.getKey().compareTo(o2.getKey());
                }
            });
            for (Map.Entry<String, Object> variable : variables) {
                _composite.addVariable(ProtobufProcessMarshaller.marshallVariable(context, variable.getKey(), variable.getValue(), true));
            }
        }
        List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(compositeNodeInstance.getIterationLevels().entrySet());
        Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {

            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o1.getKey().compareTo(o2.getKey());
            }
        });
        for (Map.Entry<String, Integer> level : iterationlevels) {
            if (level.getKey() != null && level.getValue() != null) {
                _composite.addIterationLevels(AutomatikoMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
            }
        }
        List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(compositeNodeInstance.getNodeInstances());
        Collections.sort(nodeInstances, new Comparator<NodeInstance>() {

            public int compare(NodeInstance o1, NodeInstance o2) {
                return (int) (o1.getId().compareTo(o2.getId()));
            }
        });
        for (NodeInstance subNodeInstance : nodeInstances) {
            _composite.addNodeInstance(writeNodeInstance(context, subNodeInstance));
        }
        List<ContextInstance> exclusiveGroupInstances = compositeNodeInstance.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
        if (exclusiveGroupInstances != null) {
            for (ContextInstance contextInstance : exclusiveGroupInstances) {
                AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance.Builder _excl = AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance.newBuilder();
                ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
                Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
                for (NodeInstance groupNodeInstance : groupNodeInstances) {
                    _excl.addGroupNodeInstanceId(groupNodeInstance.getId());
                }
                _composite.addExclusiveGroup(_excl.build());
            }
        }
        _content = AutomatikoMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(_type).setComposite(_composite.build());
    } else {
        throw new IllegalArgumentException("Unknown node instance type: " + nodeInstance);
    }
    return _content.build();
}
Also used : JoinInstance(io.automatiko.engine.workflow.process.instance.node.JoinInstance) DynamicNodeInstance(io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) ArrayList(java.util.ArrayList) NodeInstanceType(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance.NodeInstanceType) Comparator(java.util.Comparator) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) List(java.util.List) ArrayList(java.util.ArrayList) NodeInstanceContent(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance.NodeInstanceContent) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) StateNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateNodeInstance) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) Collection(java.util.Collection) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) StateNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateNodeInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) SubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) DynamicNodeInstance(io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance) Map(java.util.Map) HashMap(java.util.HashMap) Entry(java.util.Map.Entry) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) SubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Example 2 with NodeInstance

use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.

the class AbstractProtobufProcessInstanceMarshaller method readProcessInstance.

// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
    AutomatikoMessages.ProcessInstance _instance = (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance) context.parameterObject;
    if (_instance == null) {
        // try to parse from the stream
        ExtensionRegistry registry = PersisterHelper.buildRegistry(context, null);
        Header _header;
        try {
            _header = PersisterHelper.readFromStreamWithHeaderPreloaded(context, registry);
        } catch (ClassNotFoundException e) {
            // Java 5 does not accept [new IOException(String, Throwable)]
            IOException ioe = new IOException("Error deserializing process instance.");
            ioe.initCause(e);
            throw ioe;
        }
        _instance = AutomatikoMessages.ProcessInstance.parseFrom(_header.getPayload(), registry);
    }
    WorkflowProcessInstanceImpl processInstance = createProcessInstance();
    processInstance.setId(_instance.getId());
    String processId = _instance.getProcessId();
    processInstance.setProcessId(processId);
    String processXml = _instance.getProcessXml();
    Process process = null;
    if (processXml != null && processXml.trim().length() > 0) {
        processInstance.setProcessXml(processXml);
        process = processInstance.getProcess();
    } else {
        process = context.processes.get(processId);
        if (process == null) {
            throw new RuntimeException("Could not find process " + processId + " when restoring process instance " + processInstance.getId());
        }
        processInstance.setProcess(process);
    }
    processInstance.setDescription(_instance.getDescription());
    processInstance.internalSetState(_instance.getState());
    processInstance.setParentProcessInstanceId(_instance.getParentProcessInstanceId());
    processInstance.setRootProcessInstanceId(_instance.getRootProcessInstanceId());
    processInstance.setRootProcessId(_instance.getRootProcessId());
    processInstance.setSignalCompletion(_instance.getSignalCompletion());
    processInstance.setInitiator(_instance.getInitiator());
    processInstance.setCorrelationKey(_instance.getCorrelationKey());
    processInstance.setStartDate(new Date(_instance.getStartDate()));
    processInstance.internalSetSlaCompliance(_instance.getSlaCompliance());
    if (_instance.getSlaDueDate() > 0) {
        processInstance.internalSetSlaDueDate(new Date(_instance.getSlaDueDate()));
    }
    processInstance.internalSetSlaTimerId(_instance.getSlaTimerId());
    processInstance.setProcessRuntime(context.getProcessRuntime());
    List<ExecutionsErrorInfo> errors = new ArrayList<>();
    for (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance.Error error : _instance.getErrorsList()) {
        errors.add(new ExecutionsErrorInfo(error.getErrorNodeId(), error.getErrorId(), error.getErrorMessage(), error.getErrorDetails()));
    }
    processInstance.internalSetExecutionErrors(errors);
    processInstance.setReferenceId(_instance.getReferenceId());
    processInstance.internalSetReferenceFromRoot(_instance.getReferenceFromRoot());
    for (String completedNodeId : _instance.getCompletedNodeIdsList()) {
        processInstance.addCompletedNodeId(completedNodeId);
    }
    if (_instance.getChildrenCount() > 0) {
        _instance.getChildrenList().forEach(child -> processInstance.addChildren(child.getProcessId(), child.getIdsList()));
    }
    if (_instance.getTagsCount() > 0) {
        _instance.getTagsList().forEach(tag -> processInstance.internalAddTag(tag.getId(), tag.getValue()));
    }
    if (_instance.getSwimlaneContextCount() > 0) {
        Context swimlaneContext = ((io.automatiko.engine.workflow.base.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
        SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
        for (AutomatikoMessages.ProcessInstance.SwimlaneContextInstance _swimlane : _instance.getSwimlaneContextList()) {
            swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
        }
    }
    for (AutomatikoMessages.ProcessInstance.NodeInstance _node : _instance.getNodeInstanceList()) {
        context.parameterObject = _node;
        readNodeInstance(context, processInstance, processInstance);
    }
    if (processInstance.getState() == ProcessInstance.STATE_ACTIVE || processInstance.getState() == ProcessInstance.STATE_ERROR) {
        for (AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance _excl : _instance.getExclusiveGroupList()) {
            ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
            processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
            for (String nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
                NodeInstance nodeInstance = ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) processInstance).getNodeInstance(nodeInstanceId, true);
                if (nodeInstance == null) {
                    throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
                }
                exclusiveGroupInstance.addNodeInstance(nodeInstance);
            }
        }
    }
    readVariableScope(context, process, processInstance, _instance);
    if (_instance.getIterationLevelsCount() > 0) {
        for (AutomatikoMessages.IterationLevel _level : _instance.getIterationLevelsList()) {
            processInstance.getIterationLevels().put(_level.getId(), _level.getLevel());
        }
    }
    return processInstance;
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) Process(io.automatiko.engine.api.definition.process.Process) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) Context(io.automatiko.engine.workflow.base.core.Context) SwimlaneContext(io.automatiko.engine.workflow.base.core.context.swimlane.SwimlaneContext) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) IOException(java.io.IOException) Date(java.util.Date) Header(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) StateNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateNodeInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) SubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) DynamicNodeInstance(io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Example 3 with NodeInstance

use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.

the class AbstractProtobufProcessInstanceMarshaller method readNodeInstance.

public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer, WorkflowProcessInstance processInstance) throws IOException {
    AutomatikoMessages.ProcessInstance.NodeInstance _node = (AutomatikoMessages.ProcessInstance.NodeInstance) context.parameterObject;
    NodeInstanceImpl nodeInstance = readNodeInstanceContent(_node, context, processInstance);
    nodeInstance.setNodeId(_node.getNodeId());
    nodeInstance.setId(_node.getId());
    nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
    nodeInstance.setProcessInstance((io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) processInstance);
    nodeInstance.setLevel(_node.getLevel() == 0 ? 1 : _node.getLevel());
    nodeInstance.internalSetTriggerTime(new Date(_node.getTriggerDate()));
    nodeInstance.internalSetSlaCompliance(_node.getSlaCompliance());
    if (_node.getSlaDueDate() > 0) {
        nodeInstance.internalSetSlaDueDate(new Date(_node.getSlaDueDate()));
    }
    nodeInstance.internalSetSlaTimerId(_node.getSlaTimerId());
    nodeInstance.internalSetRetryJobId(_node.getRetryJobId());
    nodeInstance.internalSetRetryAttempts(_node.getRetryAttempts());
    switch(_node.getContent().getType()) {
        case COMPOSITE_CONTEXT_NODE:
        case DYNAMIC_NODE:
            if (_node.getContent().getComposite().getVariableCount() > 0) {
                Context variableScope = ((io.automatiko.engine.workflow.base.core.Process) ((io.automatiko.engine.workflow.base.instance.ProcessInstance) processInstance).getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
                for (AutomatikoMessages.Variable _variable : _node.getContent().getComposite().getVariableList()) {
                    try {
                        Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
                        variableScopeInstance.internalSetVariable(_variable.getName(), _value);
                    } catch (ClassNotFoundException e) {
                        throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
                    }
                }
            }
            if (_node.getContent().getComposite().getIterationLevelsCount() > 0) {
                for (AutomatikoMessages.IterationLevel _level : _node.getContent().getComposite().getIterationLevelsList()) {
                    ((CompositeContextNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
                }
            }
            for (AutomatikoMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
                context.parameterObject = _instance;
                readNodeInstance(context, (CompositeContextNodeInstance) nodeInstance, processInstance);
            }
            for (AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance _excl : _node.getContent().getComposite().getExclusiveGroupList()) {
                ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
                ((CompositeContextNodeInstance) nodeInstance).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
                for (String nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
                    NodeInstance groupNodeInstance = ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) processInstance).getNodeInstance(nodeInstanceId, true);
                    if (groupNodeInstance == null) {
                        throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
                    }
                    exclusiveGroupInstance.addNodeInstance(groupNodeInstance);
                }
            }
            break;
        case FOR_EACH_NODE:
            for (AutomatikoMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getForEach().getNodeInstanceList()) {
                context.parameterObject = _instance;
                readNodeInstance(context, (ForEachNodeInstance) nodeInstance, processInstance);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((ForEachNodeInstance) nodeInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
                for (AutomatikoMessages.Variable _variable : _node.getContent().getForEach().getVariableList()) {
                    try {
                        Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
                        variableScopeInstance.internalSetVariable(_variable.getName(), _value);
                    } catch (ClassNotFoundException e) {
                        throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
                    }
                }
                if (_node.getContent().getForEach().getIterationLevelsCount() > 0) {
                    for (AutomatikoMessages.IterationLevel _level : _node.getContent().getForEach().getIterationLevelsList()) {
                        ((ForEachNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
                    }
                }
            }
            break;
        case EVENT_SUBPROCESS_NODE:
            for (AutomatikoMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
                context.parameterObject = _instance;
                readNodeInstance(context, (EventSubProcessNodeInstance) nodeInstance, processInstance);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((EventSubProcessNodeInstance) nodeInstance).getContextInstance(VariableScope.VARIABLE_SCOPE);
                for (AutomatikoMessages.Variable _variable : _node.getContent().getComposite().getVariableList()) {
                    try {
                        Object _value = ProtobufProcessMarshaller.unmarshallVariableValue(context, _variable);
                        variableScopeInstance.internalSetVariable(_variable.getName(), _value);
                    } catch (ClassNotFoundException e) {
                        throw new IllegalArgumentException("Could not reload variable " + _variable.getName());
                    }
                }
            }
            break;
        default:
    }
    return nodeInstance;
}
Also used : NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) Process(io.automatiko.engine.api.definition.process.Process) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) NodeInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl) Context(io.automatiko.engine.workflow.base.core.Context) SwimlaneContext(io.automatiko.engine.workflow.base.core.context.swimlane.SwimlaneContext) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) Date(java.util.Date) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) StateNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateNodeInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) SubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) DynamicNodeInstance(io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Example 4 with NodeInstance

use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.

the class VariableUtil method resolveVariable.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static String resolveVariable(String s, NodeInstance nodeInstance) {
    if (s == null) {
        return null;
    }
    Map<String, String> replacements = new HashMap<String, String>();
    Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(s);
    while (matcher.find()) {
        String paramName = matcher.group(1);
        String replacementKey = paramName;
        String defaultValue = "";
        if (paramName.contains(":")) {
            String[] items = paramName.split(":");
            paramName = items[0];
            defaultValue = items[1];
        }
        if (replacements.get(paramName) == null) {
            VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).resolveContextInstance(VariableScope.VARIABLE_SCOPE, paramName);
            if (variableScopeInstance != null) {
                Object variableValue = variableScopeInstance.getVariable(paramName);
                String variableValueString = variableValue == null ? defaultValue : variableValue.toString();
                replacements.put(replacementKey, variableValueString);
            } else {
                try {
                    ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) nodeInstance.getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
                    Object variableValue = evaluator.evaluate(paramName, new NodeInstanceResolverFactory((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance));
                    String variableValueString = variableValue == null ? defaultValue : variableValue.toString();
                    replacements.put(replacementKey, variableValueString);
                } catch (Throwable t) {
                }
            }
        }
    }
    for (Map.Entry<String, String> replacement : replacements.entrySet()) {
        s = s.replace("#{" + replacement.getKey() + "}", replacement.getValue());
    }
    return s;
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ExpressionEvaluator(io.automatiko.engine.api.expression.ExpressionEvaluator) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) NodeInstanceResolverFactory(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with NodeInstance

use of io.automatiko.engine.api.runtime.process.NodeInstance in project automatiko-engine by automatiko-io.

the class CancelNodeInstanceAction method execute.

public void execute(ProcessContext context) throws Exception {
    WorkflowProcessInstance pi = context.getNodeInstance().getProcessInstance();
    NodeInstance nodeInstance = findNodeByUniqueId(pi.getNodeInstances(), attachedToNodeId);
    if (nodeInstance != null) {
        ((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).cancel();
    }
}
Also used : NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Aggregations

NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)26 ArrayList (java.util.ArrayList)20 List (java.util.List)15 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)14 DelayedExecution (io.automatiko.engine.api.event.process.DelayedExecution)9 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)9 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)9 ProcessNodeInstanceFailedEvent (io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent)9 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)9 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)9 ProcessSignaledEvent (io.automatiko.engine.api.event.process.ProcessSignaledEvent)9 ProcessStartedEvent (io.automatiko.engine.api.event.process.ProcessStartedEvent)9 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)9 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)9 SLAViolatedEvent (io.automatiko.engine.api.event.process.SLAViolatedEvent)9 ProcessRuntime (io.automatiko.engine.api.runtime.process.ProcessRuntime)9 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)9 UnitOfWorkManager (io.automatiko.engine.api.uow.UnitOfWorkManager)9 WorkUnit (io.automatiko.engine.api.uow.WorkUnit)9 Transition (io.automatiko.engine.api.workflow.workitem.Transition)9