Search in sources :

Example 1 with UserTaskInstanceDataEvent

use of org.kie.kogito.services.event.UserTaskInstanceDataEvent in project kogito-runtimes by kiegroup.

the class PublishEventIT method assertUserTaskInstanceEvent.

protected UserTaskInstanceEventBody assertUserTaskInstanceEvent(DataEvent<?> event, String taskName, String taskDescription, String taskPriority, String taskState, String processId, String nodeName) {
    assertThat(event).isInstanceOf(UserTaskInstanceDataEvent.class);
    UserTaskInstanceEventBody body = ((UserTaskInstanceDataEvent) event).getData();
    assertThat(body).isNotNull();
    assertThat(body.getId()).isNotNull();
    assertThat(body.getTaskName()).isEqualTo(taskName);
    assertThat(body.getTaskDescription()).isEqualTo(taskDescription);
    assertThat(body.getReferenceName()).isEqualTo(nodeName);
    assertThat(body.getTaskPriority()).isEqualTo(taskPriority);
    assertThat(body.getStartDate()).isNotNull();
    assertThat(body.getState()).isEqualTo(taskState);
    if (taskState.equals("Completed") || taskState.equals("Aborted")) {
        assertThat(body.getCompleteDate()).isNotNull();
    } else {
        assertThat(body.getCompleteDate()).isNull();
    }
    assertThat(event.getSource().toString()).isEqualTo("http://myhost/" + processId);
    assertThat(event.getTime()).isBeforeOrEqualTo(ZonedDateTime.now().toOffsetDateTime());
    assertThat(((UserTaskInstanceDataEvent) event).getKogitoAddons()).isEqualTo("test");
    return body;
}
Also used : UserTaskInstanceEventBody(org.kie.kogito.services.event.impl.UserTaskInstanceEventBody) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent)

Example 2 with UserTaskInstanceDataEvent

use of org.kie.kogito.services.event.UserTaskInstanceDataEvent in project kogito-runtimes by kiegroup.

the class MongoDBEventPublisherTest method testPublishEvents_withTransaction.

@Test
void testPublishEvents_withTransaction() {
    ClientSession clientSession = mock(ClientSession.class);
    when(transactionManager.getClientSession()).thenReturn(clientSession);
    when(transactionManager.enabled()).thenReturn(true);
    publisher.configure();
    List<DataEvent<?>> events = new ArrayList<>();
    events.add(processInstanceDataEvent);
    events.add(userTaskInstanceDataEvent);
    events.add(variableInstanceDataEvent);
    events.add(event);
    publisher.publish(events);
    verify(mongoCollection, times(3)).insertOne(eq(clientSession), any(AbstractDataEvent.class));
    verify(mongoCollection, times(3)).deleteOne(eq(clientSession), any());
    verify(mongoCollection).insertOne(eq(clientSession), eq(processInstanceDataEvent));
    verify(mongoCollection).deleteOne(eq(clientSession), eq(Filters.eq(ID, "testProcessInstanceEvent")));
    verify(mongoCollection).insertOne(eq(clientSession), eq(userTaskInstanceDataEvent));
    verify(mongoCollection).deleteOne(eq(clientSession), eq(Filters.eq(ID, "testUserTaskInstanceEvent")));
    verify(mongoCollection).insertOne(eq(clientSession), eq(variableInstanceDataEvent));
    verify(mongoCollection).deleteOne(eq(clientSession), eq(Filters.eq(ID, "testVariableInstanceEvent")));
}
Also used : ClientSession(com.mongodb.client.ClientSession) ArrayList(java.util.ArrayList) AbstractDataEvent(org.kie.kogito.event.AbstractDataEvent) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) AbstractDataEvent(org.kie.kogito.event.AbstractDataEvent) Test(org.junit.jupiter.api.Test)

Example 3 with UserTaskInstanceDataEvent

use of org.kie.kogito.services.event.UserTaskInstanceDataEvent in project kogito-runtimes by kiegroup.

