use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateBoundaryTimerWithGlobalTestServiceRollback.
@Test(timeout = 20000)
public void testInterediateBoundaryTimerWithGlobalTestServiceRollback() throws Exception {
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/HumanTaskWithBoundaryTimer.bpmn"), ResourceType.BPMN2).schedulerService(globalScheduler).userGroupCallback(userGroupCallback).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
long ksessionId = ksession.getIdentifier();
ProcessInstance processInstance;
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
Map<String, Object> params = new HashMap<String, Object>();
params.put("test", "john");
processInstance = ksession.startProcess("PROCESS_1", params);
} finally {
ut.rollback();
}
manager.disposeRuntimeEngine(runtime);
try {
// two types of checks as different managers will treat it differently
// per process instance will fail on getting runtime
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
// where singleton and per request will return runtime but there should not be process instance
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
}
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
assertNotNull(timerInstances);
assertEquals(0, timerInstances.size());
if (runtime != null) {
manager.disposeRuntimeEngine(runtime);
}
}
use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.
the class TaskServiceEJBImpl method configureDelegate.
@PostConstruct
public void configureDelegate() {
UserGroupCallback callback = UserDataServiceProvider.getUserGroupCallback();
HumanTaskConfigurator configurator = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).userGroupCallback(callback);
DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
DeploymentDescriptor descriptor = manager.getDefaultDescriptor();
// in case there is descriptor with enabled audit register then by default
if (!descriptor.getAuditMode().equals(AuditMode.NONE)) {
JPATaskLifeCycleEventListener listener = new JPATaskLifeCycleEventListener(false);
BAMTaskEventListener bamListener = new BAMTaskEventListener(false);
// if the audit persistence unit is different than default for the engine perform proper init
if (!"org.jbpm.domain".equals(descriptor.getAuditPersistenceUnit())) {
EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(descriptor.getAuditPersistenceUnit());
listener = new JPATaskLifeCycleEventListener(emf);
bamListener = new BAMTaskEventListener(emf);
}
configurator.listener(listener);
configurator.listener(bamListener);
}
delegate = (InternalTaskService) configurator.getTaskService();
}
use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.
the class ChecklistExample method main.
public static void main(String[] args) {
try {
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(new UserGroupCallback() {
public List<String> getGroupsForUser(String userId) {
List<String> result = new ArrayList<String>();
if ("actor4".equals(userId)) {
result.add("group1");
}
return result;
}
public boolean existsUser(String arg0) {
return true;
}
public boolean existsGroup(String arg0) {
return true;
}
}).addAsset(KieServices.Factory.get().getResources().newClassPathResource("checklist/SampleChecklistProcess.bpmn"), ResourceType.BPMN2).get();
ChecklistManager checklistManager = new DefaultChecklistManager(environment);
long c1 = checklistManager.createContext("org.jbpm.examples.checklist.sample1", "actor1");
List<ChecklistItem> items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task1");
ChecklistItem item1 = findChecklistItem(items, "Task1");
checklistManager.completeTask("actor1", item1.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Adding Extra Task");
String[] actorIds = new String[] { "actor5" };
ChecklistItem itemExtra = checklistManager.addTask("actor5", actorIds, new String[0], "TaskExtra", "2+", c1);
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task2");
ChecklistItem item2 = findChecklistItem(items, "Task2");
checklistManager.claimTask("actor4", item2.getTaskId());
checklistManager.completeTask("actor4", item2.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task3b");
ChecklistItem item3b = findChecklistItem(items, "Task3b");
checklistManager.claimTask("actor3", item3b.getTaskId());
checklistManager.completeTask("actor3", item3b.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task3a");
ChecklistItem item3a = findChecklistItem(items, "Task3a");
checklistManager.completeTask("actor1", item3a.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Extra Task");
itemExtra = findChecklistItem(items, "TaskExtra");
checklistManager.completeTask("actor5", itemExtra.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
System.out.println("Completing Task4");
ChecklistItem item4 = findChecklistItem(items, "Task4");
checklistManager.completeTask("actor1", item4.getTaskId());
items = checklistManager.getTasks(c1, null);
printChecklistItems(items, c1);
} catch (Throwable t) {
t.printStackTrace();
}
System.exit(0);
}
use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.
the class GlobalQuartzDBTimerServiceTest method testTimerRequiresRecoveryFlagSet.
@Test(timeout = 20000)
public void testTimerRequiresRecoveryFlagSet() throws Exception {
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/HumanTaskWithBoundaryTimer.bpmn"), ResourceType.BPMN2).schedulerService(globalScheduler).userGroupCallback(userGroupCallback).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
Map<String, Object> params = new HashMap<String, Object>();
params.put("test", "john");
ProcessInstance processInstance = ksession.startProcess("PROCESS_1", params);
Connection connection = null;
Statement stmt = null;
try {
connection = ((DataSource) InitialContext.doLookup("jdbc/jbpm-ds")).getConnection();
stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("select REQUESTS_RECOVERY from QRTZ_JOB_DETAILS");
while (resultSet.next()) {
boolean requestsRecovery = resultSet.getBoolean(1);
assertEquals("Requests recovery must be set to true", true, requestsRecovery);
}
} finally {
if (stmt != null) {
stmt.close();
}
if (connection != null) {
connection.close();
}
}
ksession.abortProcessInstance(processInstance.getId());
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback.
@Test(timeout = 20000)
public void testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback() throws Exception {
// prepare listener to assert results
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT2.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).userGroupCallback(userGroupCallback).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
long ksessionId = ksession.getIdentifier();
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "R3/PT1S");
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// get tasks
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Reserved);
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwnerByStatus("john", statuses, "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
runtime.getTaskService().start(task.getId(), "john");
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
runtime.getTaskService().complete(task.getId(), "john", null);
} finally {
ut.rollback();
}
processInstance = ksession.getProcessInstance(processInstance.getId());
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance) processInstance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertTrue(activeNodes.iterator().next() instanceof HumanTaskNodeInstance);
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
assertNotNull(timerInstances);
assertEquals(0, timerInstances.size());
// clean up
ksession.abortProcessInstance(processInstance.getId());
manager.disposeRuntimeEngine(runtime);
}
Aggregations