Search in sources :

Example 1 with ProcessWorkItemTransitionEvent

use of org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent in project kogito-runtimes by kiegroup.

the class UserTaskIT method testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity.

@Test
public void testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    final List<String> workItemTransitionEvents = new ArrayList<>();
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(new DefaultKogitoProcessEventListener() {

        @Override
        public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("BEFORE:: " + event);
        }

        @Override
        public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("AFTER:: " + event);
        }
    });
    Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("FirstTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    assertEquals(0, wi.getResults().size());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Claim.ID, Collections.singletonMap("test", "value"), securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("FirstTask", wi.getName());
    assertEquals(Claim.ID, wi.getPhase());
    assertEquals(Claim.STATUS, wi.getPhaseStatus());
    assertEquals(2, wi.getResults().size());
    assertEquals("value", wi.getResults().get("test"));
    assertEquals("john", wi.getResults().get("ActorId"));
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("SecondTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    assertEquals(0, wi.getResults().size());
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    assertThat(workItemTransitionEvents).hasSize(10);
}
Also used : ProcessConfig(org.kie.kogito.process.ProcessConfig) HashMap(java.util.HashMap) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) HumanTaskTransition(org.jbpm.process.instance.impl.humantask.HumanTaskTransition) Model(org.kie.kogito.Model) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessWorkItemTransitionEvent

use of org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent in project kogito-runtimes by kiegroup.

the class UserTaskIT method testBasicUserTaskProcess.

@Test
public void testBasicUserTaskProcess() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    final List<String> workItemTransitionEvents = new ArrayList<>();
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(new DefaultKogitoProcessEventListener() {

        @Override
        public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("BEFORE:: " + event);
        }

        @Override
        public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("AFTER:: " + event);
        }
    });
    Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(workItemTransitionEvents).hasSize(8);
}
Also used : ProcessConfig(org.kie.kogito.process.ProcessConfig) HashMap(java.util.HashMap) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) DefaultKogitoProcessEventListener(org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) Model(org.kie.kogito.Model) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 3 with ProcessWorkItemTransitionEvent

use of org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent in project kogito-runtimes by kiegroup.

the class KogitoProcessEventSupportImpl method fireBeforeWorkItemTransition.

@Override
public void fireBeforeWorkItemTransition(final KogitoProcessInstance instance, KogitoWorkItem workitem, Transition<?> transition, KieRuntime kruntime) {
    final ProcessWorkItemTransitionEvent event = new KogitoProcessWorkItemTransitionEventImpl(instance, workitem, transition, kruntime, false);
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        if (hasListeners()) {
            notifyAllListeners(event, (l, e1) -> l.beforeWorkItemTransition(e1));
        }
    }));
}
Also used : ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) WorkUnit(org.kie.kogito.uow.WorkUnit) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) AbstractEventSupport(org.drools.core.event.AbstractEventSupport) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeadlineType(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent.DeadlineType) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) UnitOfWorkManager(org.kie.kogito.uow.UnitOfWorkManager) SLAViolatedEventImpl(org.drools.core.event.SLAViolatedEventImpl) SignalEvent(org.kie.api.event.process.SignalEvent) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) SignalEventImpl(org.drools.core.event.SignalEventImpl) ProcessCompletedEventImpl(org.drools.core.event.ProcessCompletedEventImpl) MessageEvent(org.kie.api.event.process.MessageEvent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) MessageEventImpl(org.drools.core.event.MessageEventImpl) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Transition(org.kie.kogito.process.workitem.Transition) KieRuntime(org.kie.api.runtime.KieRuntime) KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent)

Example 4 with ProcessWorkItemTransitionEvent

use of org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent in project kogito-runtimes by kiegroup.

the class KogitoProcessEventSupportImpl method fireAfterWorkItemTransition.

@Override
public void fireAfterWorkItemTransition(final KogitoProcessInstance instance, KogitoWorkItem workitem, Transition<?> transition, KieRuntime kruntime) {
    final ProcessWorkItemTransitionEvent event = new KogitoProcessWorkItemTransitionEventImpl(instance, workitem, transition, kruntime, true);
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        if (hasListeners()) {
            notifyAllListeners(event, (l, e1) -> l.afterWorkItemTransition(e1));
        }
    }));
}
Also used : ProcessStartedEventImpl(org.drools.core.event.ProcessStartedEventImpl) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) WorkUnit(org.kie.kogito.uow.WorkUnit) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) AbstractEventSupport(org.drools.core.event.AbstractEventSupport) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeadlineType(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent.DeadlineType) KogitoProcessEventListener(org.kie.kogito.internal.process.event.KogitoProcessEventListener) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) UnitOfWorkManager(org.kie.kogito.uow.UnitOfWorkManager) SLAViolatedEventImpl(org.drools.core.event.SLAViolatedEventImpl) SignalEvent(org.kie.api.event.process.SignalEvent) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) SignalEventImpl(org.drools.core.event.SignalEventImpl) ProcessCompletedEventImpl(org.drools.core.event.ProcessCompletedEventImpl) MessageEvent(org.kie.api.event.process.MessageEvent) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) MessageEventImpl(org.drools.core.event.MessageEventImpl) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Transition(org.kie.kogito.process.workitem.Transition) KieRuntime(org.kie.api.runtime.KieRuntime) KogitoProcessEventSupport(org.kie.kogito.internal.process.event.KogitoProcessEventSupport) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) SLAViolatedEvent(org.kie.api.event.process.SLAViolatedEvent) HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent)

