Search in sources :

Example 1 with ProcessInstanceInfo

use of org.jbpm.persistence.processinstance.ProcessInstanceInfo in project jbpm by kiegroup.

the class WorkItemPersistenceTest method retrieveProcessInstanceInfo.

@SuppressWarnings("unchecked")
public static ArrayList<ProcessInstanceInfo> retrieveProcessInstanceInfo(EntityManagerFactory emf) {
    JtaTransactionManager txm = new JtaTransactionManager(null, null, null);
    boolean txOwner = txm.begin();
    EntityManager em = emf.createEntityManager();
    ArrayList<ProcessInstanceInfo> procInstInfoList = new ArrayList<ProcessInstanceInfo>();
    List<Object> mdList = em.createQuery("SELECT p FROM ProcessInstanceInfo p").getResultList();
    for (Object resultObject : mdList) {
        ProcessInstanceInfo procInstInfo = (ProcessInstanceInfo) resultObject;
        procInstInfoList.add(procInstInfo);
        logger.trace("> {}", procInstInfo);
    }
    txm.commit(txOwner);
    return procInstInfoList;
}
Also used : ProcessInstanceInfo(org.jbpm.persistence.processinstance.ProcessInstanceInfo) JtaTransactionManager(org.drools.persistence.jta.JtaTransactionManager) EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList)

Example 2 with ProcessInstanceInfo

use of org.jbpm.persistence.processinstance.ProcessInstanceInfo in project jbpm by kiegroup.

the class ProcessInstanceMigrationTest method assertDefinitionChanged.

@SuppressWarnings("unchecked")
private void assertDefinitionChanged(long pid, String sPid, boolean complete) throws InterruptedException {
    if (!complete) {
        assertEquals(sPid, ksession.getProcessInstance(pid).getProcessId());
    }
    EntityManager em = getEmf().createEntityManager();
    Query query = em.createQuery("select p from ProcessInstanceInfo p where p.processInstanceId = :pid").setParameter("pid", pid);
    List<ProcessInstanceInfo> found = query.getResultList();
    int count = (complete) ? 0 : 1;
    assertNotNull(found);
    assertEquals(count, found.size());
    if (!complete) {
        ProcessInstanceInfo instance = found.get(0);
        assertEquals(sPid, instance.getProcessId());
    }
    manager.disposeRuntimeEngine(engine);
}
Also used : ProcessInstanceInfo(org.jbpm.persistence.processinstance.ProcessInstanceInfo) EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query)

Example 3 with ProcessInstanceInfo

use of org.jbpm.persistence.processinstance.ProcessInstanceInfo in project jbpm by kiegroup.

the class WorkItemPersistenceTest method testHumanTask.

