use of org.drools.io.impl.ClassPathResource in project jBPM5-Developer-Guide by Salaboy.
the class PersistentProcessTest method processInstancesAndLocalHTTest.
@Test
public void processInstancesAndLocalHTTest() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("process-async-interactions.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
System.out.println(">>> Error:" + error.getMessage());
}
fail(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
Environment env = EnvironmentFactory.newEnvironment();
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.runtime.ht");
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager());
// Let's create a Persistence Knowledge Session
System.out.println(" >>> Let's create a Persistent Knowledge Session");
final StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
int sessionId = ksession.getId();
assertNotNull(sessionId);
assertTrue(sessionId != 0);
// We need to register the WorkItems and Listeners that the session will use
TaskService client = createTaskService(emf);
LocalHTWorkItemHandler localHTWorkItemHandler = new LocalHTWorkItemHandler(client, ksession);
MockExternalServiceWorkItemHandler mockExternalServiceWorkItemHandler = new MockExternalServiceWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", localHTWorkItemHandler);
ksession.getWorkItemManager().registerWorkItemHandler("External Service Call", mockExternalServiceWorkItemHandler);
//KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
// Let's create a Process Instance
Person person = new Person("Salaboy", 29);
Map<String, Object> params = new HashMap<String, Object>();
params.put("person", person);
//Each Command will generate an interaction
System.out.println(">>> Let's Create Process Instance");
ProcessInstance processInstance = ksession.createProcessInstance("com.salaboy.process.AsyncInteractions", params);
System.out.println(">>> Let's Start the Process Instance");
processInstance = ksession.startProcessInstance(processInstance.getId());
System.out.println(" >>> Looking for Salaboy's Tasks");
List<TaskSummary> salaboysTasks = client.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
assertTrue(salaboysTasks.size() == 1);
TaskSummary salaboyTask = salaboysTasks.get(0);
System.out.println(" >>> Starting Salaboy's Task");
client.start(salaboyTask.getId(), "salaboy");
System.out.println(" >>> Completing Salaboy's Task");
client.complete(salaboyTask.getId(), "salaboy", null);
List<TaskSummary> adminTasks = client.getTasksAssignedAsPotentialOwner("Administrator", "en-UK");
assertTrue(adminTasks.size() == 1);
TaskSummary adminTask = adminTasks.get(0);
client.start(adminTask.getId(), "Administrator");
client.complete(adminTask.getId(), "Administrator", null);
processInstance = ksession.getProcessInstance(processInstance.getId());
//The process instance was completed and it should be out of the Ksession.
assertNull(processInstance);
// We need to dispose the session, because the reference to this ksession object will no longer be valid
// Another thread could load the same session and execute a different command.
System.out.println(">>> Disposing Session");
ksession.dispose();
}
use of org.drools.io.impl.ClassPathResource in project jBPM5-Developer-Guide by Salaboy.
the class AsyncWorkItemWaitForCompletionTest method initializeSession.
private void initializeSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
//We are using a proces containing a single Task. The task is configured
//to wait until the completion of the external system. A specialized
//callback (CompleteWorkItemCallback) is used to complete the work item
//after the command was executed.
kbuilder.add(new ClassPathResource("async-work-item-wait.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors errors = kbuilder.getErrors();
for (KnowledgeBuilderError error : errors) {
System.out.println(">>> Error:" + error.getMessage());
}
throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
session.addEventListener(new DefaultAgendaEventListener() {
@Override
public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
session.fireAllRules();
}
});
//Registers the session in SessionStoreUtil. The callback we are using
//for the process' Task will retrieve this session later and completes
//the work item using it.
SessionStoreUtil.sessionCache.put("sessionId=" + session.getId(), session);
}
use of org.drools.io.impl.ClassPathResource in project jBPM5-Developer-Guide by Salaboy.
the class GenericWebServiceTaskTest method initializeSession.
private void initializeSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("HospitalInvokeInsuranceScenarioV3-data.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors errors = kbuilder.getErrors();
for (KnowledgeBuilderError error : errors) {
System.out.println(">>> Error:" + error.getMessage());
}
throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
session.addEventListener(new DefaultAgendaEventListener() {
@Override
public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
session.fireAllRules();
}
});
}
use of org.drools.io.impl.ClassPathResource in project jBPM5-Developer-Guide by Salaboy.
the class HospitalInsuranceProcessExecutorTest method initializeSession.
private void initializeSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("InsuranceProcessV2.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors errors = kbuilder.getErrors();
for (KnowledgeBuilderError error : errors) {
System.out.println(">>> Error:" + error.getMessage());
}
throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
session.addEventListener(new DefaultAgendaEventListener() {
@Override
public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
session.fireAllRules();
}
});
//Registers the same generic handler for all the tasks. The handler will
//schedule commands into the Executor Service. Each task in the process
//is configured to use a different command.
AsyncGenericWorkItemHandler genericHandler = new AsyncGenericWorkItemHandler(executor, session.getId());
session.getWorkItemManager().registerWorkItemHandler("Gather Patient Data", genericHandler);
session.getWorkItemManager().registerWorkItemHandler("Insurance Service", genericHandler);
session.getWorkItemManager().registerWorkItemHandler("External Insurance Company Service", genericHandler);
session.getWorkItemManager().registerWorkItemHandler("Rates Service", genericHandler);
session.getWorkItemManager().registerWorkItemHandler("Invoice Service", genericHandler);
}
use of org.drools.io.impl.ClassPathResource in project jBPM5-Developer-Guide by Salaboy.
the class HospitalInsuranceProcessTest method initializeSession.
private void initializeSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("InsuranceProcessV1.bpmn"), ResourceType.BPMN2);
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors errors = kbuilder.getErrors();
for (KnowledgeBuilderError error : errors) {
System.out.println(">>> Error:" + error.getMessage());
}
throw new IllegalStateException(">>> Knowledge couldn't be parsed! ");
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
session = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLoggerFactory.newConsoleLogger(session);
session.addEventListener(new DefaultAgendaEventListener() {
@Override
public void afterRuleFlowGroupActivated(org.drools.event.rule.RuleFlowGroupActivatedEvent event) {
session.fireAllRules();
}
});
//Registers an independent mocked work item handler for each task present
//in the process.
PatientDataServiceWorkItemHandler patientDataHandler = new PatientDataServiceWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Gather Patient Data", patientDataHandler);
InsuranceServiceWorkItemHandler insuranceServiceHandler = new InsuranceServiceWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Insurance Service", insuranceServiceHandler);
CompanyGatewayWorkItemHandler companyGatewayHandler = new CompanyGatewayWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("External Insurance Company Service", companyGatewayHandler);
RatesServiceWorkItemHandler ratesServiceHandler = new RatesServiceWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Rates Service", ratesServiceHandler);
InvoiceServiceWorkItemHandler invoiceServiceHandler = new InvoiceServiceWorkItemHandler();
session.getWorkItemManager().registerWorkItemHandler("Invoice Service", invoiceServiceHandler);
}
Aggregations