Search in sources :

Example 6 with JPATaskLifeCycleEventListener

use of org.jbpm.services.task.audit.JPATaskLifeCycleEventListener in project jbpm by kiegroup.

the class AuditTaskDeleteTest method produceTaskInstances.

private void produceTaskInstances() {
    InternalTaskService taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).listener(new JPATaskLifeCycleEventListener(true)).listener(new BAMTaskEventListener(true)).getTaskService();
    Calendar cal = randomCal();
    String processId = "process";
    taskTestData = new Task[10];
    List<ProcessInstanceLog> pLogs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        cal.add(Calendar.HOUR_OF_DAY, 1);
        Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").setProcessId(processId + i).setProcessInstanceId(i).setCreatedOn(cal.getTime()).getTask();
        taskService.addTask(task, new HashMap<String, Object>());
        taskTestData[i] = task;
        ProcessInstanceLog plog = buildCompletedProcessInstance(i);
        pLogs.add(plog);
    }
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    Object tx = jtaHelper.joinTransaction(em);
    pLogs.forEach(pl -> {
        em.persist(pl);
    });
    jtaHelper.leaveTransaction(em, tx);
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) TaskFluent(org.jbpm.services.task.utils.TaskFluent) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) InternalTaskService(org.kie.internal.task.api.InternalTaskService) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) EntityManager(javax.persistence.EntityManager) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 7 with JPATaskLifeCycleEventListener

use of org.jbpm.services.task.audit.JPATaskLifeCycleEventListener in project jbpm by kiegroup.

the class DefaultRegisterableItemsFactory method getTaskListeners.

@Override
public List<TaskLifeCycleEventListener> getTaskListeners() {
    List<TaskLifeCycleEventListener> defaultListeners = new ArrayList<TaskLifeCycleEventListener>();
    defaultListeners.add(new JPATaskLifeCycleEventListener(true));
    // add any custom listeners
    defaultListeners.addAll(super.getTaskListeners());
    // add listeners from deployment descriptor
    defaultListeners.addAll(getTaskListenersFromDescriptor());
    return defaultListeners;
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) ArrayList(java.util.ArrayList) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 8 with JPATaskLifeCycleEventListener

use of org.jbpm.services.task.audit.JPATaskLifeCycleEventListener in project jbpm by kiegroup.

the class HumanTaskServiceProducer method configureHumanTaskConfigurator.

protected void configureHumanTaskConfigurator(HumanTaskConfigurator configurator) {
    configurator.environment(getEnvironment(identityProvider)).entityManagerFactory(emf).userGroupCallback(safeGet(userGroupCallback)).userInfo(safeGet(userInfo));
    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);
    }
    // next proceed with registration of further listeners as cdi injections
    try {
        for (TaskLifeCycleEventListener listener : taskListeners) {
            configurator.listener(listener);
            logger.debug("Registering listener {}", listener);
        }
    } catch (Exception e) {
        logger.debug("Cannot add listeners to task service due to {}", e.getMessage());
    }
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) 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) AmbiguousResolutionException(javax.enterprise.inject.AmbiguousResolutionException) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 9 with JPATaskLifeCycleEventListener

use of org.jbpm.services.task.audit.JPATaskLifeCycleEventListener in project jbpm by kiegroup.

the class CustomTaskEventListenerProducer method getEventListeners.

@Override
public List<TaskLifeCycleEventListener> getEventListeners(String identifier, Map<String, Object> params) {
    List<TaskLifeCycleEventListener> taskEventListeners = new ArrayList<TaskLifeCycleEventListener>();
    taskEventListeners.add(new JPATaskLifeCycleEventListener(true));
    return taskEventListeners;
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) ArrayList(java.util.ArrayList) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 10 with JPATaskLifeCycleEventListener

use of org.jbpm.services.task.audit.JPATaskLifeCycleEventListener in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionCustomTaskServiceFactory.

@Test
public void testCreationOfSessionCustomTaskServiceFactory() {
    final AtomicBoolean customTaskServiceUsed = new AtomicBoolean(false);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("org.kie.internal.runtime.manager.TaskServiceFactory", new TaskServiceFactory() {

        private EntityManagerFactory emf;

        public EntityManagerFactory produceEntityManagerFactory() {
            if (this.emf == null) {
                this.emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
            }
            return this.emf;
        }

        @Override
        public TaskService newTaskService() {
            customTaskServiceUsed.set(true);
            return HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(produceEntityManagerFactory()).listener(new JPATaskLifeCycleEventListener(true)).getTaskService();
        }

        @Override
        public void close() {
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    // ksession for process instance #1
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id == 1);
    // FIXME quick hack to overcome problems with same pi ids when not using persistence
    ksession.startProcess("ScriptTask");
    // ksession for process instance #2
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    long ksession2Id = ksession2.getIdentifier();
    assertTrue(ksession2Id == 2);
    ProcessInstance pi1 = ksession.startProcess("UserTask");
    ProcessInstance pi2 = ksession2.startProcess("UserTask");
    // both processes started
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
    ksession = runtime.getKieSession();
    assertEquals(ksession1Id, ksession.getIdentifier());
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
    ksession2 = runtime2.getKieSession();
    assertEquals(ksession2Id, ksession2.getIdentifier());
    manager.close();
    // check if our custom task service factory was used
    assertTrue(customTaskServiceUsed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskServiceFactory(org.kie.internal.runtime.manager.TaskServiceFactory) HumanTaskServiceFactory(org.jbpm.services.task.HumanTaskServiceFactory) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) EntityManagerFactory(javax.persistence.EntityManagerFactory) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Aggregations

JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)10 BAMTaskEventListener (org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener)7 Before (org.junit.Before)4 ArrayList (java.util.ArrayList)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)3 TaskLifeCycleEventListener (org.kie.api.task.TaskLifeCycleEventListener)3 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 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 PostConstruct (javax.annotation.PostConstruct)1 AmbiguousResolutionException (javax.enterprise.inject.AmbiguousResolutionException)1 EntityManager (javax.persistence.EntityManager)1 ProcessInstanceLog (org.jbpm.process.audit.ProcessInstanceLog)1 StandaloneJtaStrategy (org.jbpm.process.audit.strategy.StandaloneJtaStrategy)1 HumanTaskConfigurator (org.jbpm.services.task.HumanTaskConfigurator)1 HumanTaskServiceFactory (org.jbpm.services.task.HumanTaskServiceFactory)1 LoadBalanceAssignmentStrategy (org.jbpm.services.task.assignment.impl.strategy.LoadBalanceAssignmentStrategy)1 TaskFluent (org.jbpm.services.task.utils.TaskFluent)1