diff --git a/api/kogito-api/src/main/java/org/kie/kogito/internal/process/runtime/KogitoNodeInstance.java b/api/kogito-api/src/main/java/org/kie/kogito/internal/process/runtime/KogitoNodeInstance.java index f91e8b1957f..a1483dd85ef 100644 --- a/api/kogito-api/src/main/java/org/kie/kogito/internal/process/runtime/KogitoNodeInstance.java +++ b/api/kogito-api/src/main/java/org/kie/kogito/internal/process/runtime/KogitoNodeInstance.java @@ -18,7 +18,9 @@ */ package org.kie.kogito.internal.process.runtime; +import java.util.Collections; import java.util.Date; +import java.util.Map; import org.kie.api.runtime.process.NodeInstance; @@ -67,4 +69,10 @@ default boolean isCancelled() { * @return actual leave time */ Date getLeaveTime(); + + Date getSlaDueDate(); + + default Map getMetaData() { + return Collections.emptyMap(); + } } diff --git a/api/kogito-api/src/main/java/org/kie/kogito/internal/process/runtime/KogitoWorkflowProcessInstance.java b/api/kogito-api/src/main/java/org/kie/kogito/internal/process/runtime/KogitoWorkflowProcessInstance.java index 078a9908541..7023cb28904 100644 --- a/api/kogito-api/src/main/java/org/kie/kogito/internal/process/runtime/KogitoWorkflowProcessInstance.java +++ b/api/kogito-api/src/main/java/org/kie/kogito/internal/process/runtime/KogitoWorkflowProcessInstance.java @@ -50,6 +50,8 @@ public interface KogitoWorkflowProcessInstance extends WorkflowProcessInstance, */ String getNodeIdInError(); + String getNodeInstanceIdInError(); + /** * Returns error message associated with this process instance in case it is in an error * state. It will consists of @@ -88,4 +90,6 @@ public interface KogitoWorkflowProcessInstance extends WorkflowProcessInstance, */ Collection adHocFragments(); + Date getSlaDueDate(); + } diff --git a/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceNodeEventBody.java b/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceNodeEventBody.java index 704f9be1ac4..ca6621c0b14 100644 --- a/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceNodeEventBody.java +++ b/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceNodeEventBody.java @@ -29,6 +29,14 @@ public class ProcessInstanceNodeEventBody { public static final int EVENT_TYPE_EXIT = 2; + public static final int EVENT_TYPE_ABORTED = 3; + + public static final int EVENT_TYPE_SKIPPED = 4; + + public static final int EVENT_TYPE_OBSOLETE = 5; + + public static final int EVENT_TYPE_ERROR = 6; + // common fields for events private Date eventDate; @@ -47,7 +55,7 @@ public class ProcessInstanceNodeEventBody { // custom data fields - private String connectionNodeInstanceId; // only for entering and leaving + private String connectionNodeDefinitionId; // only for entering and leaving private String nodeDefinitionId; // definition on bpmn2 @@ -57,6 +65,10 @@ public class ProcessInstanceNodeEventBody { private String nodeInstanceId; + private String workItemId; + + private Date slaDueDate; + private Map data; private ProcessInstanceNodeEventBody() { @@ -87,8 +99,8 @@ public String getProcessInstanceId() { return processInstanceId; } - public String getConnectionNodeInstanceId() { - return connectionNodeInstanceId; + public String getConnectionNodeDefinitionId() { + return connectionNodeDefinitionId; } public String getNodeDefinitionId() { @@ -107,6 +119,14 @@ public String getNodeInstanceId() { return nodeInstanceId; } + public Date getSlaDueDate() { + return slaDueDate; + } + + public String getWorkItemId() { + return workItemId; + } + public Map getData() { return data; } @@ -114,7 +134,7 @@ public Map getData() { @Override public String toString() { return "ProcessInstanceNodeEventBody [eventDate=" + eventDate + ", eventUser=" + eventUser + ", eventType=" + eventType + ", processId=" + processId + ", processVersion=" + processVersion - + ", processInstanceId=" + processInstanceId + ", connectionNodeInstanceId=" + connectionNodeInstanceId + ", nodeDefinitionId=" + nodeDefinitionId + ", nodeName=" + nodeName + + ", processInstanceId=" + processInstanceId + ", connectionNodeInstanceId=" + connectionNodeDefinitionId + ", nodeDefinitionId=" + nodeDefinitionId + ", nodeName=" + nodeName + ", nodeType=" + nodeType + ", nodeInstanceId=" + nodeInstanceId + ", data=" + data + "]"; } @@ -181,8 +201,8 @@ public Builder processInstanceId(String processInstanceId) { return this; } - public Builder connectionNodeInstanceId(String connectionNodeInstanceId) { - instance.connectionNodeInstanceId = connectionNodeInstanceId; + public Builder connectionNodeDefinitionId(String connectionNodeDefinitionId) { + instance.connectionNodeDefinitionId = connectionNodeDefinitionId; return this; } @@ -211,8 +231,20 @@ public Builder data(String name, Object value) { return this; } + public Builder slaDueDate(Date slaDueDate) { + instance.slaDueDate = slaDueDate; + return this; + } + + public Builder workItemId(String workItemId) { + instance.workItemId = workItemId; + return this; + } + public ProcessInstanceNodeEventBody build() { return instance; } + } + } 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 91fc9f75ec8..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 @@ -41,6 +41,20 @@ public class ProcessInstanceSLAEventBody { private String nodeInstanceId; + private String nodeName; + + private String nodeType; + + private Date slaDueDate; + + public Date getSlaDueDate() { + return slaDueDate; + } + + public void setSlaDueDate(Date slaDueDate) { + this.slaDueDate = slaDueDate; + } + public Date getEventDate() { return eventDate; } @@ -69,6 +83,14 @@ public String getNodeInstanceId() { return nodeInstanceId; } + public String getNodeName() { + return nodeName; + } + + public String getNodeType() { + return nodeType; + } + @Override public String toString() { return "ProcessErrorEventBody [processId=" + processId + ", processInstanceId=" + processInstanceId + ", nodeDefinitionId=" + nodeDefinitionId + ", nodeInstanceId=" + nodeInstanceId + "]"; @@ -86,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; @@ -121,8 +148,19 @@ public Builder nodeDefinitionId(String nodeDefinitionId) { return this; } + public Builder nodeName(String nodeName) { + instance.nodeName = nodeName; + return this; + } + + public Builder nodeType(String nodeType) { + instance.nodeType = nodeType; + return this; + } + public ProcessInstanceSLAEventBody build() { return instance; } } + } diff --git a/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceStateEventBody.java b/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceStateEventBody.java index a6cc39229b9..6c7b7a80c3f 100644 --- a/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceStateEventBody.java +++ b/api/kogito-events-api/src/main/java/org/kie/kogito/event/process/ProcessInstanceStateEventBody.java @@ -62,6 +62,8 @@ public class ProcessInstanceStateEventBody { private Set roles; + public Date slaDueDate; + public Date getEventDate() { return eventDate; } @@ -118,6 +120,10 @@ public Set getRoles() { return roles; } + public Date getSlaDueDate() { + return slaDueDate; + } + public Builder update() { return new Builder(this); } @@ -245,8 +251,14 @@ public Builder roles(String... roles) { return this; } + public Builder slaDueDate(Date slaDueDate) { + instance.slaDueDate = slaDueDate; + return this; + } + public ProcessInstanceStateEventBody build() { return instance; } + } } diff --git a/api/kogito-events-api/src/main/java/org/kie/kogito/event/usertask/UserTaskInstanceStateEventBody.java b/api/kogito-events-api/src/main/java/org/kie/kogito/event/usertask/UserTaskInstanceStateEventBody.java index 336f7fb4188..a8423c45355 100644 --- a/api/kogito-events-api/src/main/java/org/kie/kogito/event/usertask/UserTaskInstanceStateEventBody.java +++ b/api/kogito-events-api/src/main/java/org/kie/kogito/event/usertask/UserTaskInstanceStateEventBody.java @@ -35,9 +35,6 @@ public class UserTaskInstanceStateEventBody { private String userTaskInstanceId; private String userTaskName; - // custom data fields - private Integer eventType; // CREATED, ADDED, CLAIMED.... - private String userTaskDescription; private String userTaskPriority; private String userTaskReferenceName; @@ -48,6 +45,8 @@ public class UserTaskInstanceStateEventBody { private String processInstanceId; + private String eventType; + public Date getEventDate() { return eventDate; } @@ -68,10 +67,6 @@ public String getUserTaskName() { return userTaskName; } - public Integer getEventType() { - return eventType; - } - public String getUserTaskDescription() { return userTaskDescription; } @@ -96,6 +91,10 @@ public String getProcessInstanceId() { return processInstanceId; } + public String getEventType() { + return eventType; + } + public Map metaData() { Map metadata = new HashMap<>(); metadata.put(UserTaskInstanceEventMetadata.USER_TASK_INSTANCE_ID_META_DATA, userTaskInstanceId); @@ -107,7 +106,7 @@ public Map metaData() { @Override public String toString() { return "UserTaskInstanceStateEventBody [eventDate=" + eventDate + ", eventUser=" + eventUser + ", userTaskDefinitionId=" + userTaskDefinitionId + ", userTaskInstanceId=" + userTaskInstanceId - + ", userTaskName=" + userTaskName + ", eventType=" + eventType + ", userTaskDescription=" + userTaskDescription + ", userTaskPriority=" + userTaskPriority + ", userTaskReferenceName=" + + ", userTaskName=" + userTaskName + ", userTaskDescription=" + userTaskDescription + ", userTaskPriority=" + userTaskPriority + ", userTaskReferenceName=" + userTaskReferenceName + ", state=" + state + ", actualOwner=" + actualOwner + ", processInstanceId=" + processInstanceId + "]"; } @@ -170,11 +169,6 @@ public Builder userTaskName(String userTaskName) { return this; } - public Builder eventType(Integer eventType) { - this.instance.eventType = eventType; - return this; - } - public Builder userTaskDescription(String userTaskDescription) { this.instance.userTaskDescription = userTaskDescription; return this; @@ -200,6 +194,11 @@ public Builder actualOwner(String userId) { return this; } + public Builder eventType(String eventType) { + this.instance.eventType = eventType; + return this; + } + public Builder processInstanceId(String processInstanceId) { this.instance.processInstanceId = processInstanceId; return this; @@ -209,4 +208,5 @@ public UserTaskInstanceStateEventBody build() { return this.instance; } } + } 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 3991c65da02..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,11 +18,13 @@ */ package org.kie.kogito.event.impl; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import org.kie.api.event.process.ProcessCompletedEvent; import org.kie.api.event.process.ProcessEvent; @@ -66,7 +68,11 @@ import org.kie.kogito.event.usertask.UserTaskInstanceStateEventBody; import org.kie.kogito.event.usertask.UserTaskInstanceVariableDataEvent; import org.kie.kogito.event.usertask.UserTaskInstanceVariableEventBody; +import org.kie.kogito.internal.process.event.KogitoProcessVariableChangedEvent; +import org.kie.kogito.internal.process.runtime.KogitoNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoProcessInstance; +import org.kie.kogito.internal.process.runtime.KogitoWorkItem; +import org.kie.kogito.internal.process.runtime.KogitoWorkItemNodeInstance; import org.kie.kogito.internal.process.runtime.KogitoWorkflowProcessInstance; import org.kie.kogito.process.workitem.HumanTaskWorkItem; @@ -103,23 +109,20 @@ 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) { - // custom data fields for this event that are not there - // private String nodeContainerDefinitionId; - // private String nodeContainerInstanceId; + private void handleProcessVariableEvent(ProcessVariableChangedEvent event) { Map metadata = buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance()); - + KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); ProcessInstanceVariableEventBody.Builder builder = ProcessInstanceVariableEventBody.create() .eventDate(new Date()) .eventUser(event.getEventIdentity()) @@ -130,41 +133,83 @@ private void handleProcesssVariableEvent(ProcessVariableChangedEvent event) { .variableName(event.getVariableId()) .variableValue(event.getNewValue()); + if (event instanceof KogitoProcessVariableChangedEvent) { + KogitoProcessVariableChangedEvent varEvent = (KogitoProcessVariableChangedEvent) event; + if (varEvent.getNodeInstance() != null && varEvent.getNodeInstance().getNodeInstanceContainer() != null) { + if (varEvent.getNodeInstance().getNodeInstanceContainer() instanceof KogitoNodeInstance) { + builder.nodeContainerDefinitionId(((KogitoNodeInstance) varEvent.getNodeInstance().getNodeInstanceContainer()).getNodeDefinitionId()); + builder.nodeContainerInstanceId(((KogitoNodeInstance) varEvent.getNodeInstance().getNodeInstanceContainer()).getId()); + } + } + } + ProcessInstanceVariableEventBody body = builder.build(); - processedEvents.add(new ProcessInstanceVariableDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body)); + ProcessInstanceVariableDataEvent piEvent = + new ProcessInstanceVariableDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body); + piEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(piEvent); } private void handleProcesssNodeEvent(SLAViolatedEvent event) { Map metadata = buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance()); + 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()); + 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(); - processedEvents.add(new ProcessInstanceSLADataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body)); + ProcessInstanceSLADataEvent piEvent = new ProcessInstanceSLADataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body); + piEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(piEvent); } - private void handleProcesssNodeEvent(ProcessNodeLeftEvent event) { - processedEvents.add(toProcessInstanceNodeEvent(event, ProcessInstanceNodeEventBody.EVENT_TYPE_EXIT)); + private void handleProcessNodeEvent(ProcessNodeLeftEvent event) { + KogitoNodeInstance nodeInstance = (KogitoNodeInstance) event.getNodeInstance(); + int eventType = ProcessInstanceNodeEventBody.EVENT_TYPE_EXIT; + + if (nodeInstance.getCancelType() != null) { + switch (nodeInstance.getCancelType()) { + case ABORTED: + eventType = ProcessInstanceNodeEventBody.EVENT_TYPE_ABORTED; + break; + case SKIPPED: + eventType = ProcessInstanceNodeEventBody.EVENT_TYPE_SKIPPED; + break; + case OBSOLETE: + eventType = ProcessInstanceNodeEventBody.EVENT_TYPE_OBSOLETE; + break; + case ERROR: + eventType = ProcessInstanceNodeEventBody.EVENT_TYPE_ERROR; + } + } + + processedEvents.add(toProcessInstanceNodeEvent(event, eventType)); } - private void handleProcesssNodeEvent(ProcessNodeTriggeredEvent event) { + private void handleProcessNodeEvent(ProcessNodeTriggeredEvent event) { processedEvents.add(toProcessInstanceNodeEvent(event, ProcessInstanceNodeEventBody.EVENT_TYPE_ENTER)); } private ProcessInstanceNodeDataEvent toProcessInstanceNodeEvent(ProcessNodeEvent event, int eventType) { Map metadata = buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance()); - + KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); + KogitoNodeInstance nodeInstance = (KogitoNodeInstance) event.getNodeInstance(); ProcessInstanceNodeEventBody.Builder builder = ProcessInstanceNodeEventBody.create() .eventDate(new Date()) .eventUser(event.getEventIdentity()) @@ -175,10 +220,26 @@ private ProcessInstanceNodeDataEvent toProcessInstanceNodeEvent(ProcessNodeEvent .nodeName(event.getNodeInstance().getNodeName()) .nodeType(event.getNodeInstance().getNode().getClass().getSimpleName()) .nodeInstanceId(event.getNodeInstance().getId()) - .nodeDefinitionId(event.getNodeInstance().getNode().getNodeUniqueId()); + .nodeDefinitionId(event.getNodeInstance().getNode().getNodeUniqueId()) + .slaDueDate(nodeInstance.getSlaDueDate()); + + if (eventType == ProcessInstanceNodeEventBody.EVENT_TYPE_ENTER) { + builder.connectionNodeDefinitionId((String) nodeInstance.getMetaData().get("IncomingConnection")); + } else { + builder.connectionNodeDefinitionId((String) nodeInstance.getMetaData().get("OutgoingConnection")); + } + + if (nodeInstance instanceof KogitoWorkItemNodeInstance) { + KogitoWorkItem workItem = ((KogitoWorkItemNodeInstance) nodeInstance).getWorkItem(); + if (workItem != null) { + builder.workItemId(workItem.getStringId()); + } + } ProcessInstanceNodeEventBody body = builder.build(); - return new ProcessInstanceNodeDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body); + ProcessInstanceNodeDataEvent piEvent = new ProcessInstanceNodeDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body); + piEvent.setKogitoBusinessKey(pi.getBusinessKey()); + return piEvent; } private void handleProcessStateEvent(ProcessCompletedEvent event) { @@ -194,10 +255,14 @@ private void handleProcessStateEvent(ProcessCompletedEvent event) { .processId(pi.getProcessId()) .processVersion(pi.getProcessVersion()) .nodeDefinitionId(pi.getNodeIdInError()) + .nodeInstanceId(pi.getNodeInstanceIdInError()) .errorMessage(pi.getErrorMessage()) .build(); Map metadata = buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance()); - processedEvents.add(new ProcessInstanceErrorDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, errorBody)); + ProcessInstanceErrorDataEvent piEvent = + new ProcessInstanceErrorDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, errorBody); + piEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(piEvent); } } @@ -213,10 +278,14 @@ private void handleProcessStateEvent(ProcessStartedEvent event) { .processId(pi.getProcessId()) .processVersion(pi.getProcessVersion()) .nodeDefinitionId(pi.getNodeIdInError()) + .nodeInstanceId(pi.getNodeInstanceIdInError()) .errorMessage(pi.getErrorMessage()) .build(); Map metadata = buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance()); - processedEvents.add(new ProcessInstanceErrorDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, errorBody)); + ProcessInstanceErrorDataEvent piEvent = + new ProcessInstanceErrorDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, errorBody); + piEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(piEvent); } } @@ -239,7 +308,8 @@ private ProcessInstanceStateDataEvent toProcessInstanceStateEvent(ProcessEvent e .parentInstanceId(pi.getParentProcessInstanceId()) .rootProcessId(pi.getRootProcessId()) .rootProcessInstanceId(pi.getRootProcessInstanceId()) - .state(event.getProcessInstance().getState()); + .state(event.getProcessInstance().getState()) + .slaDueDate(pi.getSlaDueDate()); String securityRoles = (String) event.getProcessInstance().getProcess().getMetaData().get("securityRoles"); if (securityRoles != null) { @@ -247,7 +317,9 @@ private ProcessInstanceStateDataEvent toProcessInstanceStateEvent(ProcessEvent e } ProcessInstanceStateEventBody body = builder.build(); - return new ProcessInstanceStateDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body); + ProcessInstanceStateDataEvent piEvent = new ProcessInstanceStateDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventIdentity(), metadata, body); + piEvent.setKogitoBusinessKey(pi.getBusinessKey()); + return piEvent; } private Map buildProcessMetadata(KogitoWorkflowProcessInstance pi) { @@ -283,6 +355,7 @@ private void addDataEvent(UserTaskEvent event) { private void handleUserTaskCommentEvent(UserTaskCommentEvent event) { Map metadata = buildUserTaskMetadata((HumanTaskWorkItem) event.getWorkItem()); metadata.putAll(buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance())); + KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); int eventType = UserTaskInstanceCommentEventBody.EVENT_TYPE_ADDED; if (event.getOldComment() != null && event.getNewComment() == null) { @@ -317,13 +390,16 @@ private void handleUserTaskCommentEvent(UserTaskCommentEvent event) { } UserTaskInstanceCommentEventBody body = builder.build(); - processedEvents.add(new UserTaskInstanceCommentDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), updatedBy, metadata, body)); + UserTaskInstanceCommentDataEvent utEvent = new UserTaskInstanceCommentDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), updatedBy, metadata, body); + utEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(utEvent); } private void handleUserTaskAttachmentEvent(UserTaskAttachmentEvent event) { Map metadata = buildUserTaskMetadata((HumanTaskWorkItem) event.getWorkItem()); metadata.putAll(buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance())); + KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); int eventType = UserTaskInstanceAttachmentEventBody.EVENT_TYPE_ADDED; if (event.getOldAttachment() != null && event.getNewAttachment() == null) { @@ -359,15 +435,16 @@ private void handleUserTaskAttachmentEvent(UserTaskAttachmentEvent event) { } UserTaskInstanceAttachmentEventBody body = builder.build(); - processedEvents - .add(new UserTaskInstanceAttachmentDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), updatedBy, metadata, body)); + UserTaskInstanceAttachmentDataEvent utEvent = new UserTaskInstanceAttachmentDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), updatedBy, metadata, body); + utEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(utEvent); } private void handleUserTaskAssignmentEvent(UserTaskAssignmentEvent event) { Map metadata = buildUserTaskMetadata((HumanTaskWorkItem) event.getWorkItem()); metadata.putAll(buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance())); - + KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); UserTaskInstanceAssignmentEventBody.Builder builder = UserTaskInstanceAssignmentEventBody.create() .eventDate(new Date()) .eventUser(event.getEventUser()) @@ -378,13 +455,16 @@ private void handleUserTaskAssignmentEvent(UserTaskAssignmentEvent event) { .users(event.getNewUsersId()); UserTaskInstanceAssignmentEventBody body = builder.build(); - processedEvents.add(new UserTaskInstanceAssignmentDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventUser(), metadata, body)); + UserTaskInstanceAssignmentDataEvent utEvent = + new UserTaskInstanceAssignmentDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventUser(), metadata, body); + utEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(utEvent); } private void handleUserTaskDeadlineEvent(UserTaskDeadlineEvent event) { Map metadata = buildUserTaskMetadata((HumanTaskWorkItem) event.getWorkItem()); metadata.putAll(buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance())); - + KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); UserTaskInstanceDeadlineEventBody.Builder builder = UserTaskInstanceDeadlineEventBody.create() .eventDate(new Date()) .eventUser(event.getEventUser()) @@ -394,13 +474,19 @@ private void handleUserTaskDeadlineEvent(UserTaskDeadlineEvent event) { .notification(event.getNotification()); UserTaskInstanceDeadlineEventBody body = builder.build(); - processedEvents.add(new UserTaskInstanceDeadlineDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventUser(), metadata, body)); + UserTaskInstanceDeadlineDataEvent utEvent = + new UserTaskInstanceDeadlineDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventUser(), metadata, body); + utEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(utEvent); } private void handleUserTaskStateEvent(UserTaskStateEvent event) { + if (event.getNewStatus() == null) { + return; + } Map metadata = buildUserTaskMetadata((HumanTaskWorkItem) event.getWorkItem()); metadata.putAll(buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance())); - + KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); UserTaskInstanceStateEventBody.Builder builder = UserTaskInstanceStateEventBody.create() .eventDate(new Date()) .eventUser(event.getEventUser()) @@ -410,18 +496,25 @@ private void handleUserTaskStateEvent(UserTaskStateEvent event) { .userTaskDescription(((HumanTaskWorkItem) event.getWorkItem()).getTaskDescription()) .userTaskPriority(((HumanTaskWorkItem) event.getWorkItem()).getTaskPriority()) .userTaskReferenceName(((HumanTaskWorkItem) event.getWorkItem()).getReferenceName()) - .state(((HumanTaskWorkItem) event.getWorkItem()).getPhaseStatus()) + .state(event.getNewStatus()) .actualOwner(((HumanTaskWorkItem) event.getWorkItem()).getActualOwner()) + .eventType(isTransition(event) ? event.getNewStatus() : "Modify") .processInstanceId(event.getProcessInstance().getId()); UserTaskInstanceStateEventBody body = builder.build(); - processedEvents.add(new UserTaskInstanceStateDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventUser(), metadata, body)); + UserTaskInstanceStateDataEvent utEvent = new UserTaskInstanceStateDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventUser(), metadata, body); + utEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(utEvent); + } + + private boolean isTransition(UserTaskStateEvent event) { + return !Objects.equals(event.getOldStatus(), event.getNewStatus()); } private void handleUserTaskVariableEvent(UserTaskVariableEvent event) { Map metadata = buildUserTaskMetadata((HumanTaskWorkItem) event.getWorkItem()); metadata.putAll(buildProcessMetadata((KogitoWorkflowProcessInstance) event.getProcessInstance())); - + KogitoWorkflowProcessInstance pi = (KogitoWorkflowProcessInstance) event.getProcessInstance(); UserTaskInstanceVariableEventBody.Builder builder = UserTaskInstanceVariableEventBody.create() .eventDate(new Date()) .eventUser(event.getEventUser()) @@ -434,8 +527,10 @@ private void handleUserTaskVariableEvent(UserTaskVariableEvent event) { .variableType(event.getVariableType().name()); UserTaskInstanceVariableEventBody body = builder.build(); - - processedEvents.add(new UserTaskInstanceVariableDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventUser(), metadata, body)); + UserTaskInstanceVariableDataEvent utEvent = + new UserTaskInstanceVariableDataEvent(buildSource(event.getProcessInstance().getProcessId()), addons.toString(), event.getEventUser(), metadata, body); + utEvent.setKogitoBusinessKey(pi.getBusinessKey()); + processedEvents.add(utEvent); } diff --git a/api/kogito-events-core/src/main/java/org/kie/kogito/event/job/JobInstanceDataEvent.java b/api/kogito-events-core/src/main/java/org/kie/kogito/event/job/JobInstanceDataEvent.java new file mode 100644 index 00000000000..023bdc3d949 --- /dev/null +++ b/api/kogito-events-core/src/main/java/org/kie/kogito/event/job/JobInstanceDataEvent.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.kie.kogito.event.job; + +import org.kie.kogito.event.AbstractDataEvent; + +public class JobInstanceDataEvent extends AbstractDataEvent { + + public JobInstanceDataEvent(String type, + String source, + byte[] data, + String kogitoProcessInstanceId, + String kogitoRootProcessInstanceId, + String kogitoProcessId, + String kogitoRootProcessId, + String kogitoIdentity) { + super(type, source, data, kogitoProcessInstanceId, kogitoRootProcessInstanceId, kogitoProcessId, + kogitoRootProcessId, null, kogitoIdentity); + } +} \ No newline at end of file diff --git a/api/kogito-events-core/src/main/java/org/kie/kogito/event/process/ProcessInstanceNodeDataEvent.java b/api/kogito-events-core/src/main/java/org/kie/kogito/event/process/ProcessInstanceNodeDataEvent.java index b58f7307ad5..db118aa009f 100644 --- a/api/kogito-events-core/src/main/java/org/kie/kogito/event/process/ProcessInstanceNodeDataEvent.java +++ b/api/kogito-events-core/src/main/java/org/kie/kogito/event/process/ProcessInstanceNodeDataEvent.java @@ -41,4 +41,5 @@ public ProcessInstanceNodeDataEvent(String source, String addons, String identit null, identity); } + } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/ProcessInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/ProcessInstance.java index fa7973511ea..8ede0d974d0 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/ProcessInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/ProcessInstance.java @@ -86,8 +86,6 @@ public interface ProcessInstance extends KogitoProcessInstance, int getSlaCompliance(); - Date getSlaDueDate(); - void configureTimers(); void setReferenceId(String referenceId); 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(); } } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/event/UserTaskStateEventImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/event/UserTaskStateEventImpl.java index b2d82962cc5..2cacd6063fa 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/event/UserTaskStateEventImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/event/UserTaskStateEventImpl.java @@ -48,10 +48,12 @@ public void setNewStatus(String newStatus) { } + @Override public String getNewStatus() { return newStatus; } + @Override public String getOldStatus() { return oldStatus; } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/humantask/HumanTaskWorkItemDecoratorImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/humantask/HumanTaskWorkItemDecoratorImpl.java index f5a721cbbd0..bea5b2cbb62 100644 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/humantask/HumanTaskWorkItemDecoratorImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/instance/impl/humantask/HumanTaskWorkItemDecoratorImpl.java @@ -387,12 +387,18 @@ public void setTaskName(String taskName) { @Override public void setTaskDescription(String taskDescription) { delegate.setTaskDescription(taskDescription); + if (delegate.getPhaseStatus() == null) { + return; + } getEventSupport().ifPresent(e -> e.fireOneUserTaskStateChange(getProcessInstance(), getNodeInstance(), getKieRuntime(), delegate.getPhaseStatus(), delegate.getPhaseStatus())); } @Override public void setTaskPriority(String taskPriority) { delegate.setTaskPriority(taskPriority); + if (delegate.getPhaseStatus() == null) { + return; + } getEventSupport().ifPresent(e -> e.fireOneUserTaskStateChange(getProcessInstance(), getNodeInstance(), getKieRuntime(), delegate.getPhaseStatus(), delegate.getPhaseStatus())); } @@ -405,6 +411,9 @@ public void setReferenceName(String referenceName) { public void setActualOwner(String actualOwner) { String currentPhaseStatus = delegate.getPhaseStatus(); delegate.setActualOwner(actualOwner); + if (currentPhaseStatus == null) { + return; + } getEventSupport().ifPresent(e -> e.fireOneUserTaskStateChange(getProcessInstance(), getNodeInstance(), getKieRuntime(), currentPhaseStatus, currentPhaseStatus)); } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstance.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstance.java index 98a32475c0c..47e84a4f425 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstance.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/NodeInstance.java @@ -18,7 +18,6 @@ */ package org.jbpm.workflow.instance; -import java.util.Date; import java.util.Map; import org.jbpm.process.instance.ContextInstance; @@ -51,8 +50,6 @@ public interface NodeInstance extends KogitoNodeInstance { int getSlaCompliance(); - Date getSlaDueDate(); - String getSlaTimerId(); default KogitoProcessInstance getKogitoProcessInstance() { diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java index af9134308dc..eecc9e33789 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/NodeInstanceImpl.java @@ -175,6 +175,7 @@ public boolean isInversionOfControl() { return false; } + @Override public CancelType getCancelType() { return cancelType; } @@ -564,6 +565,7 @@ public String getUniqueId() { return result.toString(); } + @Override public Map getMetaData() { return this.metaData; } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java index f095f8f1b2b..e13e3d50248 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/instance/impl/WorkflowProcessInstanceImpl.java @@ -140,6 +140,7 @@ public abstract class WorkflowProcessInstanceImpl extends ProcessInstanceImpl im private Date endDate; private String nodeIdInError; + private String nodeInstanceIdInError; private String errorMessage; private transient Optional errorCause = Optional.empty(); @@ -297,7 +298,7 @@ public List getNodeInstances(final long nodeId, final List nodes = findNodeInstanceEvents(events, 2); + List nodes = findNodeInstanceEvents(events, ProcessInstanceNodeEventBody.EVENT_TYPE_EXIT); assertThat(nodes).hasSize(9).extractingResultOf("getNodeType").contains("StartNode", "ActionNode", "BoundaryEventNode", "EndNode"); } @@ -284,7 +284,7 @@ public void testBasicUserTaskProcessAbort() throws Exception { events = publisher.extract(); assertThat(events).hasSize(4); - triggered = findNodeInstanceEvents(events, 2); + triggered = findNodeInstanceEvents(events, ProcessInstanceNodeEventBody.EVENT_TYPE_ABORTED); assertThat(triggered).hasSize(1).extractingResultOf("getNodeName").containsOnly("First Task"); assertProcessInstanceEvent(events.get(3), "UserTasksProcess", "UserTasksProcess", ProcessInstance.STATE_ABORTED);