Java Code Examples for org.kie.api.runtime.KieSession#getProcessInstance()
The following examples show how to use
org.kie.api.runtime.KieSession#getProcessInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignalEventCommand.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public Void execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); if (processInstanceId == null && correlationKey == null) { ksession.signalEvent(eventType, event); } else { ProcessInstance processInstance; if( correlationKey != null ) { processInstance = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(correlationKey); } else { processInstance = ksession.getProcessInstance(processInstanceId); } if (processInstance != null) { processInstance.signalEvent(eventType, event); } } return null; }
Example 2
Source File: LibraryClient.java From rhpam-7-openshift-image with Apache License 2.0 | 6 votes |
boolean returnLoan(Loan loan) { ReturnRequest returnRequest = new ReturnRequest(); returnRequest.setLoan(loan); ReturnResponse returnResponse; if (appcfg.getKieSession() != null) { KieSession kieSession = appcfg.getKieSession(); WorkflowProcessInstance procinst = (WorkflowProcessInstance) kieSession.getProcessInstance(loan.getId()); procinst.signalEvent("ReturnSignal", returnRequest); returnResponse = (ReturnResponse) procinst.getVariable("returnResponse"); } else { ProcessServicesClient procserv = appcfg.getProcessServicesClient(); procserv.signalProcessInstance("rhpam-kieserver-library", loan.getId(), "ReturnSignal", returnRequest); //returnResponse = (ReturnResponse)procserv.getProcessInstanceVariable("rhpam-kieserver-library", loan.getId(), "returnResponse"); returnResponse = new ReturnResponse(); returnResponse.setAcknowledged(true); } return returnResponse != null ? returnResponse.isAcknowledged() : false; }
Example 3
Source File: JbpmBpmn2TestCase.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public void assertNodeActive(String processInstanceId, KieSession ksession, String... name) { List<String> names = new ArrayList<String>(); for (String n : name) { names.add(n); } ProcessInstance processInstance = ksession .getProcessInstance(processInstanceId); if (processInstance instanceof WorkflowProcessInstance) { assertNodeActive((WorkflowProcessInstance) processInstance, names); } if (!names.isEmpty()) { String s = names.get(0); for (int i = 1; i < names.size(); i++) { s += ", " + names.get(i); } fail("Node(s) not active: " + s); } }
Example 4
Source File: SLAComplianceTest.java From kogito-runtimes with Apache License 2.0 | 6 votes |
@Test public void testSLAonProcessMet() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLA.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ProcessInstance processInstance = ksession.startProcess("UserTask"); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("john", workItem.getParameter("ActorId")); processInstance = ksession.getProcessInstance(processInstance.getId()); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceFinished(processInstance, ksession); int slaCompliance = getSLAComplianceForProcessInstance(processInstance); assertEquals(ProcessInstance.SLA_MET, slaCompliance); ksession.dispose(); }
Example 5
Source File: MigrateProcessInstanceCommand.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Void execute(Context context ) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) ksession.getProcessInstance(processInstanceId); if (processInstance == null) { throw new IllegalArgumentException("Could not find process instance " + processInstanceId); } if (processId == null) { throw new IllegalArgumentException("Null process id"); } WorkflowProcess process = (WorkflowProcess) ksession.getKieBase().getProcess(processId); if (process == null) { throw new IllegalArgumentException("Could not find process " + processId); } if (processInstance.getProcessId().equals(processId)) { return null; } synchronized (processInstance) { org.kie.api.definition.process.Process oldProcess = processInstance.getProcess(); processInstance.disconnect(); processInstance.setProcess(oldProcess); if (nodeMapping == null) { nodeMapping = new HashMap<String, Long>(); } updateNodeInstances(processInstance, nodeMapping); processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession); processInstance.setProcess(process); processInstance.reconnect(); } return null; }
Example 6
Source File: ResumeProcessInstanceCommand.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Object execute(Context context ) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); if (processInstanceId == null) { return null; } ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId); if ( processInstance == null ) { throw new IllegalArgumentException( "Could not find process instance for id " + processInstanceId ); } if ( processInstance.getState() != ProcessInstance.STATE_SUSPENDED ) { throw new IllegalArgumentException( "Process instance with id " + processInstanceId + " in state " + processInstance.getState()); } ((org.jbpm.process.instance.ProcessInstance) processInstance).setState( ProcessInstance.STATE_ACTIVE ); return null; }
Example 7
Source File: SuspendProcessInstanceCommand.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Object execute(Context context ) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); if (processInstanceId == null) { return null; } ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId); if ( processInstance == null ) { throw new IllegalArgumentException( "Could not find process instance for id " + processInstanceId ); } if ( processInstance.getState() != ProcessInstance.STATE_ACTIVE ) { throw new IllegalArgumentException( "Process instance with id " + processInstanceId + " in state " + processInstance.getState()); } ((org.jbpm.process.instance.ProcessInstance) processInstance).setState( ProcessInstance.STATE_SUSPENDED ); return null; }
Example 8
Source File: StandaloneBPMNProcessTest.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public static void runTestSignallingExceptionServiceTask(KieSession ksession) throws Exception { // Setup String eventType = "exception-signal"; SignallingTaskHandlerDecorator signallingTaskWrapper = new SignallingTaskHandlerDecorator(ServiceTaskHandler.class, eventType); signallingTaskWrapper.setWorkItemExceptionParameterName(ExceptionService.exceptionParameterName); ksession.getWorkItemManager().registerWorkItemHandler("Service Task", signallingTaskWrapper); Object [] caughtEventObjectHolder = new Object[1]; caughtEventObjectHolder[0] = null; ExceptionService.setCaughtEventObjectHolder(caughtEventObjectHolder); // Start process Map<String, Object> params = new HashMap<String, Object>(); String input = "this is my service input"; params.put("serviceInputItem", input ); ProcessInstance processInstance = ksession.startProcess("ServiceProcess", params); // Check that event was passed to Event SubProcess (and grabbed by WorkItemHandler); assertThat(caughtEventObjectHolder[0] != null && caughtEventObjectHolder[0] instanceof WorkItem).isTrue().withFailMessage("Event was not passed to Event Subprocess."); WorkItem workItem = (WorkItem) caughtEventObjectHolder[0]; Object throwObj = workItem.getParameter(ExceptionService.exceptionParameterName); assertThat(throwObj instanceof Throwable).isTrue().withFailMessage("WorkItem doesn't contain Throwable."); assertThat(((Throwable) throwObj).getMessage().endsWith(input)).isTrue().withFailMessage("Exception message does not match service input."); // Complete process assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE).withFailMessage("Process instance is not active."); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); processInstance = ksession.getProcessInstance(processInstance.getId()); if( processInstance != null ) { assertThat(processInstance.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED).withFailMessage("Process instance is not completed."); } // otherwise, persistence use => processInstance == null => process is completed }
Example 9
Source File: SetProcessInstanceVariablesCommand.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public Void execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup(KieSession.class); ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId); if (processInstance != null) { if (variables != null) { for (Map.Entry<String, Object> entry : variables.entrySet()) { ((WorkflowProcessInstance) processInstance).setVariable(entry.getKey(), entry.getValue()); } } } return null; }
Example 10
Source File: GetProcessInstanceCommand.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public ProcessInstance execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); if (processInstanceId == null) { return null; } final ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId, readOnly); if ( this.outIdentifier != null ) { ((RegistryContext) context).lookup( ExecutionResultImpl.class ).setResult(this.outIdentifier, processInstance); } return processInstance; }
Example 11
Source File: ProcessEventTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testInternalEventCorrelation() throws Exception { Reader source = new StringReader( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.core.event\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"MyVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <eventNode id=\"2\" name=\"Event\" variableName=\"MyVar\" >\n" + " <eventFilters>\n" + " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + " </eventFilters>\n" + " </eventNode>\n" + " <join id=\"3\" name=\"Join\" type=\"1\" />\n" + " <end id=\"4\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"3\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " <connection from=\"3\" to=\"4\" />\n" + " </connections>\n" + "\n" + "</process>"); builder.addRuleFlow(source); KieSession session = createKieSession(builder.getPackages()); ProcessInstance processInstance = session.startProcess("org.drools.core.event"); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); assertEquals("SomeText", ((VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance( VariableScope.VARIABLE_SCOPE)).getVariable("MyVar")); session = JbpmSerializationHelper.getSerialisedStatefulKnowledgeSession(session); processInstance = session.getProcessInstance(processInstance.getId()); ((InternalWorkingMemory) session).getProcessRuntime().signalEvent("MyEvent", "MyValue"); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); }
Example 12
Source File: ProcessEventTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testExternalEventCorrelation() throws Exception { Reader source = new StringReader( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.core.event\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"MyVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <eventNode id=\"2\" name=\"Event\" variableName=\"MyVar\" scope=\"external\" >\n" + " <eventFilters>\n" + " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + " </eventFilters>\n" + " </eventNode>\n" + " <join id=\"3\" name=\"Join\" type=\"1\" />\n" + " <end id=\"4\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"3\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " <connection from=\"3\" to=\"4\" />\n" + " </connections>\n" + "\n" + "</process>"); builder.addRuleFlow(source); KieSession session = createKieSession(builder.getPackages()); ProcessInstance processInstance = session.startProcess("org.drools.core.event"); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); assertEquals("SomeText", ((VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance( VariableScope.VARIABLE_SCOPE)).getVariable("MyVar")); session = JbpmSerializationHelper.getSerialisedStatefulKnowledgeSession(session); processInstance = session.getProcessInstance(processInstance.getId()); ((InternalWorkingMemory) session).getProcessRuntime().signalEvent("MyEvent", "MyValue"); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); assertEquals("MyValue", ((VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance( VariableScope.VARIABLE_SCOPE)).getVariable("MyVar")); }
Example 13
Source File: SLAComplianceTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testSLAonProcessViolated() throws Exception { CountDownLatch latch = new CountDownLatch(1); final ProcessEventListener listener = new DefaultProcessEventListener(){ @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } }; KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLA.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ksession.addEventListener(listener); ProcessInstance processInstance = ksession.startProcess("UserTask"); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("john", workItem.getParameter("ActorId")); boolean slaViolated = latch.await(10, TimeUnit.SECONDS); assertTrue(slaViolated, "SLA was not violated while it is expected"); processInstance = ksession.getProcessInstance(processInstance.getId()); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); int slaCompliance = getSLAComplianceForProcessInstance(processInstance); assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceFinished(processInstance, ksession); slaCompliance = getSLAComplianceForProcessInstance(processInstance); assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance); ksession.dispose(); }
Example 14
Source File: SLAComplianceTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testSLAonUserTaskViolated() throws Exception { CountDownLatch latch = new CountDownLatch(1); final ProcessEventListener listener = new DefaultProcessEventListener(){ @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } }; KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLAOnTask.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ksession.addEventListener(listener); ProcessInstance processInstance = ksession.startProcess("UserTask"); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("john", workItem.getParameter("ActorId")); boolean slaViolated = latch.await(10, TimeUnit.SECONDS); assertTrue(slaViolated, "SLA was not violated while it is expected"); processInstance = ksession.getProcessInstance(processInstance.getId()); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); int slaCompliance = getSLAComplianceForProcessInstance(processInstance); assertEquals(ProcessInstance.SLA_NA, slaCompliance); Collection<NodeInstance> active = ((WorkflowProcessInstance)processInstance).getNodeInstances(); assertEquals(1, active.size()); NodeInstance userTaskNode = active.iterator().next(); slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0); assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceFinished(processInstance, ksession); slaCompliance = getSLAComplianceForProcessInstance(processInstance); assertEquals(ProcessInstance.SLA_NA, slaCompliance); slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1); assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance); ksession.dispose(); }
Example 15
Source File: SLAComplianceTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testSLAonProcessViolatedExternalTracking() throws Exception { CountDownLatch latch = new CountDownLatch(1); final ProcessEventListener listener = new DefaultProcessEventListener(){ @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } }; KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLA.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ksession.addEventListener(listener); ksession.getEnvironment().set("SLATimerMode", "false"); ProcessInstance processInstance = ksession.startProcess("UserTask"); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("john", workItem.getParameter("ActorId")); boolean slaViolated = latch.await(5, TimeUnit.SECONDS); assertFalse(slaViolated, "SLA should not violated by timer"); // simulate external tracking of sla ksession.signalEvent("slaViolation", null, processInstance.getId()); slaViolated = latch.await(10, TimeUnit.SECONDS); assertTrue(slaViolated, "SLA was not violated while it is expected"); processInstance = ksession.getProcessInstance(processInstance.getId()); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); int slaCompliance = getSLAComplianceForProcessInstance(processInstance); assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceFinished(processInstance, ksession); slaCompliance = getSLAComplianceForProcessInstance(processInstance); assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance); ksession.dispose(); }
Example 16
Source File: SLAComplianceTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testSLAonUserTaskViolatedExternalTracking() throws Exception { CountDownLatch latch = new CountDownLatch(1); final ProcessEventListener listener = new DefaultProcessEventListener(){ @Override public void afterSLAViolated(SLAViolatedEvent event) { latch.countDown(); } }; KieBase kbase = createKnowledgeBase("BPMN2-UserTaskWithSLAOnTask.bpmn2"); KieSession ksession = createKnowledgeSession(kbase); TestWorkItemHandler workItemHandler = new TestWorkItemHandler(); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", workItemHandler); ksession.addEventListener(listener); ksession.getEnvironment().set("SLATimerMode", "false"); ProcessInstance processInstance = ksession.startProcess("UserTask"); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); WorkItem workItem = workItemHandler.getWorkItem(); assertNotNull(workItem); assertEquals("john", workItem.getParameter("ActorId")); boolean slaViolated = latch.await(5, TimeUnit.SECONDS); assertFalse(slaViolated, "SLA should not violated by timer"); processInstance = ksession.getProcessInstance(processInstance.getId()); assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE); Collection<NodeInstance> active = ((WorkflowProcessInstance)processInstance).getNodeInstances(); assertEquals(1, active.size()); NodeInstance userTaskNode = active.iterator().next(); // simulate external tracking of sla ksession.signalEvent("slaViolation:" + userTaskNode.getId(), null, processInstance.getId()); slaViolated = latch.await(10, TimeUnit.SECONDS); assertTrue(slaViolated, "SLA was not violated while it is expected"); ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null); assertProcessInstanceFinished(processInstance, ksession); int slaCompliance = getSLAComplianceForProcessInstance(processInstance); assertEquals(ProcessInstance.SLA_NA, slaCompliance); slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 0); assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance); slaCompliance = getSLAComplianceForNodeInstance(processInstance.getId(), (org.jbpm.workflow.instance.NodeInstance) userTaskNode, 1); assertEquals(ProcessInstance.SLA_VIOLATED, slaCompliance); ksession.dispose(); }
Example 17
Source File: JavaHandlerWorkItemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String className = (String) workItem.getParameter("Class"); Class<JavaHandler> c = (Class<JavaHandler>) Class.forName(className); JavaHandler handler = c.newInstance(); KieSession localksession = ksession; RuntimeManager runtimeManager = null; RuntimeEngine engine = null; if (localksession == null) { runtimeManager = RuntimeManagerRegistry.get().getManager(((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId()); engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(workItem.getProcessInstanceId())); localksession = engine.getKieSession(); } ProcessContext kcontext = new ProcessContext(localksession); try { WorkflowProcessInstance processInstance = (WorkflowProcessInstance) localksession.getProcessInstance(workItem.getProcessInstanceId()); kcontext.setProcessInstance(processInstance); WorkItemNodeInstance nodeInstance = findNodeInstance(workItem.getId(), processInstance); kcontext.setNodeInstance(nodeInstance); Map<String, Object> results = handler.execute(kcontext); manager.completeWorkItem(workItem.getId(), results); } finally { if (engine != null) { runtimeManager.disposeRuntimeEngine(engine); } } return; } catch (Exception e) { handleException(e); } }
Example 18
Source File: ProcessEventTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testProcessInstanceSignalEvent() throws Exception { Reader source = new StringReader( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.core.event\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"MyVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <eventNode id=\"2\" name=\"Event\" variableName=\"MyVar\" >\n" + " <eventFilters>\n" + " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + " </eventFilters>\n" + " </eventNode>\n" + " <join id=\"3\" name=\"Join\" type=\"1\" />\n" + " <end id=\"4\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"3\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " <connection from=\"3\" to=\"4\" />\n" + " </connections>\n" + "\n" + "</process>"); builder.addRuleFlow(source); KieSession session = createKieSession(builder.getPackages()); ProcessInstance processInstance = session.startProcess("org.drools.core.event"); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); session = JbpmSerializationHelper.getSerialisedStatefulKnowledgeSession(session); processInstance = session.getProcessInstance(processInstance.getId()); processInstance.signalEvent("MyEvent", "MyValue"); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); assertEquals("MyValue", ((VariableScopeInstance) ((org.jbpm.process.instance.ProcessInstance) processInstance).getContextInstance( VariableScope.VARIABLE_SCOPE)).getVariable("MyVar")); }
Example 19
Source File: ProcessEventTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testInternalCompositeEventCorrelation() throws Exception { Reader source = new StringReader( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.core.event\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <variables>\n" + " <variable name=\"MyVar\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <composite id=\"2\" name=\"CompositeNode\" >\n" + " <nodes>\n" + " <eventNode id=\"2\" name=\"Event\" variableName=\"MyVar\" >\n" + " <eventFilters>\n" + " <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" + " </eventFilters>\n" + " </eventNode>\n" + " <join id=\"3\" name=\"Join\" type=\"1\" />\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + " <in-ports>\n" + " <in-port type=\"DROOLS_DEFAULT\" nodeId=\"3\" nodeInType=\"DROOLS_DEFAULT\" />\n" + " </in-ports>\n" + " <out-ports>\n" + " <out-port type=\"DROOLS_DEFAULT\" nodeId=\"3\" nodeOutType=\"DROOLS_DEFAULT\" />\n" + " </out-ports>\n" + " </composite>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>"); builder.addRuleFlow(source); KieSession session = createKieSession(builder.getPackages()); ProcessInstance processInstance = session.startProcess("org.drools.core.event"); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); session = JbpmSerializationHelper.getSerialisedStatefulKnowledgeSession(session); processInstance = session.getProcessInstance(processInstance.getId()); ((InternalWorkingMemory) session).getProcessRuntime().signalEvent("MyEvent", "MyValue"); assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); }
Example 20
Source File: FlowTest.java From kogito-runtimes with Apache License 2.0 | 3 votes |
public Object execute(Context context) { KieSession ksession = ((RegistryContext) context).lookup( KieSession.class ); org.jbpm.process.instance.ProcessInstance processInstance = (org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(processInstanceId); VariableScopeInstance variableScope = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE); Object variable = variableScope.getVariable(variableName); return variable; }