Search in sources :

Example 1 with VariableInstanceEventBody

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

the class VariableInstanceDataEventCodecTest method setUp.

@BeforeEach
void setUp() {
    codec = new VariableInstanceDataEventCodec();
    String source = "testSource";
    String kogitoAddons = "testKogitoAddons";
    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");
    VariableInstanceEventBody body = VariableInstanceEventBody.create().changeDate(new Date()).changedByNodeId("testChangedByNodeId").changedByNodeName("testChangedByNodeName").changedByNodeType("testChangedByNodeType").changedByUser("testChangedByUser").processId("testKogitoProcessId").processInstanceId("testKogitoProcessinstanceId").rootProcessId("testKogitoRootProcessId").rootProcessInstanceId("testKogitoRootProcessinstanceId").variableName("testVariableName").variablePreviousValue("testVariablePreviousValue").variableValue("testVariableValue").build();
    event = new VariableInstanceDataEvent(source, kogitoAddons, metaData, body);
}
Also used : HashMap(java.util.HashMap) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) BsonString(org.bson.BsonString) VariableInstanceEventBody(org.kie.kogito.event.process.VariableInstanceEventBody) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with VariableInstanceEventBody

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

the class ProcessInstanceEventBatch method create.

protected VariableInstanceEventBody create(KogitoProcessVariableChangedEvent event) {
    KogitoProcessInstance pi = (KogitoProcessInstance) event.getProcessInstance();
    VariableInstanceEventBody.Builder eventBuilder = VariableInstanceEventBody.create().changeDate(event.getEventDate()).processId(pi.getProcessId()).processInstanceId(pi.getStringId()).rootProcessId(pi.getRootProcessId()).rootProcessInstanceId(pi.getRootProcessInstanceId()).variableName(event.getVariableId()).variableValue(event.getNewValue()).variablePreviousValue(event.getOldValue());
    if (event.getNodeInstance() != null) {
        eventBuilder.changedByNodeId(event.getNodeInstance().getNodeDefinitionId()).changedByNodeName(event.getNodeInstance().getNodeName()).changedByNodeType(event.getNodeInstance().getNode().getClass().getSimpleName());
    }
    return eventBuilder.build();
}
Also used : KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) VariableInstanceEventBody(org.kie.kogito.event.process.VariableInstanceEventBody)

Example 3 with VariableInstanceEventBody

use of org.kie.kogito.event.process.VariableInstanceEventBody 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) Comment(org.kie.kogito.process.workitem.Comment) ProcessErrorEventBody(org.kie.kogito.event.process.ProcessErrorEventBody) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) MilestoneEventBody(org.kie.kogito.event.process.MilestoneEventBody) KogitoWorkItem(org.kie.kogito.internal.process.runtime.KogitoWorkItem) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) Function(java.util.function.Function) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) UserTaskInstanceEventBody(org.kie.kogito.event.process.UserTaskInstanceEventBody) ProcessInstanceEventBody(org.kie.kogito.event.process.ProcessInstanceEventBody) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) Map(java.util.Map) KogitoWorkflowProcessInstance(org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance) NodeInstanceEventBody(org.kie.kogito.event.process.NodeInstanceEventBody) Addons(org.kie.kogito.Addons) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) LinkedHashSet(java.util.LinkedHashSet) ProcessVariableChangedEvent(org.kie.api.event.process.ProcessVariableChangedEvent) CommentEventBody(org.kie.kogito.event.process.CommentEventBody) EventBatch(org.kie.kogito.event.EventBatch) Attachment(org.kie.kogito.process.workitem.Attachment) 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) VariableInstanceEventBody(org.kie.kogito.event.process.VariableInstanceEventBody) List(java.util.List) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) Collectors.toList(java.util.stream.Collectors.toList) ProcessNodeEvent(org.kie.api.event.process.ProcessNodeEvent) UserTaskDeadlineDataEvent(org.kie.kogito.event.process.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) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) AttachmentEventBody(org.kie.kogito.event.process.AttachmentEventBody) UserTaskDeadlineEventBody(org.kie.kogito.event.process.UserTaskDeadlineEventBody) HumanTaskDeadlineEvent(org.kie.kogito.internal.process.event.HumanTaskDeadlineEvent) ProcessEvent(org.kie.api.event.process.ProcessEvent) ProcessInstanceEventBody(org.kie.kogito.event.process.ProcessInstanceEventBody) ProcessWorkItemTransitionEvent(org.kie.kogito.internal.process.event.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) UserTaskInstanceEventBody(org.kie.kogito.event.process.UserTaskInstanceEventBody) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) UserTaskDeadlineDataEvent(org.kie.kogito.event.process.UserTaskDeadlineDataEvent) DataEvent(org.kie.kogito.event.DataEvent) ProcessCompletedEvent(org.kie.api.event.process.ProcessCompletedEvent) LinkedHashMap(java.util.LinkedHashMap) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) VariableInstanceEventBody(org.kie.kogito.event.process.VariableInstanceEventBody)

Example 4 with VariableInstanceEventBody

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

the class PublishEventIT method testBusinessRuleProcessStartToEndWithVariableTracked.

