Search in sources :

Example 1 with NodeInstanceContent

use of org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent in project jbpm by kiegroup.

the class AbstractProtobufProcessInstanceMarshaller method readNodeInstanceContent.

protected NodeInstanceImpl readNodeInstanceContent(JBPMMessages.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();
            ((RuleSetNodeInstance) nodeInstance).setRuleFlowGroup(_content.getRuleSet().getRuleFlowGroup());
            if (_content.getRuleSet().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getRuleSet().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((RuleSetNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            if (_content.getRuleSet().getMapEntryCount() > 0) {
                Map<String, FactHandle> factInfo = new HashMap<String, FactHandle>();
                for (TextMapEntry entry : _content.getRuleSet().getMapEntryList()) {
                    factInfo.put(entry.getName(), DefaultFactHandle.createFromExternalFormat(entry.getValue()));
                }
                ((RuleSetNodeInstance) nodeInstance).setFactHandles(factInfo);
            }
            break;
        case HUMAN_TASK_NODE:
            nodeInstance = new HumanTaskNodeInstance();
            ((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId(_content.getHumanTask().getWorkItemId());
            if (_content.getHumanTask().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getHumanTask().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((HumanTaskNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case WORK_ITEM_NODE:
            nodeInstance = new WorkItemNodeInstance();
            ((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId(_content.getWorkItem().getWorkItemId());
            if (_content.getWorkItem().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getWorkItem().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((WorkItemNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case SUBPROCESS_NODE:
            nodeInstance = new SubProcessNodeInstance();
            ((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId(_content.getSubProcess().getProcessInstanceId());
            if (_content.getSubProcess().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getSubProcess().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((SubProcessNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case MILESTONE_NODE:
            nodeInstance = new MilestoneNodeInstance();
            if (_content.getMilestone().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _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 ASYNC_EVENT_NODE:
            nodeInstance = new AsyncEventNodeInstance();
            ((AsyncEventNodeInstance) nodeInstance).setEventType(_content.getAsyncEvent().getEventType());
            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 (JBPMMessages.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();
            break;
        case COMPOSITE_CONTEXT_NODE:
            nodeInstance = new CompositeContextNodeInstance();
            if (_content.getComposite().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case DYNAMIC_NODE:
            nodeInstance = new DynamicNodeInstance();
            if (_content.getComposite().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
                    timerInstances.add(_timerId);
                }
                ((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
            }
            break;
        case STATE_NODE:
            nodeInstance = new StateNodeInstance();
            if (_content.getState().getTimerInstanceIdCount() > 0) {
                List<Long> timerInstances = new ArrayList<Long>();
                for (Long _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<Long> timerInstances = new ArrayList<Long>();
                for (Long _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 : AsyncEventNodeInstance(org.jbpm.workflow.instance.node.AsyncEventNodeInstance) JoinInstance(org.jbpm.workflow.instance.node.JoinInstance) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) NodeInstanceContent(org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent) RuleSetNodeInstance(org.jbpm.workflow.instance.node.RuleSetNodeInstance) NodeInstanceImpl(org.jbpm.workflow.instance.impl.NodeInstanceImpl) MilestoneNodeInstance(org.jbpm.workflow.instance.node.MilestoneNodeInstance) StateNodeInstance(org.jbpm.workflow.instance.node.StateNodeInstance) CompositeContextNodeInstance(org.jbpm.workflow.instance.node.CompositeContextNodeInstance) TextMapEntry(org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) EventSubProcessNodeInstance(org.jbpm.workflow.instance.node.EventSubProcessNodeInstance) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ForEachNodeInstance(org.jbpm.workflow.instance.node.ForEachNodeInstance) TimerNodeInstance(org.jbpm.workflow.instance.node.TimerNodeInstance) AsyncEventNodeInstance(org.jbpm.workflow.instance.node.AsyncEventNodeInstance) EventNodeInstance(org.jbpm.workflow.instance.node.EventNodeInstance)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)1 NodeInstanceContent (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent)1 TextMapEntry (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry)1 NodeInstanceImpl (org.jbpm.workflow.instance.impl.NodeInstanceImpl)1 AsyncEventNodeInstance (org.jbpm.workflow.instance.node.AsyncEventNodeInstance)1 CompositeContextNodeInstance (org.jbpm.workflow.instance.node.CompositeContextNodeInstance)1 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)1 EventNodeInstance (org.jbpm.workflow.instance.node.EventNodeInstance)1 EventSubProcessNodeInstance (org.jbpm.workflow.instance.node.EventSubProcessNodeInstance)1 ForEachNodeInstance (org.jbpm.workflow.instance.node.ForEachNodeInstance)1 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)1 JoinInstance (org.jbpm.workflow.instance.node.JoinInstance)1 MilestoneNodeInstance (org.jbpm.workflow.instance.node.MilestoneNodeInstance)1 RuleSetNodeInstance (org.jbpm.workflow.instance.node.RuleSetNodeInstance)1 StateNodeInstance (org.jbpm.workflow.instance.node.StateNodeInstance)1 SubProcessNodeInstance (org.jbpm.workflow.instance.node.SubProcessNodeInstance)1 TimerNodeInstance (org.jbpm.workflow.instance.node.TimerNodeInstance)1 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)1