Search in sources :

Example 1 with GetProcessInstanceCommand

use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project drools by kiegroup.

the class CommandBasedStatefulKnowledgeSession method getProcessInstance.

public ProcessInstance getProcessInstance(long id) {
    GetProcessInstanceCommand command = new GetProcessInstanceCommand();
    command.setProcessInstanceId(id);
    return runner.execute(command);
}
Also used : GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand)

Example 2 with GetProcessInstanceCommand

use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method testPersistenceTimer.

@Test
public void testPersistenceTimer() throws Exception {
    setUp();
    Properties properties = new Properties();
    properties.setProperty("drools.commandService", PersistableRunner.class.getName());
    properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
    properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
    properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
    SessionConfiguration config = SessionConfiguration.newInstance(properties);
    config.setOption(TimerJobFactoryOption.get(TimerJobFactoryType.JPA.getId()));
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    Collection<KiePackage> kpkgs = getProcessTimer();
    kbase.addPackages(kpkgs);
    PersistableRunner service = new PersistableRunner(kbase, config, env);
    Long sessionId = service.getSessionId();
    StartProcessCommand startProcessCommand = new StartProcessCommand();
    startProcessCommand.setProcessId("org.drools.test.TestProcess");
    ProcessInstance processInstance = service.execute(startProcessCommand);
    logger.info("Started process instance {}", processInstance.getId());
    Thread.sleep(500);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    Thread.sleep(5000);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNull(processInstance);
}
Also used : JPASignalManagerFactory(org.jbpm.persistence.processinstance.JPASignalManagerFactory) Properties(java.util.Properties) JPAWorkItemManagerFactory(org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) PersistableRunner(org.drools.persistence.PersistableRunner) GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand) KiePackage(org.kie.api.definition.KiePackage) JPAProcessInstanceManagerFactory(org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) SessionConfiguration(org.drools.core.SessionConfiguration) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 3 with GetProcessInstanceCommand

use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method testPersistenceWorkItemsUserTransaction.

