use of org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance in project jbpm by kiegroup.
the class SplitInstance method executeStrategy.
protected void executeStrategy(Split split, String type) {
// TODO make different strategies for each type
switch(split.getType()) {
case Split.TYPE_AND:
triggerCompleted(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, true);
break;
case Split.TYPE_XOR:
List<Connection> outgoing = split.getDefaultOutgoingConnections();
int priority = Integer.MAX_VALUE;
Connection selected = null;
for (final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
final Connection connection = (Connection) iterator.next();
ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint(connection);
if (constraint != null && constraint.getPriority() < priority && !constraint.isDefault()) {
try {
if (constraint.evaluate(this, connection, constraint)) {
selected = connection;
priority = constraint.getPriority();
}
} catch (RuntimeException e) {
throw new RuntimeException("Exception when trying to evaluate constraint " + constraint.getName() + " in split " + split.getName(), e);
}
}
}
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
if (selected == null) {
for (final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
final Connection connection = (Connection) iterator.next();
if (split.isDefault(connection)) {
selected = connection;
break;
}
}
}
if (selected == null) {
throw new IllegalArgumentException("XOR split could not find at least one valid outgoing connection for split " + getSplit().getName());
}
if (!hasLoop(selected.getTo(), split)) {
setLevel(1);
((NodeInstanceContainer) getNodeInstanceContainer()).setCurrentLevel(1);
}
triggerConnection(selected);
break;
case Split.TYPE_OR:
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
outgoing = split.getDefaultOutgoingConnections();
boolean found = false;
List<NodeInstanceTrigger> nodeInstances = new ArrayList<NodeInstanceTrigger>();
List<Connection> outgoingCopy = new ArrayList<Connection>(outgoing);
while (!outgoingCopy.isEmpty()) {
priority = Integer.MAX_VALUE;
Connection selectedConnection = null;
ConstraintEvaluator selectedConstraint = null;
for (final Iterator<Connection> iterator = outgoingCopy.iterator(); iterator.hasNext(); ) {
final Connection connection = (Connection) iterator.next();
ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint(connection);
if (constraint != null && constraint.getPriority() < priority && !constraint.isDefault()) {
priority = constraint.getPriority();
selectedConnection = connection;
selectedConstraint = constraint;
}
}
if (selectedConstraint == null) {
break;
}
if (selectedConstraint.evaluate(this, selectedConnection, selectedConstraint)) {
nodeInstances.add(new NodeInstanceTrigger(followConnection(selectedConnection), selectedConnection.getToType()));
found = true;
}
outgoingCopy.remove(selectedConnection);
}
for (NodeInstanceTrigger nodeInstance : nodeInstances) {
// stop if this process instance has been aborted / completed
if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) {
return;
}
triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType());
}
if (!found) {
for (final Iterator<Connection> iterator = outgoing.iterator(); iterator.hasNext(); ) {
final Connection connection = (Connection) iterator.next();
ConstraintEvaluator constraint = (ConstraintEvaluator) split.getConstraint(connection);
if (constraint != null && constraint.isDefault() || split.isDefault(connection)) {
triggerConnection(connection);
found = true;
break;
}
}
}
if (!found) {
throw new IllegalArgumentException("OR split could not find at least one valid outgoing connection for split " + getSplit().getName());
}
break;
case Split.TYPE_XAND:
((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
Node node = getNode();
List<Connection> connections = null;
if (node != null) {
connections = node.getOutgoingConnections(type);
}
if (connections == null || connections.isEmpty()) {
((org.jbpm.workflow.instance.NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, type);
} else {
ExclusiveGroupInstance groupInstance = new ExclusiveGroupInstance();
org.kie.api.runtime.process.NodeInstanceContainer parent = getNodeInstanceContainer();
if (parent instanceof ContextInstanceContainer) {
((ContextInstanceContainer) parent).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, groupInstance);
} else {
throw new IllegalArgumentException("An Exclusive AND is only possible if the parent is a context instance container");
}
Map<org.jbpm.workflow.instance.NodeInstance, String> nodeInstancesMap = new HashMap<org.jbpm.workflow.instance.NodeInstance, String>();
for (Connection connection : connections) {
nodeInstancesMap.put(followConnection(connection), connection.getToType());
}
for (NodeInstance nodeInstance : nodeInstancesMap.keySet()) {
groupInstance.addNodeInstance(nodeInstance);
}
for (Map.Entry<org.jbpm.workflow.instance.NodeInstance, String> entry : nodeInstancesMap.entrySet()) {
// stop if this process instance has been aborted / completed
if (getProcessInstance().getState() != ProcessInstance.STATE_ACTIVE) {
return;
}
boolean hidden = false;
if (getNode().getMetaData().get("hidden") != null) {
hidden = true;
}
InternalKnowledgeRuntime kruntime = getProcessInstance().getKnowledgeRuntime();
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireBeforeNodeLeft(this, kruntime);
}
((org.jbpm.workflow.instance.NodeInstance) entry.getKey()).trigger(this, entry.getValue());
if (!hidden) {
((InternalProcessRuntime) kruntime.getProcessRuntime()).getProcessEventSupport().fireAfterNodeLeft(this, kruntime);
}
}
}
break;
default:
throw new IllegalArgumentException("Illegal split type " + split.getType());
}
}
use of org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance in project jbpm by kiegroup.
the class AbstractProcessInstanceMarshaller method writeProcessInstance.
// Output methods
public Object writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException {
WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
ObjectOutputStream stream = context.stream;
stream.writeLong(workFlow.getId());
stream.writeUTF(workFlow.getProcessId());
stream.writeInt(workFlow.getState());
stream.writeLong(workFlow.getNodeInstanceCounter());
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
if (swimlaneContextInstance != null) {
Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
stream.writeInt(swimlaneActors.size());
for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
stream.writeUTF(entry.getKey());
stream.writeUTF(entry.getValue());
}
} else {
stream.writeInt(0);
}
List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(workFlow.getNodeInstances());
Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
public int compare(NodeInstance o1, NodeInstance o2) {
return (int) (o1.getId() - o2.getId());
}
});
for (NodeInstance nodeInstance : nodeInstances) {
stream.writeShort(PersisterEnums.NODE_INSTANCE);
writeNodeInstance(context, nodeInstance);
}
stream.writeShort(PersisterEnums.END);
List<ContextInstance> exclusiveGroupInstances = workFlow.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 nodeInstance : groupNodeInstances) {
stream.writeLong(nodeInstance.getId());
}
}
}
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow.getContextInstance(VariableScope.VARIABLE_SCOPE);
Map<String, Object> variables = variableScopeInstance.getVariables();
List<String> keys = new ArrayList<String>(variables.keySet());
Collection<Object> values = variables.values();
Collections.sort(keys, new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareTo(o2);
}
});
// Process Variables
// - Number of non null Variables = nonnullvariables.size()
// For Each Variable
// - Variable Key
// - Marshalling Strategy Index
// - Marshalled Object
Collection<Object> notNullValues = new ArrayList<Object>();
for (Object value : values) {
if (value != null) {
notNullValues.add(value);
}
}
stream.writeInt(notNullValues.size());
for (String key : keys) {
Object object = variables.get(key);
if (object != null) {
stream.writeUTF(key);
// New marshalling algorithm when using strategies
int useNewMarshallingStrategyAlgorithm = -2;
stream.writeInt(useNewMarshallingStrategyAlgorithm);
// Choose first strategy that accepts the object (what was always done)
ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(object);
stream.writeUTF(strategy.getClass().getName());
strategy.write(stream, object);
}
}
return null;
}
use of org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance 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);
}
}
use of org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method readNodeInstance.
public NodeInstance readNodeInstance(MarshallerReaderContext context, NodeInstanceContainer nodeInstanceContainer, WorkflowProcessInstance processInstance) throws IOException {
JBPMMessages.ProcessInstance.NodeInstance _node = (JBPMMessages.ProcessInstance.NodeInstance) context.parameterObject;
NodeInstanceImpl nodeInstance = readNodeInstanceContent(_node, context, processInstance);
nodeInstance.setNodeId(_node.getNodeId());
nodeInstance.setId(_node.getId());
nodeInstance.setNodeInstanceContainer(nodeInstanceContainer);
nodeInstance.setProcessInstance((org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance);
nodeInstance.setLevel(_node.getLevel() == 0 ? 1 : _node.getLevel());
nodeInstance.internalSetSlaCompliance(_node.getSlaCompliance());
if (_node.getSlaDueDate() > 0) {
nodeInstance.internalSetSlaDueDate(new Date(_node.getSlaDueDate()));
}
nodeInstance.internalSetSlaTimerId(_node.getSlaTimerId());
switch(_node.getContent().getType()) {
case COMPOSITE_CONTEXT_NODE:
case DYNAMIC_NODE:
if (_node.getContent().getComposite().getVariableCount() > 0) {
Context variableScope = ((org.jbpm.process.core.Process) ((org.jbpm.process.instance.ProcessInstance) processInstance).getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) ((CompositeContextNodeInstance) nodeInstance).getContextInstance(variableScope);
for (JBPMMessages.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 (JBPMMessages.IterationLevel _level : _node.getContent().getComposite().getIterationLevelsList()) {
((CompositeContextNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
for (JBPMMessages.ProcessInstance.NodeInstance _instance : _node.getContent().getComposite().getNodeInstanceList()) {
context.parameterObject = _instance;
readNodeInstance(context, (CompositeContextNodeInstance) nodeInstance, processInstance);
}
for (JBPMMessages.ProcessInstance.ExclusiveGroupInstance _excl : _node.getContent().getComposite().getExclusiveGroupList()) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
((CompositeContextNodeInstance) nodeInstance).addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
for (Long nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
NodeInstance groupNodeInstance = ((org.jbpm.workflow.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 (JBPMMessages.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 (JBPMMessages.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 (JBPMMessages.IterationLevel _level : _node.getContent().getForEach().getIterationLevelsList()) {
((ForEachNodeInstance) nodeInstance).getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
}
break;
case EVENT_SUBPROCESS_NODE:
for (JBPMMessages.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 (JBPMMessages.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;
}
use of org.jbpm.process.instance.context.exclusive.ExclusiveGroupInstance in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method readProcessInstance.
// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
InternalKnowledgeBase ruleBase = context.kBase;
InternalWorkingMemory wm = context.wm;
JBPMMessages.ProcessInstance _instance = (org.jbpm.marshalling.impl.JBPMMessages.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 = JBPMMessages.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 = ruleBase.getProcess(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.setState(_instance.getState());
processInstance.setParentProcessInstanceId(_instance.getParentProcessInstanceId());
processInstance.setSignalCompletion(_instance.getSignalCompletion());
processInstance.setDeploymentId(_instance.getDeploymentId());
processInstance.setCorrelationKey(_instance.getCorrelationKey());
processInstance.internalSetSlaCompliance(_instance.getSlaCompliance());
if (_instance.getSlaDueDate() > 0) {
processInstance.internalSetSlaDueDate(new Date(_instance.getSlaDueDate()));
}
processInstance.internalSetSlaTimerId(_instance.getSlaTimerId());
long nodeInstanceCounter = _instance.getNodeInstanceCounter();
processInstance.setKnowledgeRuntime(wm.getKnowledgeRuntime());
processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
for (String completedNodeId : _instance.getCompletedNodeIdsList()) {
processInstance.addCompletedNodeId(completedNodeId);
}
if (_instance.getSwimlaneContextCount() > 0) {
Context swimlaneContext = ((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
for (JBPMMessages.ProcessInstance.SwimlaneContextInstance _swimlane : _instance.getSwimlaneContextList()) {
swimlaneContextInstance.setActorId(_swimlane.getSwimlane(), _swimlane.getActorId());
}
}
for (JBPMMessages.ProcessInstance.NodeInstance _node : _instance.getNodeInstanceList()) {
context.parameterObject = _node;
readNodeInstance(context, processInstance, processInstance);
}
for (JBPMMessages.ProcessInstance.ExclusiveGroupInstance _excl : _instance.getExclusiveGroupList()) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
for (Long nodeInstanceId : _excl.getGroupNodeInstanceIdList()) {
NodeInstance nodeInstance = ((org.jbpm.workflow.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);
}
}
if (_instance.getVariableCount() > 0) {
Context variableScope = ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(variableScope);
for (JBPMMessages.Variable _variable : _instance.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 (_instance.getIterationLevelsCount() > 0) {
for (JBPMMessages.IterationLevel _level : _instance.getIterationLevelsList()) {
processInstance.getIterationLevels().put(_level.getId(), _level.getLevel());
}
}
processInstance.reconnect();
return processInstance;
}
Aggregations