Search in sources :

Example 1 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class EmergencyBedRequestV2Test method testUnhappyPath.

@Test
public void testUnhappyPath() {
    //prepare input parameters for the process:
    String date = DateFormat.getDateInstance().format(new Date());
    String entity = "911";
    String patientAge = "21";
    String patientGender = "F";
    String patientStatus = "Not Critical";
    Map<String, Object> inputVariables = new HashMap<String, Object>();
    inputVariables.put("bedrequest_date", date);
    inputVariables.put("bedrequest_entity", entity);
    inputVariables.put("bedrequest_patientage", patientAge);
    inputVariables.put("bedrequest_patientgender", patientGender);
    inputVariables.put("bedrequest_patientstatus", patientStatus);
    //Start the process using its ID and pass the input variables
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcess("hospitalEmergencyV2", inputVariables);
    //**************   Notify Rejection to Ambulance   **************//
    //The process must be in the 'Notify Rejection to Ambulance' task. 
    //The reason is that the business rules are rejecting the bed request
    //if the status of the patient is not 'Critical'
    Assert.assertEquals("Notify Rejection to Ambulance", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals("The patient is not in a Critical situation.", mockWorkItemHandler.getInputParameter("message"));
    //let's complete the task
    mockWorkItemHandler.completeWorkItem(null);
    //The process should be completed now.
    Assert.assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 2 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class EmergencyBedRequestV3Test method doTest.

@Test
public void doTest() {
    //prepare input parameters for the process:
    String date = DateFormat.getDateInstance().format(new Date());
    String entity = "911";
    String patientAge = "21";
    String patientGender = "F";
    String patientStatus = "Critical";
    Map<String, Object> inputVariables = new HashMap<String, Object>();
    inputVariables.put("bedrequest_date", date);
    inputVariables.put("bedrequest_entity", entity);
    inputVariables.put("bedrequest_patientage", patientAge);
    inputVariables.put("bedrequest_patientgender", patientGender);
    inputVariables.put("bedrequest_patientstatus", patientStatus);
    //Start the process using its ID and pass the input variables
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcess("hospitalEmergencyV3", inputVariables);
    //**************   Coordinate Staff   **************//
    //The process must be in the 'Coordinate Staff' task. Let's check the
    //input parameters received by the handler associated to that task.
    Assert.assertEquals("Coordinate Staff", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals(date, mockWorkItemHandler.getInputParameter("bedrequest_date"));
    Assert.assertEquals(entity, mockWorkItemHandler.getInputParameter("bedrequest_entity"));
    Assert.assertEquals(patientAge, mockWorkItemHandler.getInputParameter("bedrequest_patientage"));
    Assert.assertEquals(patientGender, mockWorkItemHandler.getInputParameter("bedrequest_patientgender"));
    Assert.assertEquals(patientStatus, mockWorkItemHandler.getInputParameter("bedrequest_patientstatus"));
    //let's complete the task emulating the results of this task.
    Map<String, Object> taskResults = new HashMap<String, Object>();
    taskResults.put("checkinresults_gate", "3C");
    mockWorkItemHandler.completeWorkItem(taskResults);
    System.out.println("\n'Coordinate Staff' task completed \n");
    //**************   Notify Gate to Ambulance   **************//
    //Now we are at 'Notify Gate to Ambulance' task. Let's check that the input
    //parameters configured for this tasks arrived as expected.
    Assert.assertEquals("Notify Gate to Ambulance", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals("3C", mockWorkItemHandler.getInputParameter("checkinresults_gate"));
    //let's complete the task with a mocked resource
    taskResults = new HashMap<String, Object>();
    taskResults.put("checkinresults_notified", "true");
    mockWorkItemHandler.completeWorkItem(taskResults);
    System.out.println("\n'Notify Gate to Ambulance' task completed\n");
    //at this point, the end node is reached, but since it is not a terminate
    //end event, the process will remain active waiting for an event ('Ambulance Arrived')
    //to happen. At this point there is no 'active' node
    System.out.println("Process state= " + processInstance.getState());
    Assert.assertTrue(processInstance.getNodeInstances().isEmpty());
    //At some point, the ambulance arrives to the gate and the process is
    //notified. (The second parameter is used when we want to send data
    //associated with the event. This is not our case)
    session.signalEvent("Ambulance Arrived", null);
    //processInstance.signalEvent("Ambulance Arrived", null);
    System.out.println("\n'Ambulance Arrived' event signaled \n");
    //**************   Check In Patient   **************//
    //In 'Check In Patient' task we are expecting a 'checkinresults_notified'
    //parameter containing the value returned by the last task
    Assert.assertEquals("Check In Patient", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals("true", mockWorkItemHandler.getInputParameter("checkinresults_notified"));
    //let's complete the task passing the mocked results
    taskResults = new HashMap<String, Object>();
    String checkinDate = DateFormat.getTimeInstance().format(new Date());
    taskResults.put("checkinresults_checkedin", "true");
    taskResults.put("checkinresults_time", checkinDate);
    mockWorkItemHandler.completeWorkItem(taskResults);
    System.out.println("\n'Check In Patient' task completed \n");
    //The process should be completed now. Let's check the 2 output
    //parameters of the last task: they should be mapped to process variables.
    Assert.assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    Assert.assertEquals("true", processInstance.getVariable("checkinresults_checkedin"));
    Assert.assertEquals(checkinDate, processInstance.getVariable("checkinresults_time"));
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 3 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class EmergencyBedRequestV4Test method doTest.

@Test
public void doTest() {
    //prepare input parameters for the process:
    String date = DateFormat.getDateInstance().format(new Date());
    String entity = "911";
    String patientAge = "21";
    String patientGender = "F";
    String patientStatus = "Critical";
    Map<String, Object> inputVariables = new HashMap<String, Object>();
    inputVariables.put("bedrequest_date", date);
    inputVariables.put("bedrequest_entity", entity);
    inputVariables.put("bedrequest_patientage", patientAge);
    inputVariables.put("bedrequest_patientgender", patientGender);
    inputVariables.put("bedrequest_patientstatus", patientStatus);
    //Start the process using its ID and pass the input variables
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcess("hospitalEmergencyV4", inputVariables);
    //**************   Coordinate Staff   **************//
    //The process must be in the 'Coordinate Staff' task. Let's check the
    //input parameters received by the handler associated to that task.
    Assert.assertEquals("Coordinate Staff", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals(date, mockWorkItemHandler.getInputParameter("bedrequest_date"));
    Assert.assertEquals(entity, mockWorkItemHandler.getInputParameter("bedrequest_entity"));
    Assert.assertEquals(patientAge, mockWorkItemHandler.getInputParameter("bedrequest_patientage"));
    Assert.assertEquals(patientGender, mockWorkItemHandler.getInputParameter("bedrequest_patientgender"));
    Assert.assertEquals(patientStatus, mockWorkItemHandler.getInputParameter("bedrequest_patientstatus"));
    //let's complete the task emulating the results of this task.
    Map<String, Object> taskResults = new HashMap<String, Object>();
    taskResults.put("checkinresults_gate", "3C");
    mockWorkItemHandler.completeWorkItem(taskResults);
    System.out.println("\n'Coordinate Staff' task completed \n");
    //**************   Notify Gate to Ambulance   **************//
    //Now we are at 'Notify Gate to Ambulance' task. Let's check that the input
    //parameters configured for this tasks arrived as expected.
    Assert.assertEquals("Notify Gate to Ambulance", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals("3C", mockWorkItemHandler.getInputParameter("checkinresults_gate"));
    //let's complete the task with a mocked resource
    taskResults = new HashMap<String, Object>();
    taskResults.put("checkinresults_notified", "true");
    mockWorkItemHandler.completeWorkItem(taskResults);
    System.out.println("\n'Notify Gate to Ambulance' task completed\n");
    //at this point, the intermediate signal event node is reached. 
    //The process is waiting in this node  for the event to happen
    Assert.assertEquals("Ambulance Arrived", processInstance.getNodeInstances().iterator().next().getNodeName());
    //At some point, the ambulance arrives to the gate and the process is
    //notified. (The second parameter is used when we want to send data
    //associated with the event. This is not our case)
    session.signalEvent("Ambulance Arrived", null);
    //processInstance.signalEvent("Ambulance Arrived", null);
    System.out.println("\n'Ambulance Arrived' event signaled \n");
    //**************   Check In Patient   **************//
    //In 'Check In Patient' task we are expecting a 'checkinresults_notified'
    //parameter containing the value returned by the last task
    Assert.assertEquals("Check In Patient", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals("true", mockWorkItemHandler.getInputParameter("checkinresults_notified"));
    //let's complete the task passing the mocked results
    taskResults = new HashMap<String, Object>();
    String checkinDate = DateFormat.getTimeInstance().format(new Date());
    taskResults.put("checkinresults_checkedin", "true");
    taskResults.put("checkinresults_time", checkinDate);
    mockWorkItemHandler.completeWorkItem(taskResults);
    System.out.println("\n'Check In Patient' task completed \n");
    //The process should be completed now. Let's check the 2 output
    //parameters of the last task: they should be mapped to process variables.
    Assert.assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    Assert.assertEquals("true", processInstance.getVariable("checkinresults_checkedin"));
    Assert.assertEquals(checkinDate, processInstance.getVariable("checkinresults_time"));
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 4 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jBPM5-Developer-Guide by Salaboy.

the class EmergencyBedRequestV1Test method doTest.

@Test
public void doTest() {
    //prepare input parameters for the process:
    String date = DateFormat.getDateInstance().format(new Date());
    String entity = "911";
    String patientAge = "21";
    String patientGender = "F";
    String patientStatus = "Critical";
    Map<String, Object> inputVariables = new HashMap<String, Object>();
    inputVariables.put("bedrequest_date", date);
    inputVariables.put("bedrequest_entity", entity);
    inputVariables.put("bedrequest_patientage", patientAge);
    inputVariables.put("bedrequest_patientgender", patientGender);
    inputVariables.put("bedrequest_patientstatus", patientStatus);
    //Start the process using its ID and pass the input variables
    WorkflowProcessInstance processInstance = (WorkflowProcessInstance) session.startProcess("hospitalEmergencyV1", inputVariables);
    //**************   Coordinate Staff   **************//
    //The process must be in the 'Coordinate Staff' task. Let's check the
    //input parameters received by the handler associated to that task.
    Assert.assertEquals("Coordinate Staff", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals(date, mockWorkItemHandler.getInputParameter("bedrequest_date"));
    Assert.assertEquals(entity, mockWorkItemHandler.getInputParameter("bedrequest_entity"));
    Assert.assertEquals(patientAge, mockWorkItemHandler.getInputParameter("bedrequest_patientage"));
    Assert.assertEquals(patientGender, mockWorkItemHandler.getInputParameter("bedrequest_patientgender"));
    Assert.assertEquals(patientStatus, mockWorkItemHandler.getInputParameter("bedrequest_patientstatus"));
    //let's complete the task emulating the results of this task.
    Map<String, Object> taskResults = new HashMap<String, Object>();
    taskResults.put("checkinresults_gate", "3C");
    mockWorkItemHandler.completeWorkItem(taskResults);
    //**************   Notify Gate to Ambulance   **************//
    //Now we are at 'Notify Gate to Ambulance' task. Let's check that the input
    //parameters configured for this tasks arrived as expected.
    Assert.assertEquals("Notify Gate to Ambulance", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals("3C", mockWorkItemHandler.getInputParameter("checkinresults_gate"));
    //let's complete the task with a mocked resource
    taskResults = new HashMap<String, Object>();
    taskResults.put("checkinresults_notified", "true");
    mockWorkItemHandler.completeWorkItem(taskResults);
    //**************   Check In Patient   **************//
    //In 'Check In Patient' task we are expecting a 'checkinresults_notified'
    //parameter containing the value returned by the last task
    Assert.assertEquals("Check In Patient", processInstance.getNodeInstances().iterator().next().getNodeName());
    Assert.assertEquals("true", mockWorkItemHandler.getInputParameter("checkinresults_notified"));
    //let's complete the task passing the mocked results
    taskResults = new HashMap<String, Object>();
    String checkinDate = DateFormat.getTimeInstance().format(new Date());
    taskResults.put("checkinresults_checkedin", "true");
    taskResults.put("checkinresults_time", checkinDate);
    mockWorkItemHandler.completeWorkItem(taskResults);
    //The process should be completed now. Let's check the 2 output
    //parameters of the last task: they should be mapped to process variables.
    Assert.assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    Assert.assertEquals("true", processInstance.getVariable("checkinresults_checkedin"));
    Assert.assertEquals(checkinDate, processInstance.getVariable("checkinresults_time"));
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 5 with WorkflowProcessInstance

use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.

the class IdentityProviderAwareProcessListener method beforeProcessStarted.

public void beforeProcessStarted(final ProcessStartedEvent event) {
    resolveIdentityProvider();
    if (identityProvider != null) {
        final WorkflowProcessInstance wpi = (WorkflowProcessInstance) event.getProcessInstance();
        final String name = identityProvider.getName();
        wpi.setVariable("initiator", name);
        wpi.getMetaData().put("OwnerId", name);
    }
}
Also used : WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance)

Aggregations

WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)24 HashMap (java.util.HashMap)16 Test (org.junit.Test)15 KieSession (org.kie.api.runtime.KieSession)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)8 Date (java.util.Date)6 RegistryContext (org.drools.core.command.impl.RegistryContext)5 Context (org.kie.api.runtime.Context)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ExecutableCommand (org.drools.core.command.impl.ExecutableCommand)3 NodeInstance (org.kie.api.runtime.process.NodeInstance)3 Matcher (java.util.regex.Matcher)2 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)2 ProcessStartedEventImpl (org.drools.core.event.ProcessStartedEventImpl)2 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)2 SignallingTaskHandlerDecorator (org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator)2 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)2