Search in sources :

Example 1 with NodeInstanceContent

use of io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance.NodeInstanceContent in project automatiko-engine by automatiko-io.

the class AbstractProtobufProcessInstanceMarshaller method readNodeInstanceContent.

protected NodeInstanceImpl readNodeInstanceContent(AutomatikoMessages.ProcessInstance.NodeInstance _node, MarshallerReaderContext context, WorkflowProcessInstance processInstance) throws IOException {
    NodeInstanceImpl nodeInstance = null;
    NodeInstanceContent _content = _node.getContent();
    switch(_content.getType()) {
        case RULE_SET_NODE:
            nodeInstance = new RuleSetNodeInstance();
            if (_content.getRuleSet().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getRuleSet().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((RuleSetNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case HUMAN_TASK_NODE:
            nodeInstance = new HumanTaskNodeInstance();
            ((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId(_content.getHumanTask().getWorkItemId());
            ((HumanTaskNodeInstance) nodeInstance).internalSetWorkItem((WorkItemImpl) readHumanTaskWorkItem(processInstance, context, _content.getHumanTask().getWorkitem()));
            if (_content.getHumanTask().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getHumanTask().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((HumanTaskNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            ((WorkItemNodeInstance) nodeInstance).internalSetProcessInstanceId(_content.getHumanTask().getErrorHandlingProcessInstanceId());
            break;
        case WORK_ITEM_NODE:
            nodeInstance = new WorkItemNodeInstance();
            ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId(_content.getWorkItem().getWorkItemId());
            ((WorkItemNodeInstance) nodeInstance).internalSetWorkItem((WorkItemImpl) readWorkItem(processInstance, context, _content.getWorkItem().getWorkitem()));
            if (_content.getWorkItem().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getWorkItem().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((WorkItemNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            ((WorkItemNodeInstance) nodeInstance).internalSetProcessInstanceId(_content.getWorkItem().getErrorHandlingProcessInstanceId());
            break;
        case SUBPROCESS_NODE:
            nodeInstance = new SubProcessNodeInstance();
            ((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId(_content.getSubProcess().getProcessInstanceId());
            if (_content.getSubProcess().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getSubProcess().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((SubProcessNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case SUB_PROCESS_NODE:
            nodeInstance = new LambdaSubProcessNodeInstance();
            ((LambdaSubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId(_content.getSubProcess().getProcessInstanceId());
            ((LambdaSubProcessNodeInstance) nodeInstance).internalSetProcessInstanceName(_content.getSubProcess().getProcessInstanceName());
            if (_content.getSubProcess().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getSubProcess().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((LambdaSubProcessNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case MILESTONE_NODE:
            nodeInstance = new MilestoneNodeInstance();
            if (_content.getMilestone().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getMilestone().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case TIMER_NODE:
            nodeInstance = new TimerNodeInstance();
            ((TimerNodeInstance) nodeInstance).internalSetTimerId(_content.getTimer().getTimerId());
            break;
        case EVENT_NODE:
            nodeInstance = new EventNodeInstance();
            break;
        case JOIN_NODE:
            nodeInstance = new JoinInstance();
            if (_content.getJoin().getTriggerCount() > 0) {
                Map<Long, Integer> triggers = new HashMap<Long, Integer>();
                for (AutomatikoMessages.ProcessInstance.NodeInstanceContent.JoinNode.JoinTrigger _join : _content.getJoin().getTriggerList()) {
                    triggers.put(_join.getNodeId(), _join.getCounter());
                }
                ((JoinInstance) nodeInstance).internalSetTriggers(triggers);
            }
            break;
        case FOR_EACH_NODE:
            nodeInstance = new ForEachNodeInstance();
            ((ForEachNodeInstance) nodeInstance).setInternalSequentialCounter(_content.getForEach().getSequentialCounter());
            break;
        case COMPOSITE_CONTEXT_NODE:
            nodeInstance = new CompositeContextNodeInstance();
            if (_content.getComposite().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getComposite().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case DYNAMIC_NODE:
            nodeInstance = new DynamicNodeInstance();
            if (_content.getComposite().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getComposite().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case STATE_NODE:
            nodeInstance = new StateNodeInstance();
            if (_content.getState().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getState().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case EVENT_SUBPROCESS_NODE:
            nodeInstance = new EventSubProcessNodeInstance();
            if (_content.getComposite().getTimerInstanceIdCount() > 0) {
                List<String> timerInstances = new ArrayList<>();
                for (String _timerId : _content.getComposite().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        default:
            throw new IllegalArgumentException("Unknown node type: " + _content.getType());
    }
    return nodeInstance;
}
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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) NodeInstanceContent(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance.NodeInstanceContent) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) NodeInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) 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) 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) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Aggregations

ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)1 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 NodeInstanceContent (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.ProcessInstance.NodeInstanceContent)1 NodeInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceImpl)1 CompositeContextNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance)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 JoinInstance (io.automatiko.engine.workflow.process.instance.node.JoinInstance)1 LambdaSubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance)1 MilestoneNodeInstance (io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance)1 RuleSetNodeInstance (io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance)1 StateNodeInstance (io.automatiko.engine.workflow.process.instance.node.StateNodeInstance)1 SubProcessNodeInstance (io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance)1 TimerNodeInstance (io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance)1 WorkItemNodeInstance (io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1