Search in sources :

Example 1 with TaskLifeCycleEventListener

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;
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ArrayList(java.util.ArrayList) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 2 with TaskLifeCycleEventListener

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();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ArrayList(java.util.ArrayList) DefaultTaskEventListener(org.jbpm.services.task.events.DefaultTaskEventListener) TaskEvent(org.kie.api.task.TaskEvent) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 3 with TaskLifeCycleEventListener

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());
    }
}
Also used : TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 4 with TaskLifeCycleEventListener

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());
    }
}
Also used : TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 5 with TaskLifeCycleEventListener

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());
    }
}
Also used : TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Aggregations

TaskLifeCycleEventListener (org.kie.api.task.TaskLifeCycleEventListener)27 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 EventService (org.kie.internal.task.api.EventService)6 JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 HashMap (java.util.HashMap)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 KieSession (org.kie.api.runtime.KieSession)3 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 DefaultTaskEventListener (org.jbpm.services.task.events.DefaultTaskEventListener)2 RegisterableItemsFactory (org.kie.api.runtime.manager.RegisterableItemsFactory)2 TaskEvent (org.kie.api.task.TaskEvent)2 TaskService (org.kie.api.task.TaskService)2 TaskSummary (org.kie.api.task.model.TaskSummary)2 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)2 List (java.util.List)1