Search in sources :

Example 1 with NodeInstanceContainer

use of io.automatiko.engine.api.runtime.process.NodeInstanceContainer 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 2 with NodeInstanceContainer

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

the class NodeInstanceImpl method getUniqueId.

public String getUniqueId() {
    String result = "" + getId();
    NodeInstanceContainer parent = getNodeInstanceContainer();
    while (parent instanceof CompositeNodeInstance) {
        CompositeNodeInstance nodeInstance = (CompositeNodeInstance) parent;
        result = nodeInstance.getId() + ":" + result;
        parent = nodeInstance.getNodeInstanceContainer();
    }
    return result;
}
Also used : NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance)

Example 3 with NodeInstanceContainer

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

the class JoinInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("An ActionNode only accepts default incoming connections!");
    }
    triggerTime = new Date();
    final Join join = getJoin();
    switch(join.getType()) {
        case Join.TYPE_XOR:
            triggerCompleted();
            break;
        case Join.TYPE_AND:
            Integer count = (Integer) this.triggers.get(from.getNodeId());
            if (count == null) {
                this.triggers.put(from.getNodeId(), 1);
            } else {
                this.triggers.put(from.getNodeId(), count.intValue() + 1);
            }
            if (checkAllActivated()) {
                decreaseAllTriggers();
                triggerCompleted();
            }
            break;
        case Join.TYPE_DISCRIMINATOR:
            boolean triggerCompleted = triggers.isEmpty();
            triggers.put(from.getNodeId(), new Integer(1));
            if (checkAllActivated()) {
                resetAllTriggers();
            }
            if (triggerCompleted) {
                triggerCompleted();
            }
            break;
        case Join.TYPE_N_OF_M:
            count = (Integer) this.triggers.get(from.getNodeId());
            if (count == null) {
                this.triggers.put(from.getNodeId(), 1);
            } else {
                this.triggers.put(from.getNodeId(), count.intValue() + 1);
            }
            int counter = 0;
            for (final Connection connection : getJoin().getDefaultIncomingConnections()) {
                if (this.triggers.get(connection.getFrom().getId()) != null) {
                    counter++;
                }
            }
            String n = join.getN();
            Integer number = null;
            if (n.startsWith("#{") && n.endsWith("}")) {
                n = n.substring(2, n.length() - 1);
                VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, n);
                if (variableScopeInstance == null) {
                    throw new IllegalArgumentException("Could not find variable " + n + " when executing join.");
                }
                Object value = variableScopeInstance.getVariable(n);
                if (value instanceof Number) {
                    number = ((Number) value).intValue();
                } else {
                    throw new IllegalArgumentException("Variable " + n + " did not return a number when executing join: " + value);
                }
            } else {
                number = Integer.parseInt(n);
            }
            if (counter >= number) {
                resetAllTriggers();
                NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
                cancelRemainingDirectFlows(nodeInstanceContainer, getJoin());
                triggerCompleted();
            }
            break;
        case Join.TYPE_OR:
            NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
            boolean activePathExists = existsActiveDirectFlow(nodeInstanceContainer, getJoin());
            if (!activePathExists) {
                triggerCompleted();
            }
            break;
        default:
            throw new IllegalArgumentException("Illegal join type " + join.getType());
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) VariableScopeInstance(io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance) Connection(io.automatiko.engine.api.definition.process.Connection) Join(io.automatiko.engine.workflow.process.core.node.Join) Date(java.util.Date)

Aggregations

NodeInstanceContainer (io.automatiko.engine.api.runtime.process.NodeInstanceContainer)3 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)2 Date (java.util.Date)2 Connection (io.automatiko.engine.api.definition.process.Connection)1 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 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 Context (io.automatiko.engine.workflow.base.core.Context)1 SwimlaneContext (io.automatiko.engine.workflow.base.core.context.swimlane.SwimlaneContext)1 ExclusiveGroupInstance (io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance)1 Join (io.automatiko.engine.workflow.process.core.node.Join)1 NodeInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl)1 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)1 CompositeNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance)1 DynamicNodeInstance (io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance)1 EventNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)1 EventSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance)1 ForEachNodeInstance (io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance)1 HumanTaskNodeInstance (io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance)1