use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.
the class DefaultRegisterableItemsFactory method getTaskListenersFromDescriptor.
protected List<TaskLifeCycleEventListener> getTaskListenersFromDescriptor() {
List<TaskLifeCycleEventListener> defaultListeners = new ArrayList<TaskLifeCycleEventListener>();
DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
if (descriptor != null) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("runtimeManager", getRuntimeManager());
params.put("classLoader", getRuntimeManager().getEnvironment().getClassLoader());
params.put("kieContainer", getRuntimeManager().getKieContainer());
for (ObjectModel model : descriptor.getTaskEventListeners()) {
Object taskListener = getInstanceFromModel(model, getRuntimeManager().getEnvironment().getClassLoader(), params);
if (taskListener != null) {
defaultListeners.add((TaskLifeCycleEventListener) taskListener);
}
}
}
return defaultListeners;
}
use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithCustomTaskListener.
@Test
public void testCreationOfSessionWithCustomTaskListener() {
final List<Long> addedTasks = new ArrayList<Long>();
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).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<TaskLifeCycleEventListener> getTaskListeners() {
List<TaskLifeCycleEventListener> listeners = super.getTaskListeners();
listeners.add(new DefaultTaskEventListener() {
@Override
public void afterTaskAddedEvent(TaskEvent event) {
addedTasks.add(event.getTask().getId());
}
});
return listeners;
}
}).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());
assertEquals(2, addedTasks.size());
manager.close();
}
use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.
the class TaskEventSupport method fireBeforeTaskUpdated.
public void fireBeforeTaskUpdated(final Task task, TaskContext context) {
final Iterator<TaskLifeCycleEventListener> iter = getEventListenersIterator();
if (iter.hasNext()) {
do {
TaskLifeCycleEventListener listener = iter.next();
listener.beforeTaskUpdatedEvent(new TaskEventImpl(task, context));
} while (iter.hasNext());
}
}
use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.
the class TaskEventSupport method fireBeforeTaskAssignmentsAddedEvent.
public void fireBeforeTaskAssignmentsAddedEvent(final Task task, TaskContext context, AssignmentType type, List<OrganizationalEntity> entities) {
final Iterator<TaskLifeCycleEventListener> iter = getEventListenersIterator();
if (iter.hasNext()) {
do {
TaskLifeCycleEventListener listener = iter.next();
listener.beforeTaskAssignmentsAddedEvent(new TaskEventImpl(task, context), type, entities);
} while (iter.hasNext());
}
}
use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.
the class TaskEventSupport method fireAfterTaskInputVariablesChanged.
public void fireAfterTaskInputVariablesChanged(final Task task, TaskContext context, Map<String, Object> variables) {
final Iterator<TaskLifeCycleEventListener> iter = getEventListenersIterator();
if (iter.hasNext()) {
do {
TaskLifeCycleEventListener listener = iter.next();
listener.afterTaskInputVariableChangedEvent(new TaskEventImpl(task, context), variables);
} while (iter.hasNext());
}
}
Aggregations