Example 5 with ProcessWorkItemTransitionEvent

use of org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent in project kogito-runtimes by kiegroup.

the class ProcessInstanceEventBatch method events.

@Override
public Collection<DataEvent<?>> events() {
    Map<String, ProcessInstanceEventBody> processInstances = new LinkedHashMap<>();
    Map<String, UserTaskInstanceEventBody> userTaskInstances = new LinkedHashMap<>();
    Set<VariableInstanceEventBody> variables = new LinkedHashSet<>();
    Collection<DataEvent<?>> processedEvents = new ArrayList<>();
    for (ProcessEvent event : rawEvents) {
        ProcessInstanceEventBody body = processInstances.computeIfAbsent(((KogitoProcessInstance) event.getProcessInstance()).getStringId(), key -> create(event));
        if (event instanceof ProcessNodeTriggeredEvent) {
            handleProcessNodeTriggeredEvent((ProcessNodeTriggeredEvent) event, body);
        } else if (event instanceof ProcessNodeLeftEvent) {
            handleProcessNodeLeftEvent((ProcessNodeLeftEvent) event, body);
        } else if (event instanceof ProcessCompletedEvent) {
            handleProcessCompletedEvent((ProcessCompletedEvent) event, body);
        } else if (event instanceof ProcessWorkItemTransitionEvent) {
            handleProcessWorkItemTransitionEvent((ProcessWorkItemTransitionEvent) event, userTaskInstances);
        } else if (event instanceof ProcessVariableChangedEvent) {
            handleProcessVariableChangedEvent((KogitoProcessVariableChangedEvent) event, variables);
        } else if (event instanceof HumanTaskDeadlineEvent) {
            processedEvents.add(buildUserTaskDeadlineEvent((HumanTaskDeadlineEvent) event));
        }
    }
    processInstances.values().stream().map(pi -> new ProcessInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    userTaskInstances.values().stream().map(pi -> new UserTaskInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    variables.stream().map(pi -> new VariableInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    return processedEvents;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) KogitoProcessVariableChangedEvent(org.kie.kogito.internal.process.event.KogitoProcessVariableChangedEvent) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Addons(org.kie.kogito.Addons) LinkedHashSet(java.util.LinkedHashSet) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) EventBatch(org.kie.kogito.event.EventBatch) KogitoProcessVariableChangedEvent(org.kie.kogito.internal.process.event.KogitoProcessVariableChangedEvent) Collection(java.util.Collection) Set(java.util.Set) KogitoNodeInstance(org.kie.kogito.internal.process.runtime.KogitoNodeInstance) Collectors(java.util.stream.Collectors) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) ProcessNodeEvent(org.kie.api.event.process.ProcessNodeEvent) UserTaskDeadlineDataEvent(org.kie.kogito.services.event.UserTaskDeadlineDataEvent) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) DataEvent(org.kie.kogito.event.DataEvent) ProcessEvent(org.kie.api.event.process.ProcessEvent) HumanTaskWorkItem(org.kie.kogito.process.workitem.HumanTaskWorkItem) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) ProcessEvent(org.kie.api.event.process.ProcessEvent) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) UserTaskDeadlineDataEvent(org.kie.kogito.services.event.UserTaskDeadlineDataEvent) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) LinkedHashMap(java.util.LinkedHashMap) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent)

Aggregations

ProcessWorkItemTransitionEvent (org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)3 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)3 ProcessNodeTriggeredEvent (org.kie.api.event.process.ProcessNodeTriggeredEvent)3 ProcessVariableChangedEvent (org.kie.api.event.process.ProcessVariableChangedEvent)3 HumanTaskDeadlineEvent (org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent)3 KogitoNodeInstance (org.kie.kogito.internal.process.runtime.KogitoNodeInstance)3 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)3 KogitoWorkItem (org.kie.kogito.internal.process.runtime.KogitoWorkItem)3 HumanTaskWorkItem (org.kie.kogito.process.workitem.HumanTaskWorkItem)3 HashMap (java.util.HashMap)2 AbstractEventSupport (org.drools.core.event.AbstractEventSupport)2 MessageEventImpl (org.drools.core.event.MessageEventImpl)2 ProcessCompletedEventImpl (org.drools.core.event.ProcessCompletedEventImpl)2 ProcessStartedEventImpl (org.drools.core.event.ProcessStartedEventImpl)2 SLAViolatedEventImpl (org.drools.core.event.SLAViolatedEventImpl)2 SignalEventImpl (org.drools.core.event.SignalEventImpl)2