@Test
public void testPersistenceWorkItemsUserTransaction() throws Exception {
    setUp();
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    Collection<KiePackage> kpkgs = getProcessWorkItems();
    kbase.addPackages(kpkgs);
    Properties properties = new Properties();
    properties.setProperty("drools.commandService", PersistableRunner.class.getName());
    properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
    properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
    properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
    properties.setProperty("drools.timerService", JpaJDKTimerService.class.getName());
    SessionConfiguration config = SessionConfiguration.newInstance(properties);
    PersistableRunner service = new PersistableRunner(kbase, config, env);
    Long sessionId = service.getSessionId();
    UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    ut.begin();
    StartProcessCommand startProcessCommand = new StartProcessCommand();
    startProcessCommand.setProcessId("org.drools.test.TestProcess");
    ProcessInstance processInstance = service.execute(startProcessCommand);
    logger.info("Started process instance {}", processInstance.getId());
    ut.commit();
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    ut.commit();
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    ut.commit();
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    ut.commit();
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    ut.commit();
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    ut.commit();
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    ut.commit();
    workItem = handler.getWorkItem();
    assertNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    ut.begin();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    ut.commit();
    assertNull(processInstance);
    service.dispose();
}
Also used : UserTransaction(javax.transaction.UserTransaction) TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) JPASignalManagerFactory(org.jbpm.persistence.processinstance.JPASignalManagerFactory) CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Properties(java.util.Properties) JPAWorkItemManagerFactory(org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) InitialContext(javax.naming.InitialContext) PersistableRunner(org.drools.persistence.PersistableRunner) GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand) KiePackage(org.kie.api.definition.KiePackage) JPAProcessInstanceManagerFactory(org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) SessionConfiguration(org.drools.core.SessionConfiguration) JpaJDKTimerService(org.drools.persistence.jpa.JpaJDKTimerService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 4 with GetProcessInstanceCommand

use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method testPersistenceWorkItems.

@Test
public void testPersistenceWorkItems() throws Exception {
    setUp();
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    Collection<KiePackage> kpkgs = getProcessWorkItems();
    kbase.addPackages(kpkgs);
    Properties properties = new Properties();
    properties.setProperty("drools.commandService", PersistableRunner.class.getName());
    properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
    properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
    properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
    properties.setProperty("drools.timerService", JpaJDKTimerService.class.getName());
    SessionConfiguration config = SessionConfiguration.newInstance(properties);
    PersistableRunner service = new PersistableRunner(kbase, config, env);
    Long sessionId = service.getSessionId();
    StartProcessCommand startProcessCommand = new StartProcessCommand();
    startProcessCommand.setProcessId("org.drools.test.TestProcess");
    ProcessInstance processInstance = service.execute(startProcessCommand);
    logger.info("Started process instance {}", processInstance.getId());
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    workItem = handler.getWorkItem();
    assertNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, kbase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstance.getId());
    processInstance = service.execute(getProcessInstanceCommand);
    assertNull(processInstance);
    service.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) JPASignalManagerFactory(org.jbpm.persistence.processinstance.JPASignalManagerFactory) CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Properties(java.util.Properties) JPAWorkItemManagerFactory(org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) PersistableRunner(org.drools.persistence.PersistableRunner) GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand) KiePackage(org.kie.api.definition.KiePackage) JPAProcessInstanceManagerFactory(org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) SessionConfiguration(org.drools.core.SessionConfiguration) JpaJDKTimerService(org.drools.persistence.jpa.JpaJDKTimerService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 5 with GetProcessInstanceCommand

use of org.drools.core.command.runtime.process.GetProcessInstanceCommand in project jbpm by kiegroup.

the class SingleSessionCommandServiceTest method testPersistenceSubProcess.

@Test
public void testPersistenceSubProcess() {
    setUp();
    Properties properties = new Properties();
    properties.setProperty("drools.commandService", PersistableRunner.class.getName());
    properties.setProperty("drools.processInstanceManagerFactory", JPAProcessInstanceManagerFactory.class.getName());
    properties.setProperty("drools.workItemManagerFactory", JPAWorkItemManagerFactory.class.getName());
    properties.setProperty("drools.processSignalManagerFactory", JPASignalManagerFactory.class.getName());
    properties.setProperty("drools.timerService", JpaJDKTimerService.class.getName());
    SessionConfiguration config = SessionConfiguration.newInstance(properties);
    InternalKnowledgeBase ruleBase = KnowledgeBaseFactory.newKnowledgeBase();
    KiePackage pkg = getProcessSubProcess();
    ruleBase.addPackages((Collection) Arrays.asList(pkg));
    PersistableRunner service = new PersistableRunner(ruleBase, config, env);
    Long sessionId = service.getSessionId();
    StartProcessCommand startProcessCommand = new StartProcessCommand();
    startProcessCommand.setProcessId("org.drools.test.TestProcess");
    RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) service.execute(startProcessCommand);
    logger.info("Started process instance {}", processInstance.getId());
    long processInstanceId = processInstance.getId();
    TestWorkItemHandler handler = TestWorkItemHandler.getInstance();
    WorkItem workItem = handler.getWorkItem();
    assertNotNull(workItem);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    GetProcessInstanceCommand getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
    processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNotNull(processInstance);
    Collection<NodeInstance> nodeInstances = processInstance.getNodeInstances();
    assertEquals(1, nodeInstances.size());
    SubProcessNodeInstance subProcessNodeInstance = (SubProcessNodeInstance) nodeInstances.iterator().next();
    long subProcessInstanceId = subProcessNodeInstance.getProcessInstanceId();
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
    RuleFlowProcessInstance subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNotNull(subProcessInstance);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    CompleteWorkItemCommand completeWorkItemCommand = new CompleteWorkItemCommand();
    completeWorkItemCommand.setWorkItemId(workItem.getId());
    service.execute(completeWorkItemCommand);
    service.dispose();
    service = new PersistableRunner(sessionId, ruleBase, config, env);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(subProcessInstanceId);
    subProcessInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNull(subProcessInstance);
    getProcessInstanceCommand = new GetProcessInstanceCommand();
    getProcessInstanceCommand.setProcessInstanceId(processInstanceId);
    processInstance = (RuleFlowProcessInstance) service.execute(getProcessInstanceCommand);
    assertNull(processInstance);
    service.dispose();
}
Also used : TestWorkItemHandler(org.jbpm.persistence.session.objects.TestWorkItemHandler) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) JPASignalManagerFactory(org.jbpm.persistence.processinstance.JPASignalManagerFactory) CompleteWorkItemCommand(org.drools.core.command.runtime.process.CompleteWorkItemCommand) Properties(java.util.Properties) JPAWorkItemManagerFactory(org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory) StartProcessCommand(org.drools.core.command.runtime.process.StartProcessCommand) WorkItem(org.kie.api.runtime.process.WorkItem) PersistableRunner(org.drools.persistence.PersistableRunner) GetProcessInstanceCommand(org.drools.core.command.runtime.process.GetProcessInstanceCommand) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) KiePackage(org.kie.api.definition.KiePackage) JPAProcessInstanceManagerFactory(org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory) SubProcessNodeInstance(org.jbpm.workflow.instance.node.SubProcessNodeInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) SessionConfiguration(org.drools.core.SessionConfiguration) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) JpaJDKTimerService(org.drools.persistence.jpa.JpaJDKTimerService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Aggregations

GetProcessInstanceCommand (org.drools.core.command.runtime.process.GetProcessInstanceCommand)13 Test (org.junit.Test)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)6 Properties (java.util.Properties)5 SessionConfiguration (org.drools.core.SessionConfiguration)5 StartProcessCommand (org.drools.core.command.runtime.process.StartProcessCommand)5 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)5 PersistableRunner (org.drools.persistence.PersistableRunner)5 JPAWorkItemManagerFactory (org.drools.persistence.jpa.processinstance.JPAWorkItemManagerFactory)5 JPAProcessInstanceManagerFactory (org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory)5 JPASignalManagerFactory (org.jbpm.persistence.processinstance.JPASignalManagerFactory)5 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5 KiePackage (org.kie.api.definition.KiePackage)5 CompleteWorkItemCommand (org.drools.core.command.runtime.process.CompleteWorkItemCommand)3 JpaJDKTimerService (org.drools.persistence.jpa.JpaJDKTimerService)3 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)3 TestWorkItemHandler (org.jbpm.persistence.session.objects.TestWorkItemHandler)3 WorkItem (org.kie.api.runtime.process.WorkItem)3 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)2