@Test
public void testHumanTask() {
    List<ProcessInstanceInfo> procInstInfoList = retrieveProcessInstanceInfo(emf);
    int numProcInstInfos = procInstInfoList.size();
    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.humantask\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + "  <header>\n" + "  </header>\n" + "\n" + "  <nodes>\n" + "    <start id=\"1\" name=\"Start\" />\n" + "    <humanTask id=\"2\" name=\"HumanTask\" >\n" + "      <work name=\"Human Task\" >\n" + "        <parameter name=\"ActorId\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "          <value>John Doe</value>\n" + "        </parameter>\n" + "        <parameter name=\"TaskName\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "          <value>Do something</value>\n" + "        </parameter>\n" + "        <parameter name=\"Priority\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "        <parameter name=\"Comment\" >\n" + "          <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + "        </parameter>\n" + "      </work>\n" + "    </humanTask>\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>");
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newReaderResource(source), ResourceType.DRF);
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    KieSession ksession = createSession(kbase);
    final List<WorkItem> workItems = new ArrayList<WorkItem>();
    DoNothingWorkItemHandler handler = new DoNothingWorkItemHandler() {

        @Override
        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            super.executeWorkItem(workItem, manager);
            workItems.add(workItem);
        }
    };
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
    ProcessInstance processInstance = ksession.startProcess("org.drools.humantask");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    int state = processInstance.getState();
    switch(state) {
        case ProcessInstance.STATE_ABORTED:
            logger.debug("STATE_ABORTED");
            break;
        case ProcessInstance.STATE_ACTIVE:
            logger.debug("STATE_ACTIVE");
            break;
        case ProcessInstance.STATE_COMPLETED:
            logger.debug("STATE_COMPLETED");
            break;
        case ProcessInstance.STATE_PENDING:
            logger.debug("STATE_PENDING");
            break;
        case ProcessInstance.STATE_SUSPENDED:
            logger.debug("STATE_SUSPENDED");
            break;
        default:
            logger.debug("Unknown state: {}", state);
    }
    procInstInfoList = retrieveProcessInstanceInfo(emf);
    assertTrue((procInstInfoList.size() - numProcInstInfos) == 1);
    ProcessInstanceInfo processInstanceInfoMadeInThisTest = procInstInfoList.get(numProcInstInfos);
    assertNotNull("ByteArray of ProcessInstanceInfo from this test is not filled and null!", processInstanceInfoMadeInThisTest.getProcessInstanceByteArray());
    assertTrue("ByteArray of ProcessInstanceInfo from this test is not filled and empty!", processInstanceInfoMadeInThisTest.getProcessInstanceByteArray().length > 0);
    assertEquals(1, workItems.size());
    ksession.getWorkItemManager().completeWorkItem(workItems.get(0).getId(), null);
    ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
    assertNull(pi);
}
Also used : DoNothingWorkItemHandler(org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) WorkItem(org.kie.api.runtime.process.WorkItem) ProcessInstanceInfo(org.jbpm.persistence.processinstance.ProcessInstanceInfo) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StringReader(java.io.StringReader) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 4 with ProcessInstanceInfo

use of org.jbpm.persistence.processinstance.ProcessInstanceInfo in project jbpm by kiegroup.

the class MapPersistenceTest method processWithNotNullStartDateTest.

@Test
public void processWithNotNullStartDateTest() {
    String processId = "signalProcessTest";
    String eventType = "myEvent";
    RuleFlowProcess process = ProcessCreatorForHelp.newSimpleEventProcess(processId, eventType);
    KieBase kbase = createKieBase(process);
    StatefulKnowledgeSession crmPersistentSession = createSession(kbase);
    RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) crmPersistentSession.startProcess(processId);
    InternalKnowledgeRuntime kruntime = processInstance.getKnowledgeRuntime();
    Assert.assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    ProcessInstanceInfo processInstanceInfo = new ProcessInstanceInfo(processInstance);
    processInstance = (RuleFlowProcessInstance) processInstanceInfo.getProcessInstance(kruntime, crmPersistentSession.getEnvironment());
    Assert.assertNotNull(processInstance.getStartDate());
    Assert.assertEquals(processInstance.getStartDate(), processInstanceInfo.getStartDate());
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) ProcessInstanceInfo(org.jbpm.persistence.processinstance.ProcessInstanceInfo) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) KieBase(org.kie.api.KieBase) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

ProcessInstanceInfo (org.jbpm.persistence.processinstance.ProcessInstanceInfo)4 ArrayList (java.util.ArrayList)2 EntityManager (javax.persistence.EntityManager)2 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)2 Test (org.junit.Test)2 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Query (javax.persistence.Query)1 InternalKnowledgeRuntime (org.drools.core.common.InternalKnowledgeRuntime)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 JtaTransactionManager (org.drools.persistence.jta.JtaTransactionManager)1 DoNothingWorkItemHandler (org.jbpm.process.instance.impl.demo.DoNothingWorkItemHandler)1 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)1 RuleFlowProcessInstance (org.jbpm.ruleflow.instance.RuleFlowProcessInstance)1 KieBase (org.kie.api.KieBase)1 KieSession (org.kie.api.runtime.KieSession)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkItem (org.kie.api.runtime.process.WorkItem)1 WorkItemManager (org.kie.api.runtime.process.WorkItemManager)1 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)1