Java Code Examples for org.kie.api.runtime.process.ProcessInstance#signalEvent()

The following examples show how to use org.kie.api.runtime.process.ProcessInstance#signalEvent() . 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 vote down vote up
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: LightWorkItemManager.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public void abortWorkItem(String id, Policy<?>... policies) {
    WorkItemImpl workItem = (WorkItemImpl) workItems.get(id);
    // work item may have been aborted
    if (workItem != null) {
        if (!workItem.enforce(policies)) {
            throw new NotAuthorizedException("Work item can be aborted as it does not fulfil policies (e.g. security)");
        }
        ProcessInstance processInstance = processInstanceManager.getProcessInstance(workItem.getProcessInstanceId());
        Transition<?> transition = new TransitionToAbort(Arrays.asList(policies));
        eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
        workItem.setState(ABORTED);
        abortPhase.apply(workItem, transition);
        
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemAborted", workItem);
        }
        workItem.setPhaseId(ID);
        workItem.setPhaseStatus(STATUS);
        eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
        workItems.remove(id);
    }
}
 
Example 3
Source File: DefaultWorkItemManager.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void completeWorkItem(String id, Map<String, Object> results, Policy<?>... policies) {
    WorkItem workItem = workItems.get(id);
    // work item may have been aborted
    if (workItem != null) {
        (workItem).setResults(results);
        ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
        (workItem).setState(COMPLETED);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemCompleted", workItem);
        }
        workItems.remove(id);
    }
}
 
Example 4
Source File: DefaultWorkItemManager.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void abortWorkItem(String id, Policy<?>... policies) {
    WorkItemImpl workItem = (WorkItemImpl) workItems.get(id);
    // work item may have been aborted
    if (workItem != null) {
        ProcessInstance processInstance = kruntime.getProcessInstance(workItem.getProcessInstanceId());
        workItem.setState(ABORTED);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemAborted", workItem);
        }
        workItems.remove(id);
    }
}
 
Example 5
Source File: LightWorkItemManager.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void internalCompleteWorkItem(WorkItem workItem) {
    ProcessInstance processInstance = processInstanceManager.getProcessInstance(workItem.getProcessInstanceId());                    
    workItem.setState(COMPLETED);
    workItem.setCompleteDate(new Date());
            
    // process instance may have finished already
    if (processInstance != null) {
        processInstance.signalEvent("workItemCompleted", workItem);
    }
    workItems.remove(workItem.getId());
 
}
 
Example 6
Source File: DefaultSignalManager.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void signalEvent(String processInstanceId, String type, Object event) {
	ProcessInstance processInstance = kruntime.getProcessInstance(processInstanceId);
	if (processInstance != null) {
	    processInstance.signalEvent(type, event);
	}
}
 
Example 7
Source File: DefaultSignalManager.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void execute(InternalWorkingMemory workingMemory) {
	ProcessInstance processInstance = workingMemory.getProcessInstance(processInstanceId);
	if (processInstance != null) {
		processInstance.signalEvent(type, event);
	}
}
 
Example 8
Source File: DefaultSignalManager.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void execute(InternalKnowledgeRuntime kruntime) {
	ProcessInstance processInstance = kruntime.getProcessInstance(processInstanceId);
	if (processInstance != null) {
		processInstance.signalEvent(type, event);
	}
}
 
Example 9
Source File: ProcessEventTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@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 10
Source File: ProcessEventTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testProcessInstanceSignalCompositeEvent() 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());
    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"));
}