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;
}
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);
}
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);
}
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());
}
Aggregations