Search in sources :

Example 6 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class AbstractProcessInstanceMarshaller method writeNodeInstanceContent.

protected void writeNodeInstanceContent(ObjectOutputStream stream, NodeInstance nodeInstance, MarshallerWriteContext context) throws IOException {
    if (nodeInstance instanceof RuleSetNodeInstance) {
        stream.writeShort(PersisterEnums.RULE_SET_NODE_INSTANCE);
        List<Long> timerInstances = ((RuleSetNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            stream.writeInt(timerInstances.size());
            for (Long id : timerInstances) {
                stream.writeLong(id);
            }
        } else {
            stream.writeInt(0);
        }
    } else if (nodeInstance instanceof HumanTaskNodeInstance) {
        stream.writeShort(PersisterEnums.HUMAN_TASK_NODE_INSTANCE);
        stream.writeLong(((HumanTaskNodeInstance) nodeInstance).getWorkItemId());
        List<Long> timerInstances = ((HumanTaskNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            stream.writeInt(timerInstances.size());
            for (Long id : timerInstances) {
                stream.writeLong(id);
            }
        } else {
            stream.writeInt(0);
        }
    } else if (nodeInstance instanceof WorkItemNodeInstance) {
        stream.writeShort(PersisterEnums.WORK_ITEM_NODE_INSTANCE);
        stream.writeLong(((WorkItemNodeInstance) nodeInstance).getWorkItemId());
        List<Long> timerInstances = ((WorkItemNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            stream.writeInt(timerInstances.size());
            for (Long id : timerInstances) {
                stream.writeLong(id);
            }
        } else {
            stream.writeInt(0);
        }
    } else if (nodeInstance instanceof SubProcessNodeInstance) {
        stream.writeShort(PersisterEnums.SUB_PROCESS_NODE_INSTANCE);
        stream.writeLong(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
        List<Long> timerInstances = ((SubProcessNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            stream.writeInt(timerInstances.size());
            for (Long id : timerInstances) {
                stream.writeLong(id);
            }
        } else {
            stream.writeInt(0);
        }
    } else if (nodeInstance instanceof MilestoneNodeInstance) {
        stream.writeShort(PersisterEnums.MILESTONE_NODE_INSTANCE);
        List<Long> timerInstances = ((MilestoneNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            stream.writeInt(timerInstances.size());
            for (Long id : timerInstances) {
                stream.writeLong(id);
            }
        } else {
            stream.writeInt(0);
        }
    } else if (nodeInstance instanceof EventNodeInstance) {
        stream.writeShort(PersisterEnums.EVENT_NODE_INSTANCE);
    } else if (nodeInstance instanceof TimerNodeInstance) {
        stream.writeShort(PersisterEnums.TIMER_NODE_INSTANCE);
        stream.writeLong(((TimerNodeInstance) nodeInstance).getTimerId());
    } else if (nodeInstance instanceof JoinInstance) {
        stream.writeShort(PersisterEnums.JOIN_NODE_INSTANCE);
        Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
        stream.writeInt(triggers.size());
        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) {
            stream.writeLong(key);
            stream.writeInt(triggers.get(key));
        }
    } else if (nodeInstance instanceof StateNodeInstance) {
        stream.writeShort(PersisterEnums.STATE_NODE_INSTANCE);
        List<Long> timerInstances = ((StateNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            stream.writeInt(timerInstances.size());
            for (Long id : timerInstances) {
                stream.writeLong(id);
            }
        } else {
            stream.writeInt(0);
        }
    } else if (nodeInstance instanceof CompositeContextNodeInstance) {
        if (nodeInstance instanceof DynamicNodeInstance) {
            stream.writeShort(PersisterEnums.DYNAMIC_NODE_INSTANCE);
        } else {
            stream.writeShort(PersisterEnums.COMPOSITE_NODE_INSTANCE);
        }
        CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
        List<Long> timerInstances = ((CompositeContextNodeInstance) nodeInstance).getTimerInstances();
        if (timerInstances != null) {
            stream.writeInt(timerInstances.size());
            for (Long id : timerInstances) {
                stream.writeLong(id);
            }
        } else {
            stream.writeInt(0);
        }
        VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
        if (variableScopeInstance == null) {
            stream.writeInt(0);
        } else {
            Map<String, Object> variables = variableScopeInstance.getVariables();
            List<String> keys = new ArrayList<String>(variables.keySet());
            Collections.sort(keys, new Comparator<String>() {

                public int compare(String o1, String o2) {
                    return o1.compareTo(o2);
                }
            });
            stream.writeInt(keys.size());
            for (String key : keys) {
                stream.writeUTF(key);
                stream.writeObject(variables.get(key));
            }
        }
        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() - o2.getId());
            }
        });
        for (NodeInstance subNodeInstance : nodeInstances) {
            stream.writeShort(PersisterEnums.NODE_INSTANCE);
            writeNodeInstance(context, subNodeInstance);
        }
        stream.writeShort(PersisterEnums.END);
        List<ContextInstance> exclusiveGroupInstances = compositeNodeInstance.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
        if (exclusiveGroupInstances == null) {
            stream.writeInt(0);
        } else {
            stream.writeInt(exclusiveGroupInstances.size());
            for (ContextInstance contextInstance : exclusiveGroupInstances) {
                ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
                Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
                stream.writeInt(groupNodeInstances.size());
                for (NodeInstance groupNodeInstance : groupNodeInstances) {
                    stream.writeLong(groupNodeInstance.getId());
                }
            }
        }
    } else if (nodeInstance instanceof ForEachNodeInstance) {
        stream.writeShort(PersisterEnums.FOR_EACH_NODE_INSTANCE);
        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() - o2.getId());
            }
        });
        for (NodeInstance subNodeInstance : nodeInstances) {
            if (subNodeInstance instanceof CompositeContextNodeInstance) {
                stream.writeShort(PersisterEnums.NODE_INSTANCE);
                writeNodeInstance(context, subNodeInstance);
            }
        }
        stream.writeShort(PersisterEnums.END);
    } else {
        throw new IllegalArgumentException("Unknown node instance type: " + nodeInstance);
    }
}
Also used : ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) VariableScopeInstance(org.jbpm.process.instance.context.variable.VariableScopeInstance) ArrayList(java.util.ArrayList) List(java.util.List) ExclusiveGroupInstance(org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance) ContextInstance(org.jbpm.process.instance.ContextInstance) SwimlaneContextInstance(org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Example 7 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class ForEachNodeInstance method getContextInstance.

@Override
public ContextInstance getContextInstance(String contextId) {
    ContextInstance contextInstance = super.getContextInstance(contextId);
    if (contextInstance == null) {
        contextInstance = resolveContextInstance(contextId, TEMP_OUTPUT_VAR);
        setContextInstance(contextId, contextInstance);
    }
    return contextInstance;
}
Also used : ContextInstance(org.jbpm.process.instance.ContextInstance)

Example 8 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class RuleSetNodeInstance method getContextInstance.

@Override
public ContextInstance getContextInstance(Context context) {
    ContextInstanceFactory conf = ContextInstanceFactoryRegistry.INSTANCE.getContextInstanceFactory(context);
    if (conf == null) {
        throw new IllegalArgumentException("Illegal context type (registry not found): " + context.getClass());
    }
    ContextInstance contextInstance = (ContextInstance) conf.getContextInstance(context, this, (ProcessInstance) getProcessInstance());
    if (contextInstance == null) {
        throw new IllegalArgumentException("Illegal context type (instance not found): " + context.getClass());
    }
    return contextInstance;
}
Also used : ContextInstance(org.jbpm.process.instance.ContextInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance) ContextInstanceFactory(org.jbpm.process.instance.impl.ContextInstanceFactory)

Example 9 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class SubProcessNodeInstance method getContextInstance.

@Override
public ContextInstance getContextInstance(Context context) {
    ContextInstanceFactory conf = ContextInstanceFactoryRegistry.INSTANCE.getContextInstanceFactory(context);
    if (conf == null) {
        throw new IllegalArgumentException("Illegal context type (registry not found): " + context.getClass());
    }
    ContextInstance contextInstance = (ContextInstance) conf.getContextInstance(context, this, (ProcessInstance) getProcessInstance());
    if (contextInstance == null) {
        throw new IllegalArgumentException("Illegal context type (instance not found): " + context.getClass());
    }
    return contextInstance;
}
Also used : ContextInstance(org.jbpm.process.instance.ContextInstance) ProcessInstance(org.jbpm.process.instance.ProcessInstance) ContextInstanceFactory(org.jbpm.process.instance.impl.ContextInstanceFactory)

Example 10 with ContextInstance

use of org.jbpm.process.instance.ContextInstance in project jbpm by kiegroup.

the class CompositeContextNodeInstance method getContextInstance.

public ContextInstance getContextInstance(String contextId) {
    ContextInstance contextInstance = this.contextInstances.get(contextId);
    if (contextInstance != null) {
        return contextInstance;
    }
    Context context = getCompositeContextNode().getDefaultContext(contextId);
    if (context != null) {
        contextInstance = getContextInstance(context);
        return contextInstance;
    }
    return null;
}
Also used : Context(org.jbpm.process.core.Context) ContextInstance(org.jbpm.process.instance.ContextInstance)

Aggregations

ContextInstance (org.jbpm.process.instance.ContextInstance)15 HashMap (java.util.HashMap)5 VariableScopeInstance (org.jbpm.process.instance.context.variable.VariableScopeInstance)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ProcessInstance (org.jbpm.process.instance.ProcessInstance)4 ExclusiveGroupInstance (org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance)4 SwimlaneContextInstance (org.jbpm.process.instance.context.swimlane.SwimlaneContextInstance)4 ContextInstanceFactory (org.jbpm.process.instance.impl.ContextInstanceFactory)4 NodeInstance (org.kie.api.runtime.process.NodeInstance)4 Collection (java.util.Collection)2 Comparator (java.util.Comparator)2 List (java.util.List)2 TextMapEntry (org.jbpm.marshalling.impl.JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry)2 Context (org.jbpm.process.core.Context)2 AbstractContextInstance (org.jbpm.process.instance.context.AbstractContextInstance)2 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)2 AsyncEventNodeInstance (org.jbpm.workflow.instance.node.AsyncEventNodeInstance)2 CompositeContextNodeInstance (org.jbpm.workflow.instance.node.CompositeContextNodeInstance)2 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)2