Search in sources :

Example 1 with BAMTaskEventListener

use of org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener in project jbpm by kiegroup.

the class LocalTaskAuditWithDeadlineTest method setup.

@Before
public void setup() {
    TaskDeadlinesServiceImpl.reset();
    pds = setupPoolingDataSource();
    emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
    this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).listener(new JPATaskLifeCycleEventListener(true)).listener(new BAMTaskEventListener(true)).getTaskService();
    this.taskAuditService = TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService();
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) Before(org.junit.Before)

Example 2 with BAMTaskEventListener

use of org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener in project jbpm by kiegroup.

the class TotalCompletionTimeAssignmentStrategyTest method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("org.jbpm.task.assignment.enabled", "true");
    System.setProperty("org.jbpm.task.assignment.strategy", "LoadBalance");
    System.setProperty("org.jbpm.task.assignment.loadbalance.calculator", "org.jbpm.services.task.assignment.impl.TotalCompletionTimeLoadCalculator");
    System.setProperty("org.jbpm.services.task.assignment.taskduration.timetolive", "1000");
    pds = setupPoolingDataSource();
    emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
    AssignmentServiceProvider.override(new LoadBalanceAssignmentStrategy());
    this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).listener(new JPATaskLifeCycleEventListener(true)).listener(new BAMTaskEventListener(true)).getTaskService();
    // giving ourselves lots of room
    taskIds = new Long[100];
    forceBAMEntries();
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) LoadBalanceAssignmentStrategy(org.jbpm.services.task.assignment.impl.strategy.LoadBalanceAssignmentStrategy) Before(org.junit.Before)

Example 3 with BAMTaskEventListener

use of org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener in project jbpm by kiegroup.

the class LocalTaskAuditTest method setup.

@Before
public void setup() {
    pds = setupPoolingDataSource();
    emf = Persistence.createEntityManagerFactory("org.jbpm.services.task");
    this.taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).listener(new JPATaskLifeCycleEventListener(true)).listener(new BAMTaskEventListener(true)).getTaskService();
    this.taskAuditService = TaskAuditServiceFactory.newTaskAuditServiceConfigurator().setTaskService(taskService).getTaskAuditService();
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) Before(org.junit.Before)

Example 4 with BAMTaskEventListener

use of org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener in project jbpm by kiegroup.

the class ProcessPersistenceHumanTaskOnLaneTest method testProcessWithBAMListener.

@SuppressWarnings("unchecked")
@Test
public void testProcessWithBAMListener() throws Exception {
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new BAMTaskEventListener(true));
    ProcessInstance processInstance = ksession.startProcess("UserTask");
    assertProcessInstanceActive(processInstance.getId());
    long task1 = -1;
    long task2 = -1;
    // simulating a system restart
    logger.debug("Reloading the environemnt to simulate system restart");
    disposeRuntimeManager();
    createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
    runtimeEngine = getRuntimeEngine();
    ksession = runtimeEngine.getKieSession();
    taskService = runtimeEngine.getTaskService();
    ((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new BAMTaskEventListener(true));
    // let john execute Task 1
    String taskUser = "john";
    String locale = "en-UK";
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner(taskUser, locale);
    assertEquals(1, list.size());
    TaskSummary task = list.get(0);
    task1 = task.getId();
    taskService.claim(task.getId(), taskUser);
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    List<Status> reservedOnly = new ArrayList<Status>();
    reservedOnly.add(Status.Reserved);
    list = taskService.getTasksAssignedAsPotentialOwnerByStatus(taskUser, reservedOnly, locale);
    assertEquals(1, list.size());
    task = list.get(0);
    task2 = task.getId();
    taskService.start(task.getId(), taskUser);
    taskService.complete(task.getId(), taskUser, null);
    assertProcessInstanceCompleted(processInstance.getId());
    EntityManager em = getEmf().createEntityManager();
    List<BAMTaskSummaryImpl> bamLogs = em.createQuery("from BAMTaskSummaryImpl").getResultList();
    em.close();
    assertNotNull(bamLogs);
    assertEquals(2, bamLogs.size());
    List<Long> taskIdsFromBAM = new ArrayList<Long>();
    for (BAMTaskSummaryImpl bamEntry : bamLogs) {
        taskIdsFromBAM.add(bamEntry.getTaskId());
    }
    assertTrue(taskIdsFromBAM.contains(task1));
    assertTrue(taskIdsFromBAM.contains(task2));
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) EventService(org.kie.internal.task.api.EventService) EntityManager(javax.persistence.EntityManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) BAMTaskSummaryImpl(org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl) Test(org.junit.Test)

Example 5 with BAMTaskEventListener

use of org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener 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)

Aggregations

BAMTaskEventListener (org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener)8 JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)7 Before (org.junit.Before)4 ArrayList (java.util.ArrayList)2 EntityManager (javax.persistence.EntityManager)2 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 DeploymentDescriptorManager (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorManager)2 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 PostConstruct (javax.annotation.PostConstruct)1 AmbiguousResolutionException (javax.enterprise.inject.AmbiguousResolutionException)1 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)1 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)1 HumanTaskConfigurator (org.jbpm.services.task.HumanTaskConfigurator)1 LoadBalanceAssignmentStrategy (org.jbpm.services.task.assignment.impl.strategy.LoadBalanceAssignmentStrategy)1 BAMTaskSummaryImpl (org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl)1 TaskFluent (org.jbpm.services.task.utils.TaskFluent)1 Test (org.junit.Test)1 KieSession (org.kie.api.runtime.KieSession)1