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);
}
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;
}
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());
}
}
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;
}
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());
}
Aggregations