Search in sources :

Example 21 with UserGroupCallback

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);
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) HashMap(java.util.HashMap) JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback) TimerService(org.drools.core.time.TimerService) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Example 22 with UserGroupCallback

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();
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) HumanTaskConfigurator(org.jbpm.services.task.HumanTaskConfigurator) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) EntityManagerFactory(javax.persistence.EntityManagerFactory) DeploymentDescriptorManager(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager) UserGroupCallback(org.kie.api.task.UserGroupCallback) PostConstruct(javax.annotation.PostConstruct)

Example 23 with UserGroupCallback

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);
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ChecklistManager(org.jbpm.examples.checklist.ChecklistManager) ChecklistItem(org.jbpm.examples.checklist.ChecklistItem) List(java.util.List) ArrayList(java.util.ArrayList) UserGroupCallback(org.kie.api.task.UserGroupCallback)

Example 24 with UserGroupCallback

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);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) Statement(java.sql.Statement) Connection(java.sql.Connection) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback) ResultSet(java.sql.ResultSet) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 25 with UserGroupCallback

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);
}
Also used : Status(org.kie.api.task.model.Status) UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) HashMap(java.util.HashMap) JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) ArrayList(java.util.ArrayList) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback) TimerService(org.drools.core.time.TimerService) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) NodeInstance(org.kie.api.runtime.process.NodeInstance) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) 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