From 22e3f86e4ab6802c6a95a15809c0ad2e7caf5593 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Martinez Date: Wed, 22 Nov 2023 11:05:26 +0100 Subject: [PATCH] fix events --- .../process/ProcessInstanceSLAEventBody.java | 15 ++++++++++ .../event/impl/ProcessInstanceEventBatch.java | 29 +++++++++++-------- .../instance/event/UserTaskEventImpl.java | 2 +- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceSLAEventBody.java b/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceSLAEventBody.java index a67aa2ca97b..133c0e57155 100644 --- a/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceSLAEventBody.java +++ b/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceSLAEventBody.java @@ -45,6 +45,16 @@ public class ProcessInstanceSLAEventBody { private String nodeType; + private Date slaDueDate; + + public Date getSlaDueDate() { + return slaDueDate; + } + + public void setSlaDueDate(Date slaDueDate) { + this.slaDueDate = slaDueDate; + } + public Date getEventDate() { return eventDate; } @@ -98,6 +108,11 @@ private Builder(ProcessInstanceSLAEventBody instance) { this.instance = instance; } + public Builder slaDueDate(Date slaDueDate) { + this.instance.slaDueDate = slaDueDate; + return this; + } + public Builder eventDate(Date eventDate) { this.instance.eventDate = eventDate; return this; diff --git a/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java b/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java index 7e950739fbf..96a34dba476 100644 --- a/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java +++ b/api/kogito-events-core/src/main/java/org/kie/kogito/event/impl/ProcessInstanceEventBatch.java @@ -18,6 +18,7 @@ */ package org.kie.kogito.event.impl; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -108,17 +109,17 @@ private void addDataEvent(ProcessEvent event) { } else if (event instanceof ProcessCompletedEvent) { handleProcessStateEvent((ProcessCompletedEvent) event); } else if (event instanceof ProcessNodeTriggeredEvent) { - handleProcesssNodeEvent((ProcessNodeTriggeredEvent) event); + handleProcessNodeEvent((ProcessNodeTriggeredEvent) event); } else if (event instanceof ProcessNodeLeftEvent) { - handleProcesssNodeEvent((ProcessNodeLeftEvent) event); + handleProcessNodeEvent((ProcessNodeLeftEvent) event); } else if (event instanceof SLAViolatedEvent) { handleProcesssNodeEvent((SLAViolatedEvent) event); } else if (event instanceof ProcessVariableChangedEvent) { - handleProcesssVariableEvent((ProcessVariableChangedEvent) event); + handleProcessVariableEvent((ProcessVariableChangedEvent) event); } } - private void handleProcesssVariableEvent(ProcessVariableChangedEvent event) { + private void handleProcessVariableEvent(ProcessVariableChangedEvent event) { Map metadata = buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance()); KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); @@ -154,17 +155,21 @@ private void handleProcesssNodeEvent(SLAViolatedEvent event) { KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); ProcessInstanceSLAEventBody.Builder builder = ProcessInstanceSLAEventBody.create() - .eventDate(new Date()) + .eventDate(Date.from(Instant.now())) .eventUser(event.getEventIdentity()) .processId(event.getProcessInstance().getProcessId()) .processVersion(event.getProcessInstance().getProcessVersion()) .processInstanceId(event.getProcessInstance().getId()); - if (event.getNodeInstance() != null) { - builder.nodeDefinitionId(event.getNodeInstance().getNode().getNodeUniqueId()) - .nodeInstanceId(event.getNodeInstance().getId()) - .nodeName(event.getNodeInstance().getNodeName()) - .nodeType(event.getNodeInstance().getNode().getClass().getSimpleName()); + if (event.getNodeInstance() instanceof KogitoNodeInstance) { + KogitoNodeInstance ni = (KogitoNodeInstance) event.getNodeInstance(); + builder.nodeDefinitionId(ni.getNode().getNodeUniqueId()) + .nodeInstanceId(ni.getId()) + .nodeName(ni.getNodeName()) + .nodeType(ni.getNode().getClass().getSimpleName()) + .slaDueDate(ni.getSlaDueDate()); + } else { + builder.slaDueDate(pi.getSlaDueDate()); } ProcessInstanceSLAEventBody body = builder.build(); @@ -173,7 +178,7 @@ private void handleProcesssNodeEvent(SLAViolatedEvent event) { processedEvents.add(piEvent); } - private void handleProcesssNodeEvent(ProcessNodeLeftEvent event) { + private void handleProcessNodeEvent(ProcessNodeLeftEvent event) { KogitoNodeInstance nodeInstance = (KogitoNodeInstance) event.getNodeInstance(); int eventType = ProcessInstanceNodeEventBody.EVENT_TYPE_EXIT; @@ -196,7 +201,7 @@ private void handleProcesssNodeEvent(ProcessNodeLeftEvent event) { processedEvents.add(toProcessInstanceNodeEvent(event, eventType)); } - private void handleProcesssNodeEvent(ProcessNodeTriggeredEvent event) { + private void handleProcessNodeEvent(ProcessNodeTriggeredEvent event) { processedEvents.add(toProcessInstanceNodeEvent(event, ProcessInstanceNodeEventBody.EVENT_TYPE_ENTER)); } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/event/UserTaskEventImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/event/UserTaskEventImpl.java index 8bdbb36f42f..dbc1920502f 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/event/UserTaskEventImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/event/UserTaskEventImpl.java @@ -90,7 +90,7 @@ public String getEventUser() { @Override public String getUserTaskDefinitionId() { - return getWorkItem().getStringId(); + return getHumanTaskNodeInstance().getNodeDefinitionId(); } }