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);
}
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();
}
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;
}
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();
}
Aggregations