@Test
public void testBusinessRuleProcessStartToEndWithVariableTracked() throws Exception {
    Map<TYPE, List<String>> resourcesTypeMap = new HashMap<>();
    resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("ruletask/BusinessRuleTaskVariableTags.bpmn2"));
    resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/BusinessRuleTask.drl"));
    Application app = generateCode(resourcesTypeMap);
    assertThat(app).isNotNull();
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleTask");
    Model m = p.createModel();
    m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKey("person");
    assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
    uow.end();
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(3);
    DataEvent<?> event = events.get(0);
    assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
    ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
    assertThat(processDataEvent.getKogitoProcessinstanceId()).isNotNull();
    assertThat(processDataEvent.getKogitoParentProcessinstanceId()).isNull();
    assertThat(processDataEvent.getKogitoRootProcessinstanceId()).isNull();
    assertThat(processDataEvent.getKogitoProcessId()).isEqualTo("BusinessRuleTask");
    assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
    assertThat(processDataEvent.getSource().toString()).isEqualTo("http://myhost/BusinessRuleTask");
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "BusinessRuleTask", "Default Process", 2);
    assertThat(body.getNodeInstances()).hasSize(3).extractingResultOf("getNodeType").contains("StartNode", "RuleSetNode", "EndNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
    assertThat(body.getVariables()).hasSize(1).containsKey("person");
    assertThat(body.getVariables().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
    event = events.get(1);
    assertThat(event).isInstanceOf(VariableInstanceDataEvent.class);
    VariableInstanceDataEvent variableDataEvent = (VariableInstanceDataEvent) event;
    assertThat(variableDataEvent.getKogitoProcessinstanceId()).isNotNull();
    assertThat(variableDataEvent.getKogitoRootProcessId()).isNull();
    assertThat(variableDataEvent.getKogitoRootProcessinstanceId()).isNull();
    assertThat(variableDataEvent.getKogitoProcessId()).isEqualTo("BusinessRuleTask");
    // first is event created based on process start so no node associated
    VariableInstanceEventBody variableEventBody = variableDataEvent.getData();
    assertThat(variableEventBody).isNotNull();
    assertThat(variableEventBody.getChangeDate()).isNotNull();
    assertThat(variableEventBody.getProcessInstanceId()).isEqualTo(variableDataEvent.getKogitoProcessinstanceId());
    assertThat(variableEventBody.getProcessId()).isEqualTo("BusinessRuleTask");
    assertThat(variableEventBody.getRootProcessId()).isNull();
    assertThat(variableEventBody.getRootProcessInstanceId()).isNull();
    assertThat(variableEventBody.getVariableName()).isEqualTo("person");
    assertThat(variableEventBody.getVariableValue()).isNotNull();
    assertThat(variableEventBody.getVariablePreviousValue()).isNull();
    assertThat(variableEventBody.getChangedByNodeId()).isNull();
    assertThat(variableEventBody.getChangedByNodeName()).isNull();
    assertThat(variableEventBody.getChangedByNodeType()).isNull();
    assertThat(variableEventBody.getChangedByUser()).isNull();
    event = events.get(2);
    assertThat(event).isInstanceOf(VariableInstanceDataEvent.class);
    variableDataEvent = (VariableInstanceDataEvent) event;
    assertThat(variableDataEvent.getKogitoProcessinstanceId()).isNotNull();
    assertThat(variableDataEvent.getKogitoRootProcessId()).isNull();
    assertThat(variableDataEvent.getKogitoRootProcessinstanceId()).isNull();
    assertThat(variableDataEvent.getKogitoProcessId()).isEqualTo("BusinessRuleTask");
    // next is event created based on business rule task so node associated
    variableEventBody = variableDataEvent.getData();
    assertThat(variableEventBody).isNotNull();
    assertThat(variableEventBody.getChangeDate()).isNotNull();
    assertThat(variableEventBody.getProcessInstanceId()).isEqualTo(variableDataEvent.getKogitoProcessinstanceId());
    assertThat(variableEventBody.getProcessId()).isEqualTo("BusinessRuleTask");
    assertThat(variableEventBody.getRootProcessId()).isNull();
    assertThat(variableEventBody.getRootProcessInstanceId()).isNull();
    assertThat(variableEventBody.getVariableName()).isEqualTo("person");
    assertThat(variableEventBody.getVariableValue()).isNotNull();
    assertThat(variableEventBody.getVariablePreviousValue()).isNotNull();
    assertThat(variableEventBody.getChangedByNodeId()).isEqualTo("BusinessRuleTask_2");
    assertThat(variableEventBody.getChangedByNodeName()).isEqualTo("Business Rule Task");
    assertThat(variableEventBody.getChangedByNodeType()).isEqualTo("RuleSetNode");
    assertThat(variableEventBody.getChangedByUser()).isNull();
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(org.kie.kogito.event.process.ProcessInstanceEventBody) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) Processes(org.kie.kogito.process.Processes) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) Model(org.kie.kogito.Model) ArrayList(java.util.ArrayList) List(java.util.List) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) VariableInstanceEventBody(org.kie.kogito.event.process.VariableInstanceEventBody) Test(org.junit.jupiter.api.Test)

Aggregations

VariableInstanceEventBody (org.kie.kogito.event.process.VariableInstanceEventBody)4 VariableInstanceDataEvent (org.kie.kogito.event.process.VariableInstanceDataEvent)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DataEvent (org.kie.kogito.event.DataEvent)2 ProcessInstanceDataEvent (org.kie.kogito.event.process.ProcessInstanceDataEvent)2 ProcessInstanceEventBody (org.kie.kogito.event.process.ProcessInstanceEventBody)2 UserTaskInstanceDataEvent (org.kie.kogito.event.process.UserTaskInstanceDataEvent)2 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)2 Collection (java.util.Collection)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 BsonString (org.bson.BsonString)1