public ProcessInstanceInfo(ProcessInstance processInstance) { this.processInstance = processInstance; this.processId = processInstance.getProcessId(); startDate = new Date(); }
public void internalAddProcessInstance(ProcessInstance processInstance) { if( ((ConcurrentHashMap<Long, ProcessInstance>) processInstances) .putIfAbsent(processInstance.getId(), processInstance) != null ) { throw new ConcurrentModificationException( "Duplicate process instance [" + processInstance.getProcessId() + "/" + processInstance.getId() + "]" + " added to process instance manager." ); } }
public void beforeProcessStarted(ProcessStartedEvent event) { String processId = event.getProcessInstance().getProcessId(); Integer count = map.get(processId); if (count == null) { map.put(processId, 1); } else { map.put(processId, count + 1); } }
@Override public void beforeProcessStarted(ProcessStartedEvent event) { startedProcesses.add(event.getProcessInstance().getProcessId()); } });
public void afterProcessStarted(ProcessStartedEvent event) { processesStarted.add(event.getProcessInstance().getProcessId()); }
public void afterProcessCompleted(ProcessCompletedEvent event) { processesCompleted.add(event.getProcessInstance().getProcessId()); }
String fromProcessIdString = kruntime.getProcessInstance(fromProcessId).getProcessId(); Process processFrom = kruntime.getKieBase().getProcess(fromProcessIdString); Process processTo = kruntime.getKieBase().getProcess(toProcessId);
@Override public void beforeProcessStarted(ProcessStartedEvent event) { if (event.getProcessInstance().getProcessId().equals("SubProcess")) { subprocessStarted.add(event.getProcessInstance().getId()); } }
if (!processInstance.getProcessId().equals(this.processId)) { this.processId = processInstance.getProcessId();
this.id = source.getId(); this.parentId = source.getParentProcessInstanceId(); this.caseDefinitionId = source.getProcessId(); this.caseDescription = ((WorkflowProcessInstanceImpl)source).getDescription(); this.caseDefinitionName = source.getProcessName();
@Override public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) { long processInstanceId = pvce.getProcessInstance().getId(); String processId = pvce.getProcessInstance().getProcessId(); String variableId = pvce.getVariableId(); String variableInstanceId = pvce.getVariableInstanceId(); String oldValue = (pvce.getOldValue() != null)?pvce.getOldValue().toString():""; String newValue = (pvce.getNewValue() != null)?pvce.getNewValue().toString():""; VariableInstanceLog log = new VariableInstanceLog( processInstanceId, processId, variableInstanceId, variableId, newValue, oldValue); log.setExternalId(""+((KieSession) pvce.getKieRuntime()).getIdentifier()); return log; }
@Override public void copyFromSource() { if (this.id != null) { return; } this.compositeId = System.getProperty("org.kie.server.id", "") + "_" + source.getId(); this.containerId = ((WorkflowProcessInstance)source).getDeploymentId(); this.correlationKey = ((WorkflowProcessInstanceImpl)source).getCorrelationKey(); this.date = new Date(); this.id = source.getId(); this.initiator = (String) ((WorkflowProcessInstanceImpl)source).getVariable("initiator"); this.parentId = source.getParentProcessInstanceId(); this.processId = source.getProcessId(); this.processInstanceDescription = ((WorkflowProcessInstanceImpl)source).getDescription(); this.processName = source.getProcessName(); this.processVersion = source.getProcess().getVersion(); this.state = source.getState(); this.variables = ((WorkflowProcessInstanceImpl)source).getVariables(); }
private void initialize(NodeInstance nodeInstance, ProcessInstance processInstance) { this.processInstanceId = processInstance.getId(); this.processId = processInstance.getProcessId(); this.setDeploymentId(((ProcessInstanceImpl)processInstance).getDeploymentId()); if( nodeInstance != null ) { this.nodeInstanceId = nodeInstance.getId(); this.nodeId = nodeInstance.getNodeId(); if( ((ProcessInstanceImpl) processInstance).getKnowledgeRuntime() != null ) { this.nodeName = nodeInstance.getNodeName(); } } VariableScopeInstance variableScope = (VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance( VariableScope.VARIABLE_SCOPE ); // set input parameters if( variableScope != null ) { this.variables = variableScope.getVariables(); } else { this.variables = new HashMap<String, Object>(0); } }
/** * Fill the process instance .kruntime and .process fields with the appropriate values. * @param processInstance * @param streamContext */ private void connectProcessInstanceToRuntimeAndProcess(ProcessInstance processInstance, Object streamContext) { ProcessInstanceImpl processInstanceImpl = (ProcessInstanceImpl) processInstance; InternalKnowledgeRuntime kruntime = processInstanceImpl.getKnowledgeRuntime(); // Attach the kruntime if not present if ( kruntime == null ) { kruntime = retrieveKnowledgeRuntime( streamContext ); processInstanceImpl.setKnowledgeRuntime( kruntime ); } // Attach the process if not present if ( processInstance.getProcess() == null ) { String processId = processInstance.getProcessId(); if (processId != null) { Process process = kruntime.getKieBase().getProcess( processId ); if (process != null) { processInstanceImpl.setProcess( process ); } } } }
Assertions.assertThat(var.getOldValue()).isIn("", " ", null); Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId()); Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId()); Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("list");
Assertions.assertThat(var.getOldValue()).isIn("", " ", null); Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId()); Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId()); Assertions.assertThat(var.getVariableId()).isEqualTo("s"); Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("s"); Assertions.assertThat(var.getOldValue()).isEqualTo("InitialValue"); Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId()); Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId()); Assertions.assertThat(var.getVariableId()).isEqualTo("s"); Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("s");
@Test public void testInternalNodeSignalEvent() { Reader source = new StringReader(process); builder.addRuleFlow(source); KieSession session = createKieSession(builder.getPackages()); final List<ProcessEvent> processEventList = new ArrayList<ProcessEvent>(); final ProcessEventListener listener = createProcessEventListener(processEventList); ((InternalWorkingMemory)session).getProcessRuntime().addEventListener(listener); ProcessInstance processInstance = ((InternalWorkingMemory)session).getProcessRuntime().startProcess("org.drools.core.event"); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); assertEquals("MyValue", ((VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance) .getContextInstance(VariableScope.VARIABLE_SCOPE)).getVariable("MyVar")); assertEquals( 28, processEventList.size() ); for (ProcessEvent e: processEventList) { logger.debug(e.toString()); } assertEquals( "org.drools.core.event", ((ProcessStartedEvent) processEventList.get(2)).getProcessInstance().getProcessId()); }
@Test public void testVariableMapping() throws Exception { KieSession workingMemory = createStatefulKnowledgeSessionFromRule(true); Map<String, Object> map = new HashMap<String, Object>(); map.put("x", "x-value"); org.jbpm.process.instance.ProcessInstance processInstance = ( org.jbpm.process.instance.ProcessInstance ) workingMemory.startProcess("com.sample.ruleflow", map); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); assertEquals(2, workingMemory.getProcessInstances().size()); for (ProcessInstance p: workingMemory.getProcessInstances()) { VariableScopeInstance variableScopeInstance = (VariableScopeInstance) (( org.jbpm.process.instance.ProcessInstance )p).getContextInstance(VariableScope.VARIABLE_SCOPE); if ("com.sample.ruleflow".equals(p.getProcessId())) { assertEquals("x-value", variableScopeInstance.getVariable("x")); } else if ("com.sample.subflow".equals(p.getProcessId())) { assertEquals("x-value", variableScopeInstance.getVariable("y")); assertEquals("z-value", variableScopeInstance.getVariable("z")); assertEquals(7, variableScopeInstance.getVariable("n")); assertEquals(10, variableScopeInstance.getVariable("o")); } } workingMemory.insert(new Person()); workingMemory.fireAllRules(); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); VariableScopeInstance variableScopeInstance = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE); assertEquals("z-value", variableScopeInstance.getVariable("x")); assertEquals(10, variableScopeInstance.getVariable("m")); assertEquals(0, workingMemory.getProcessInstances().size()); }
ProcessInstanceLog log = logList.get(0); assertEquals(log.getProcessInstanceId().longValue(), processInstance.getId()); assertEquals(log.getProcessId(), processInstance.getProcessId()); log = logList.get(0); assertEquals("Process instance id", log.getProcessInstanceId().longValue(), processInstance.getId()); assertEquals("Process id", log.getProcessId(), processInstance.getProcessId()); assertEquals("Status", log.getStatus().intValue(), ProcessInstance.STATE_ACTIVE ); log = (ProcessInstanceLog) result; assertEquals(log.getProcessInstanceId().longValue(), processInstance.getId()); assertEquals(log.getProcessId(), processInstance.getProcessId());
@Test @RequirePersistence public void testScriptTaskWithHistoryLog() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-ScriptTask.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("ScriptTask"); assertProcessInstanceCompleted(processInstance); AuditLogService logService = new JPAAuditLogService(ksession.getEnvironment()); List<NodeInstanceLog> logs = logService.findNodeInstances(processInstance.getId()); assertNotNull(logs); assertEquals(6, logs.size()); for (NodeInstanceLog log : logs) { assertNotNull(log.getDate()); } ProcessInstanceLog pilog = logService.findProcessInstance(processInstance.getId()); assertNotNull(pilog); assertNotNull(pilog.getEnd()); List<ProcessInstanceLog> pilogs = logService.findActiveProcessInstances(processInstance.getProcessId()); assertNotNull(pilogs); assertEquals(0, pilogs.size()); logService.dispose(); }