From ff89364f4d1950c71d0fc9589985ad2589450f1d Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:33:54 +0100 Subject: [PATCH] [Fix #1995] Setting last update when pi is created (#1996) --- .../ProcessInstanceErrorDataEventMerger.java | 2 +- .../storage/merger/ProcessInstanceEventMerger.java | 5 ++++- .../merger/ProcessInstanceNodeDataEventMerger.java | 2 +- .../ProcessInstanceStateDataEventMerger.java | 2 +- .../ProcessInstanceVariableDataEventMerger.java | 7 +------ .../jpa/storage/ProcessInstanceEntityStorage.java | 14 ++++++++------ 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceErrorDataEventMerger.java b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceErrorDataEventMerger.java index 6466c4e719..87b6566433 100644 --- a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceErrorDataEventMerger.java +++ b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceErrorDataEventMerger.java @@ -30,8 +30,8 @@ public class ProcessInstanceErrorDataEventMerger extends ProcessInstanceEventMer @Override public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent data) { - pi = getOrNew(pi, data); ProcessInstanceErrorDataEvent event = (ProcessInstanceErrorDataEvent) data; + pi = getOrNew(pi, data, event.getData().getEventDate()); ProcessInstanceError error = new ProcessInstanceError(); error.setMessage(event.getData().getErrorMessage()); error.setNodeDefinitionId(event.getData().getNodeDefinitionId()); diff --git a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceEventMerger.java b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceEventMerger.java index 7da0072eb1..440d4d6c1a 100644 --- a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceEventMerger.java +++ b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceEventMerger.java @@ -19,17 +19,20 @@ package org.kie.kogito.index.storage.merger; import java.util.ArrayList; +import java.util.Date; import org.kie.kogito.event.process.ProcessInstanceDataEvent; +import org.kie.kogito.index.DateTimeUtils; import org.kie.kogito.index.model.ProcessInstance; public abstract class ProcessInstanceEventMerger implements Merger, ProcessInstance> { - protected ProcessInstance getOrNew(ProcessInstance pi, ProcessInstanceDataEvent event) { + protected ProcessInstance getOrNew(ProcessInstance pi, ProcessInstanceDataEvent event, Date date) { if (pi == null) { pi = new ProcessInstance(); pi.setId(event.getKogitoProcessInstanceId()); pi.setProcessId(event.getKogitoProcessId()); + pi.setLastUpdate(DateTimeUtils.toZonedDateTime(date)); pi.setMilestones(new ArrayList<>()); pi.setNodes(new ArrayList<>()); } diff --git a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceNodeDataEventMerger.java b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceNodeDataEventMerger.java index f3442d24b9..d800dfd226 100644 --- a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceNodeDataEventMerger.java +++ b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceNodeDataEventMerger.java @@ -47,8 +47,8 @@ public class ProcessInstanceNodeDataEventMerger extends ProcessInstanceEventMerg @Override public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent data) { - pi = getOrNew(pi, data); ProcessInstanceNodeDataEvent event = (ProcessInstanceNodeDataEvent) data; + pi = getOrNew(pi, data, event.getData().getEventDate()); List nodeInstances = Optional.ofNullable(pi.getNodes()).orElse(new ArrayList<>()); diff --git a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceStateDataEventMerger.java b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceStateDataEventMerger.java index db80965403..b49036fb0c 100644 --- a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceStateDataEventMerger.java +++ b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceStateDataEventMerger.java @@ -39,8 +39,8 @@ public class ProcessInstanceStateDataEventMerger extends ProcessInstanceEventMer @Override public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent data) { - pi = getOrNew(pi, data); ProcessInstanceStateDataEvent event = (ProcessInstanceStateDataEvent) data; + pi = getOrNew(pi, data, event.getData().getEventDate()); LOGGER.debug("Value before merging: {}", pi); pi.setId(event.getData().getProcessInstanceId()); pi.setVersion(event.getData().getProcessVersion()); diff --git a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceVariableDataEventMerger.java b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceVariableDataEventMerger.java index d6102ec7b4..b536a15f08 100644 --- a/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceVariableDataEventMerger.java +++ b/data-index/data-index-storage/data-index-storage-common/src/main/java/org/kie/kogito/index/storage/merger/ProcessInstanceVariableDataEventMerger.java @@ -23,22 +23,17 @@ import org.kie.kogito.event.process.ProcessInstanceVariableEventBody; import org.kie.kogito.index.json.JsonUtils; import org.kie.kogito.index.model.ProcessInstance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import jakarta.enterprise.context.ApplicationScoped; @ApplicationScoped public class ProcessInstanceVariableDataEventMerger extends ProcessInstanceEventMerger { - private static final Logger LOGGER = LoggerFactory.getLogger(ProcessInstanceVariableDataEventMerger.class); - - @SuppressWarnings("unchecked") @Override public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent data) { - pi = getOrNew(pi, data); ProcessInstanceVariableDataEvent event = (ProcessInstanceVariableDataEvent) data; ProcessInstanceVariableEventBody body = event.getData(); + pi = getOrNew(pi, data, body.getEventDate()); pi.setVariables(JsonUtils.mergeVariable(body.getVariableName(), body.getVariableValue(), pi.getVariables())); return pi; } diff --git a/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/ProcessInstanceEntityStorage.java b/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/ProcessInstanceEntityStorage.java index 5ae222d0b6..5ea98dda39 100644 --- a/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/ProcessInstanceEntityStorage.java +++ b/data-index/data-index-storage/data-index-storage-jpa-common/src/main/java/org/kie/kogito/index/jpa/storage/ProcessInstanceEntityStorage.java @@ -20,6 +20,7 @@ import java.time.ZonedDateTime; import java.util.ArrayList; +import java.util.Date; import java.util.Set; import org.kie.kogito.event.process.ProcessInstanceErrorDataEvent; @@ -93,11 +94,12 @@ public void indexVariable(ProcessInstanceVariableDataEvent event) { indexVariable(event.getData()); } - private ProcessInstanceEntity findOrInit(String processId, String processInstanceId) { + private ProcessInstanceEntity findOrInit(String processId, String processInstanceId, Date date) { return repository.findByIdOptional(processInstanceId).orElseGet(() -> { ProcessInstanceEntity pi = new ProcessInstanceEntity(); pi.setProcessId(processId); pi.setId(processInstanceId); + pi.setLastUpdate(toZonedDateTime(date)); pi.setNodes(new ArrayList<>()); pi.setMilestones(new ArrayList<>()); repository.persist(pi); @@ -106,7 +108,7 @@ private ProcessInstanceEntity findOrInit(String processId, String processInstanc } private void indexError(ProcessInstanceErrorEventBody error) { - ProcessInstanceEntity pi = findOrInit(error.getProcessId(), error.getProcessInstanceId()); + ProcessInstanceEntity pi = findOrInit(error.getProcessId(), error.getProcessInstanceId(), error.getEventDate()); ProcessInstanceErrorEntity errorEntity = pi.getError(); if (errorEntity == null) { errorEntity = new ProcessInstanceErrorEntity(); @@ -118,7 +120,7 @@ private void indexError(ProcessInstanceErrorEventBody error) { } private void indexNode(ProcessInstanceNodeEventBody data) { - ProcessInstanceEntity pi = findOrInit(data.getProcessId(), data.getProcessInstanceId()); + ProcessInstanceEntity pi = findOrInit(data.getProcessId(), data.getProcessInstanceId(), data.getEventDate()); pi.getNodes().stream().filter(n -> n.getId().equals(data.getNodeInstanceId())).findAny().ifPresentOrElse(n -> updateNode(n, data), () -> createNode(pi, data)); if ("MilestoneNode".equals(data.getNodeType())) { pi.getMilestones().stream().filter(n -> n.getId().equals(data.getNodeInstanceId())).findAny().ifPresentOrElse(n -> updateMilestone(n, data), () -> createMilestone(pi, data)); @@ -171,12 +173,12 @@ private NodeInstanceEntity updateNode(NodeInstanceEntity nodeInstance, ProcessIn } private void indexSLA(ProcessInstanceSLAEventBody data) { - findOrInit(data.getProcessId(), data.getProcessInstanceId()); + findOrInit(data.getProcessId(), data.getProcessInstanceId(), data.getEventDate()); repository.flush(); } private void indexState(ProcessInstanceStateEventBody data, Set addons, String endpoint) { - ProcessInstanceEntity pi = findOrInit(data.getProcessId(), data.getProcessInstanceId()); + ProcessInstanceEntity pi = findOrInit(data.getProcessId(), data.getProcessInstanceId(), data.getEventDate()); pi.setVersion(data.getProcessVersion()); pi.setProcessName(data.getProcessName()); pi.setRootProcessInstanceId(data.getRootProcessInstanceId()); @@ -199,7 +201,7 @@ private void indexState(ProcessInstanceStateEventBody data, Set addons, } private void indexVariable(ProcessInstanceVariableEventBody data) { - ProcessInstanceEntity pi = findOrInit(data.getProcessId(), data.getProcessInstanceId()); + ProcessInstanceEntity pi = findOrInit(data.getProcessId(), data.getProcessInstanceId(), data.getEventDate()); pi.setVariables(JsonUtils.mergeVariable(data.getVariableName(), data.getVariableValue(), pi.getVariables())); repository.flush(); }