Search in sources :

Example 26 with UserGroupCallback

use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.

the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTAfterWithGlobalTestService.

@Test(timeout = 20000)
public void testInterediateTimerWithHTAfterWithGlobalTestService() throws Exception {
    NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
    // prepare listener to assert results
    final List<Long> timerExpirations = new ArrayList<Long>();
    ProcessEventListener listener = new DefaultProcessEventListener() {

        @Override
        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            if (event.getNodeInstance().getNodeName().equals("timer")) {
                timerExpirations.add(event.getProcessInstance().getId());
            }
        }
    };
    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/IntermediateCatchEventTimerCycleWithHT.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).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("x", "R3/PT1S");
    ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    logger.debug("Disposed after start");
    // dispose session to force session to be reloaded on timer expiration
    manager.disposeRuntimeEngine(runtime);
    countDownListener.waitTillCompleted();
    countDownListener.reset(1);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    ksession = runtime.getKieSession();
    // 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(3, tasks.size());
    for (TaskSummary task : tasks) {
        runtime.getTaskService().start(task.getId(), "john");
        runtime.getTaskService().complete(task.getId(), "john", null);
    }
    processInstance = ksession.getProcessInstance(processInstance.getId());
    assertNull(processInstance);
    // let's wait to ensure no more timers are expired and triggered
    countDownListener.waitTillCompleted(3000);
    manager.disposeRuntimeEngine(runtime);
    assertEquals(3, timerExpirations.size());
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ArrayList(java.util.ArrayList) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) TaskSummary(org.kie.api.task.model.TaskSummary) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Test(org.junit.Test)

Example 27 with UserGroupCallback

use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.

the class JBPMHelper method getUserGroupCallback.

@Deprecated
@SuppressWarnings("unchecked")
public static UserGroupCallback getUserGroupCallback() {
    Properties properties = getProperties();
    String className = properties.getProperty("taskservice.usergroupcallback");
    if (className != null) {
        try {
            Class<UserGroupCallback> clazz = (Class<UserGroupCallback>) Class.forName(className);
            return clazz.newInstance();
        } catch (Exception e) {
            throw new IllegalArgumentException("Cannot create instance of UserGroupCallback " + className, e);
        }
    } else {
        return new JBossUserGroupCallbackImpl("classpath:/usergroups.properties");
    }
}
Also used : JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback)

Example 28 with UserGroupCallback

use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.

the class LDAPUserGroupCallbackImplTest method testGroupsForUser.

@Test
public void testGroupsForUser() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.CUSTOM);
    Assertions.assertThat(ldapUserGroupCallback).isNotNull();
    List<String> userGroups = ldapUserGroupCallback.getGroupsForUser("john");
    Assertions.assertThat(userGroups).hasSize(1);
}
Also used : UserGroupCallback(org.kie.api.task.UserGroupCallback) Test(org.junit.Test)

Example 29 with UserGroupCallback

use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.

the class LDAPUserGroupCallbackImplTest method testGroupExists.

@Test
public void testGroupExists() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.CUSTOM);
    Assertions.assertThat(ldapUserGroupCallback).isNotNull();
    boolean groupExists = ldapUserGroupCallback.existsGroup("manager");
    Assertions.assertThat(groupExists).isTrue();
}
Also used : UserGroupCallback(org.kie.api.task.UserGroupCallback) Test(org.junit.Test)

Example 30 with UserGroupCallback

use of org.kie.api.task.UserGroupCallback in project jbpm by kiegroup.

the class LDAPUserGroupCallbackImplTest method testUsersSubtreeScopeBaseDnContext.

@Test
public void testUsersSubtreeScopeBaseDnContext() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallbackWithUserCtx(SearchScope.SUBTREE_SCOPE, "dc=jbpm,dc=org");
    assertUsers(ldapUserGroupCallback, true, true, true, true);
}
Also used : UserGroupCallback(org.kie.api.task.UserGroupCallback) Test(org.junit.Test)

Aggregations

UserGroupCallback (org.kie.api.task.UserGroupCallback)47 Test (org.junit.Test)41 Properties (java.util.Properties)10 ArrayList (java.util.ArrayList)8 JBossUserGroupCallbackImpl (org.jbpm.services.task.identity.JBossUserGroupCallbackImpl)8 HashMap (java.util.HashMap)7 KieSession (org.kie.api.runtime.KieSession)6 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)6 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)6 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)5 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)5 List (java.util.List)4 Status (org.kie.api.task.model.Status)4 TaskSummary (org.kie.api.task.model.TaskSummary)4 UserTransaction (javax.transaction.UserTransaction)3 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)3 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)3 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)3 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)3 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)3