the class UserTaskInstanceDataEventCodecTest method setUp.

@BeforeEach
void setUp() {
    codec = new UserTaskInstanceDataEventCodec();
    String source = "testSource";
    String kogitoAddons = "testKogitoAddons";
    Comment comment = new Comment("testCommentId", "testCommentUpdatedBy");
    comment.setContent("testCommentContent");
    comment.setUpdatedAt(new Date());
    Set<Comment> comments = Collections.singleton(comment);
    Attachment attachment = new Attachment("testAttachmentId", "testAttachmentUpdatedBy");
    attachment.setContent(URI.create("test.attachment.test"));
    attachment.setName("testAttachmentName");
    attachment.setUpdatedAt(new Date());
    Set<Attachment> attachments = Collections.singleton(attachment);
    Map<String, String> metaData = new HashMap<>();
    metaData.put(ProcessInstanceEventBody.ID_META_DATA, "testKogitoProcessinstanceId");
    metaData.put(ProcessInstanceEventBody.ROOT_ID_META_DATA, "testKogitoRootProcessinstanceId");
    metaData.put(ProcessInstanceEventBody.PROCESS_ID_META_DATA, "testKogitoProcessId");
    metaData.put(ProcessInstanceEventBody.ROOT_PROCESS_ID_META_DATA, "testKogitoRootProcessId");
    metaData.put(UserTaskInstanceEventBody.UT_STATE_META_DATA, "testKogitoUserTaskinstanceState");
    metaData.put(UserTaskInstanceEventBody.UT_ID_META_DATA, "testKogitoUserTaskinstanceId");
    UserTaskInstanceEventBody body = UserTaskInstanceEventBody.create().id("testId").taskName("testTaskName").taskDescription("testTaskDescription").taskPriority("testTaskPriority").referenceName("testReferenceName").startDate(new Date()).completeDate(new Date()).state("testState").actualOwner("testActualOwner").potentialUsers(Collections.singleton("testPotentialUsers")).potentialGroups(Collections.singleton("testPotentialGroups")).excludedUsers(Collections.singleton("testExcludedUsers")).adminUsers(Collections.singleton("testAdminUsers")).adminGroups(Collections.singleton("testAdminGroups")).inputs(Collections.singletonMap("testInputsKey", "testInputsValue")).outputs(Collections.singletonMap("testOutputsKey", "testOutputsValue")).processInstanceId("testKogitoProcessinstanceId").rootProcessInstanceId("testKogitoRootProcessinstanceId").processId("testKogitoProcessId").rootProcessId("testKogitoRootProcessId").comments(comments).attachments(attachments).build();
    event = new UserTaskInstanceDataEvent(source, kogitoAddons, metaData, body);
}
Also used : Comment(org.kie.kogito.process.workitem.Comment) HashMap(java.util.HashMap) Attachment(org.kie.kogito.process.workitem.Attachment) UserTaskInstanceEventBody(org.kie.kogito.services.event.impl.UserTaskInstanceEventBody) BsonString(org.bson.BsonString) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with UserTaskInstanceDataEvent

use of org.kie.kogito.services.event.UserTaskInstanceDataEvent 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

UserTaskInstanceDataEvent (org.kie.kogito.services.event.UserTaskInstanceDataEvent)4 ArrayList (java.util.ArrayList)2 DataEvent (org.kie.kogito.event.DataEvent)2 ProcessInstanceDataEvent (org.kie.kogito.services.event.ProcessInstanceDataEvent)2 VariableInstanceDataEvent (org.kie.kogito.services.event.VariableInstanceDataEvent)2 UserTaskInstanceEventBody (org.kie.kogito.services.event.impl.UserTaskInstanceEventBody)2 ClientSession (com.mongodb.client.ClientSession)1 Collection (java.util.Collection)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 BsonString (org.bson.BsonString)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ProcessCompletedEvent (org.kie.api.event.process.ProcessCompletedEvent)1