context = new ClassPathXmlApplicationContext("jbpm/jpa-local-lane/jpa-spring.xml");
EntityManagerFactory emf = (EntityManagerFactory) context.getBean("jbpmEMF");
AbstractPlatformTransactionManager aptm = (AbstractPlatformTransactionManager) context.getBean( "jbpmTxManager" );
Properties auth = new Properties();
auth.setProperty("max", "Standard");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(auth);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()
.entityManagerFactory(emf)
.userGroupCallback(userGroupCallback)
.addAsset(ResourceFactory.newClassPathResource("jbpm/processes/sample1.bpmn2"), ResourceType.BPMN2)
.addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, aptm)
.get();
RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = engine.getKieSession();
TaskService taskService = engine.getTaskService();
Map<String,Object> params = new HashMap<String,Object>();
params.put("userid", "max");
ProcessInstance processInstance = ksession.startProcess("agu.samples.sample1", params);
AuditLogService logService = (AuditLogService) context.getBean("logService");
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
TransactionStatus status = aptm.getTransaction(def);
ProcessInstanceLog log = logService.findProcessInstance(processInstance.getId());
assertNotNull(log);
aptm.commit(status);
List<TaskSummary> tasks = taskService.getTasksOwned("max", "en-UK");
System.out.println("Found " + tasks.size() + " task(s) for user 'max'");
long taskId = tasks.get(0).getId();