use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class AbstractProcessInstanceMarshaller method readProcessInstance.
// Input methods
public ProcessInstance readProcessInstance(MarshallerReaderContext context) throws IOException {
ObjectInputStream stream = context.stream;
InternalKnowledgeBase kBase = context.kBase;
InternalWorkingMemory wm = context.wm;
WorkflowProcessInstanceImpl processInstance = createProcessInstance();
processInstance.setId(stream.readLong());
String processId = stream.readUTF();
processInstance.setProcessId(processId);
Process process = kBase.getProcess(processId);
if (kBase != null) {
processInstance.setProcess(process);
}
processInstance.setState(stream.readInt());
long nodeInstanceCounter = stream.readLong();
processInstance.setKnowledgeRuntime(wm.getKnowledgeRuntime());
int nbSwimlanes = stream.readInt();
if (nbSwimlanes > 0) {
Context swimlaneContext = ((org.jbpm.process.core.Process) process).getDefaultContext(SwimlaneContext.SWIMLANE_SCOPE);
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) processInstance.getContextInstance(swimlaneContext);
for (int i = 0; i < nbSwimlanes; i++) {
String name = stream.readUTF();
String value = stream.readUTF();
swimlaneContextInstance.setActorId(name, value);
}
}
while (stream.readShort() == PersisterEnums.NODE_INSTANCE) {
readNodeInstance(context, processInstance, processInstance);
}
int exclusiveGroupInstances = stream.readInt();
for (int i = 0; i < exclusiveGroupInstances; i++) {
ExclusiveGroupInstance exclusiveGroupInstance = new ExclusiveGroupInstance();
processInstance.addContextInstance(ExclusiveGroup.EXCLUSIVE_GROUP, exclusiveGroupInstance);
int nodeInstances = stream.readInt();
for (int j = 0; j < nodeInstances; j++) {
long nodeInstanceId = stream.readLong();
NodeInstance nodeInstance = processInstance.getNodeInstance(nodeInstanceId);
if (nodeInstance == null) {
throw new IllegalArgumentException("Could not find node instance when deserializing exclusive group instance: " + nodeInstanceId);
}
exclusiveGroupInstance.addNodeInstance(nodeInstance);
}
}
// Process Variables
// - Number of Variables = keys.size()
// For Each Variable
// - Variable Key
// - Marshalling Strategy Index
// - Marshalled Object
int nbVariables = stream.readInt();
if (nbVariables > 0) {
Context variableScope = ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(variableScope);
for (int i = 0; i < nbVariables; i++) {
String name = stream.readUTF();
try {
ObjectMarshallingStrategy strategy = null;
int index = stream.readInt();
// This is the old way of de/serializing strategy objects
if (index >= 0) {
strategy = context.resolverStrategyFactory.getStrategy(index);
} else // This is the new way
if (index == -2) {
String strategyClassName = context.stream.readUTF();
if (!StringUtils.isEmpty(strategyClassName)) {
strategy = context.resolverStrategyFactory.getStrategyObject(strategyClassName);
if (strategy == null) {
throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
}
}
}
// If either way retrieves a strategy, use it
Object value = null;
if (strategy != null) {
value = strategy.read(stream);
}
variableScopeInstance.internalSetVariable(name, value);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not reload variable " + name);
}
}
}
processInstance.internalSetNodeInstanceCounter(nodeInstanceCounter);
if (wm != null) {
processInstance.reconnect();
}
return processInstance;
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method writeProcessInstance.
// Output methods
public JBPMMessages.ProcessInstance writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException {
WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
JBPMMessages.ProcessInstance.Builder _instance = JBPMMessages.ProcessInstance.newBuilder().setId(workFlow.getId()).setProcessId(workFlow.getProcessId()).setState(workFlow.getState()).setNodeInstanceCounter(workFlow.getNodeInstanceCounter()).setProcessType(workFlow.getProcess().getType()).setParentProcessInstanceId(workFlow.getParentProcessInstanceId()).setSignalCompletion(workFlow.isSignalCompletion()).setSlaCompliance(workFlow.getSlaCompliance());
if (workFlow.getProcessXml() != null) {
_instance.setProcessXml(workFlow.getProcessXml());
}
if (workFlow.getDescription() != null) {
_instance.setDescription(workFlow.getDescription());
}
if (workFlow.getDeploymentId() != null) {
_instance.setDeploymentId(workFlow.getDeploymentId());
}
_instance.addAllCompletedNodeIds(workFlow.getCompletedNodeIds());
if (workFlow.getCorrelationKey() != null) {
_instance.setCorrelationKey(workFlow.getCorrelationKey());
}
if (workFlow.getSlaDueDate() != null) {
_instance.setSlaDueDate(workFlow.getSlaDueDate().getTime());
}
if (workFlow.getSlaTimerId() != null) {
_instance.setSlaTimerId(workFlow.getSlaTimerId());
}
SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
if (swimlaneContextInstance != null) {
Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
_instance.addSwimlaneContext(JBPMMessages.ProcessInstance.SwimlaneContextInstance.newBuilder().setSwimlane(entry.getKey()).setActorId(entry.getValue()).build());
}
}
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) {
_instance.addNodeInstance(writeNodeInstance(context, nodeInstance));
}
List<ContextInstance> exclusiveGroupInstances = workFlow.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
if (exclusiveGroupInstances != null) {
for (ContextInstance contextInstance : exclusiveGroupInstances) {
JBPMMessages.ProcessInstance.ExclusiveGroupInstance.Builder _exclusive = JBPMMessages.ProcessInstance.ExclusiveGroupInstance.newBuilder();
ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
for (NodeInstance nodeInstance : groupNodeInstances) {
_exclusive.addGroupNodeInstanceId(nodeInstance.getId());
}
_instance.addExclusiveGroup(_exclusive.build());
}
}
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) workFlow.getContextInstance(VariableScope.VARIABLE_SCOPE);
List<Map.Entry<String, Object>> variables = new ArrayList<Map.Entry<String, Object>>(variableScopeInstance.getVariables().entrySet());
Collections.sort(variables, new Comparator<Map.Entry<String, Object>>() {
public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<String, Object> variable : variables) {
if (variable.getValue() != null) {
_instance.addVariable(ProtobufProcessMarshaller.marshallVariable(context, variable.getKey(), variable.getValue()));
}
}
List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(workFlow.getIterationLevels().entrySet());
Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<String, Integer> level : iterationlevels) {
if (level.getValue() != null) {
_instance.addIterationLevels(JBPMMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
}
}
return _instance.build();
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class RuntimeDataServiceImplTest method testGetTaskEvents.
@Test
public void testGetTaskEvents() {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance instance = processService.getProcessInstance(processInstanceId);
assertNotNull(instance);
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstance node = activeNodes.iterator().next();
assertNotNull(node);
assertTrue(node instanceof WorkItemNodeInstance);
Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
assertNotNull(workItemId);
UserTaskInstanceDesc userTask = runtimeDataService.getTaskByWorkItemId(workItemId);
assertNotNull(userTask);
List<TaskEvent> auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter());
assertNotNull(auditTasks);
assertEquals(1, auditTasks.size());
assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
userTaskService.start(userTask.getTaskId(), "salaboy");
auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), new QueryFilter());
assertNotNull(auditTasks);
assertEquals(2, auditTasks.size());
assertEquals(TaskEvent.TaskEventType.ADDED, auditTasks.get(0).getType());
assertEquals(TaskEvent.TaskEventType.STARTED, auditTasks.get(1).getType());
QueryFilter filter = new QueryFilter();
filter.setFilterParams("t.type = :type ");
filter.setParams(Collections.singletonMap("type", TaskEvent.TaskEventType.COMPLETED));
auditTasks = runtimeDataService.getTaskEvents(userTask.getTaskId(), filter);
assertNotNull(auditTasks);
assertEquals(0, auditTasks.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class RuntimeDataServiceImplTest method testGetNodeInstanceForWorkItem.
@Test
public void testGetNodeInstanceForWorkItem() {
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance instance = processService.getProcessInstance(processInstanceId);
assertNotNull(instance);
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstanceImpl) instance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstance node = activeNodes.iterator().next();
assertNotNull(node);
assertTrue(node instanceof WorkItemNodeInstance);
Long workItemId = ((WorkItemNodeInstance) node).getWorkItemId();
assertNotNull(workItemId);
NodeInstanceDesc desc = runtimeDataService.getNodeInstanceForWorkItem(workItemId);
assertNotNull(desc);
assertEquals(processInstanceId, desc.getProcessInstanceId());
assertEquals("Write a Document", desc.getName());
assertEquals("HumanTaskNode", desc.getNodeType());
}
use of org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl in project jbpm by kiegroup.
the class JbpmJUnitBaseTestCase method assertNumOfOutgoingConnections.
public void assertNumOfOutgoingConnections(ProcessInstance process, String nodeName, int num) {
assertNodeExists(process, nodeName);
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) process;
for (Node node : instance.getNodeContainer().getNodes()) {
if (node.getName().equals(nodeName)) {
if (node.getOutgoingConnections().size() != num) {
fail("Expected outgoing connections: " + num + " - found " + node.getOutgoingConnections().size());
} else {
break;
}
}
}
}
Aggregations