Skip to content

Commit

Permalink
[Fix apache/incubator-kie-issues#1857] Adding triggerCount
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Mar 6, 2025
1 parent 37ca11b commit fc0287c
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type ProcessInstance {

type ProcessInstanceError {
nodeDefinitionId: String!
nodeInstanceId: String
message: String
}

Expand Down Expand Up @@ -142,6 +143,8 @@ type NodeInstance {
definitionId: String!
nodeId: String!
slaDueDate: DateTime
triggerCount: Int
errorMessage: String
}

enum MilestoneStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ public class NodeInstance {

private ZonedDateTime slaDueDate;

private int triggerCount;

private String errorMessage;

public int getTriggerCount() {
return triggerCount;
}

public void setTriggerCount(int triggerCount) {
this.triggerCount = triggerCount;
}

public String getErrorMessage() {
return errorMessage;
}

public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}

@JsonProperty("nodeDefinitionId")
private String definitionId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class ProcessInstanceError {

private String nodeDefinitionId;
private String nodeInstanceId;
@JsonProperty("errorMessage")
private String message;

Expand Down Expand Up @@ -77,4 +78,12 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(nodeDefinitionId, message);
}

public String getNodeInstanceId() {
return nodeInstanceId;
}

public void setNodeInstanceId(String nodeInstanceId) {
this.nodeInstanceId = nodeInstanceId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.kie.kogito.event.process.ProcessInstanceDataEvent;
import org.kie.kogito.event.process.ProcessInstanceErrorDataEvent;
import org.kie.kogito.event.process.ProcessInstanceErrorEventBody;
import org.kie.kogito.index.CommonUtils;
import org.kie.kogito.index.model.ProcessInstance;
import org.kie.kogito.index.model.ProcessInstanceError;
Expand All @@ -30,14 +31,17 @@
public class ProcessInstanceErrorDataEventMerger extends ProcessInstanceEventMerger {

@Override
public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent<?> data) {
ProcessInstanceErrorDataEvent event = (ProcessInstanceErrorDataEvent) data;
pi = getOrNew(pi, data, event.getData().getEventDate());
public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent<?> dataEvent) {
ProcessInstanceErrorDataEvent event = (ProcessInstanceErrorDataEvent) dataEvent;
ProcessInstanceErrorEventBody data = event.getData();
pi = getOrNew(pi, dataEvent, data.getEventDate());
ProcessInstanceError error = new ProcessInstanceError();
error.setMessage(event.getData().getErrorMessage());
error.setNodeDefinitionId(event.getData().getNodeDefinitionId());
error.setMessage(data.getErrorMessage());
error.setNodeDefinitionId(data.getNodeDefinitionId());
error.setNodeInstanceId(data.getNodeInstanceId());
pi.setError(error);
pi.setState(CommonUtils.ERROR_STATE);
pi.getNodes().stream().filter(n -> n.getId().equals(error.getNodeInstanceId())).findAny().ifPresent(n -> n.setErrorMessage(data.getErrorMessage()));
return pi;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent<?> dat
nodeInstance.setName(body.getNodeName());
nodeInstance.setType(body.getNodeType());
nodeInstance.setSlaDueDate(toZonedDateTime(body.getSlaDueDate()));
nodeInstance.setTriggerCount(body.triggerCount());
ZonedDateTime eventDate = toZonedDateTime(body.getEventDate());
switch (body.getEventType()) {
case EVENT_TYPE_ENTER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,30 @@ public class NodeInstanceEntity extends AbstractEntity {
private ZonedDateTime exit;
private ZonedDateTime slaDueDate;
private String definitionId;
private int triggerCount;
private String errorMessage;

@ManyToOne(cascade = CascadeType.ALL, optional = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "processInstanceId", foreignKey = @ForeignKey(name = "fk_nodes_process"))
private ProcessInstanceEntity processInstance;

public int getTriggerCount() {
return triggerCount;
}

public void setTriggerCount(int triggerCount) {
this.triggerCount = triggerCount;
}

public String getErrorMessage() {
return errorMessage;
}

public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}

@Override
public String getId() {
return id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class ProcessInstanceErrorEntity {

private String nodeDefinitionId;
private String nodeInstanceId;
private String message;

public String getNodeDefinitionId() {
Expand All @@ -44,22 +45,28 @@ public void setMessage(String message) {
this.message = message;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProcessInstanceErrorEntity that = (ProcessInstanceErrorEntity) o;
return Objects.equals(nodeDefinitionId, that.nodeDefinitionId) &&
Objects.equals(message, that.message);
public void setNodeInstanceId(String nodeInstanceId) {
this.nodeInstanceId = nodeInstanceId;
}

public String getNodeInstanceId() {
return nodeInstanceId;
}

@Override
public int hashCode() {
return Objects.hash(nodeDefinitionId, message);
return Objects.hash(message, nodeDefinitionId, nodeInstanceId);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof ProcessInstanceErrorEntity))
return false;
ProcessInstanceErrorEntity other = (ProcessInstanceErrorEntity) obj;
return Objects.equals(message, other.message) && Objects.equals(nodeDefinitionId, other.nodeDefinitionId)
&& Objects.equals(nodeInstanceId, other.nodeInstanceId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ private void indexError(ProcessInstanceEntity pi, ProcessInstanceErrorEventBody
}
errorEntity.setMessage(error.getErrorMessage());
errorEntity.setNodeDefinitionId(error.getNodeDefinitionId());
errorEntity.setNodeInstanceId(error.getNodeInstanceId());
pi.setState(CommonUtils.ERROR_STATE);
pi.getNodes().stream().filter(n -> n.getId().equals(error.getNodeInstanceId())).findAny().ifPresent(n -> n.setErrorMessage(error.getErrorMessage()));
}

private void indexNode(ProcessInstanceEntity pi, ProcessInstanceNodeEventBody data) {
Expand Down Expand Up @@ -186,6 +188,7 @@ private NodeInstanceEntity updateNode(NodeInstanceEntity nodeInstance, ProcessIn
nodeInstance.setName(body.getNodeName());
nodeInstance.setType(body.getNodeType());
nodeInstance.setSlaDueDate(toZonedDateTime(body.getSlaDueDate()));
nodeInstance.setTriggerCount(body.triggerCount());
ZonedDateTime eventDate = toZonedDateTime(body.getEventDate());
switch (body.getEventType()) {
case EVENT_TYPE_ENTER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ public static class NodeInstanceEntity {

Long slaDueDate;

private int triggerCount;

private String errorMessage;

public String getId() {
return id;
}
Expand Down Expand Up @@ -363,6 +367,22 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(id);
}

public int getTriggerCount() {
return triggerCount;
}

public void setTriggerCount(int triggerCount) {
this.triggerCount = triggerCount;
}

public String getErrorMessage() {
return errorMessage;
}

public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}

public static class ProcessInstanceErrorEntity {
Expand All @@ -371,6 +391,8 @@ public static class ProcessInstanceErrorEntity {

String message;

private String nodeInstanceId;

public String getNodeDefinitionId() {
return nodeDefinitionId;
}
Expand All @@ -387,22 +409,30 @@ public void setMessage(String message) {
this.message = message;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProcessInstanceErrorEntity that = (ProcessInstanceErrorEntity) o;
return Objects.equals(nodeDefinitionId, that.nodeDefinitionId) &&
Objects.equals(message, that.message);
public String getNodeInstanceId() {
return nodeInstanceId;
}

public void setNodeInstanceId(String nodeInstanceId) {
this.nodeInstanceId = nodeInstanceId;
}

@Override
public int hashCode() {
return Objects.hash(nodeDefinitionId, message);
return Objects.hash(message, nodeDefinitionId, nodeInstanceId);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ProcessInstanceErrorEntity other = (ProcessInstanceErrorEntity) obj;
return Objects.equals(message, other.message) && Objects.equals(nodeDefinitionId, other.nodeDefinitionId)
&& Objects.equals(nodeInstanceId, other.nodeInstanceId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ NodeInstance toNodeInstance(ProcessInstanceEntity.NodeInstanceEntity entity) {
instance.setExit(instantToZonedDateTime(entity.getExit()));
instance.setDefinitionId(entity.getDefinitionId());
instance.setSlaDueDate(instantToZonedDateTime(entity.getSlaDueDate()));
instance.setTriggerCount(instance.getTriggerCount());
instance.setErrorMessage(entity.getErrorMessage());
return instance;
}

Expand All @@ -166,6 +168,8 @@ ProcessInstanceEntity.NodeInstanceEntity fromNodeInstance(NodeInstance instance)
entity.setExit(zonedDateTimeToInstant(instance.getExit()));
entity.setDefinitionId(instance.getDefinitionId());
entity.setSlaDueDate(zonedDateTimeToInstant(instance.getSlaDueDate()));
entity.setTriggerCount(instance.getTriggerCount());
entity.setErrorMessage(instance.getErrorMessage());
return entity;
}

Expand All @@ -176,6 +180,7 @@ ProcessInstanceError toProcessInstanceError(ProcessInstanceEntity.ProcessInstanc

ProcessInstanceError error = new ProcessInstanceError();
error.setNodeDefinitionId(entity.getNodeDefinitionId());
error.setNodeInstanceId(entity.getNodeInstanceId());
error.setMessage(entity.getMessage());
return error;
}
Expand All @@ -187,6 +192,7 @@ ProcessInstanceEntity.ProcessInstanceErrorEntity fromProcessInstanceError(Proces

ProcessInstanceEntity.ProcessInstanceErrorEntity entity = new ProcessInstanceEntity.ProcessInstanceErrorEntity();
entity.setNodeDefinitionId(error.getNodeDefinitionId());
entity.setNodeInstanceId(error.getNodeInstanceId());
entity.setMessage(error.getMessage());
return entity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public CompletableFuture<String> abortProcessInstance(String serviceURL, Process
pInstance.abort();

if (pInstance.status() == org.kie.kogito.process.ProcessInstance.STATE_ERROR) {
throw new ProcessInstanceExecutionException(pInstance.id(), pInstance.error().get().failedNodeId(), pInstance.error().get().errorMessage());
throw ProcessInstanceExecutionException.fromError(pInstance);
} else {
return String.format(SUCCESSFULLY_OPERATION_MESSAGE, "ABORT ProcessInstance with id: " + processInstance.getId());
}
Expand All @@ -106,7 +106,7 @@ public CompletableFuture<String> retryProcessInstance(String serviceURL, Process
pInstance.error().get().retrigger();

if (pInstance.status() == org.kie.kogito.process.ProcessInstance.STATE_ERROR) {
throw new ProcessInstanceExecutionException(pInstance.id(), pInstance.error().get().failedNodeId(), pInstance.error().get().errorMessage());
throw ProcessInstanceExecutionException.fromError(pInstance);
} else {
return String.format(SUCCESSFULLY_OPERATION_MESSAGE, "RETRY ProcessInstance in error with id: " + processInstance.getId());
}
Expand All @@ -119,7 +119,7 @@ public CompletableFuture<String> skipProcessInstance(String serviceURL, ProcessI
pInstance.error().get().skip();

if (pInstance.status() == org.kie.kogito.process.ProcessInstance.STATE_ERROR) {
throw new ProcessInstanceExecutionException(pInstance.id(), pInstance.error().get().failedNodeId(), pInstance.error().get().errorMessage());
throw ProcessInstanceExecutionException.fromError(pInstance);
} else {
return String.format(SUCCESSFULLY_OPERATION_MESSAGE, "SKIP ProcessInstance in error with id: " + processInstance.getId());
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public CompletableFuture<String> triggerNodeInstance(String serviceURL, ProcessI
pInstance.triggerNode(nodeDefinitionId);

if (pInstance.status() == org.kie.kogito.process.ProcessInstance.STATE_ERROR) {
throw new ProcessInstanceExecutionException(pInstance.id(), pInstance.error().get().failedNodeId(), pInstance.error().get().errorMessage());
throw ProcessInstanceExecutionException.fromError(pInstance);
} else {
return String.format(SUCCESSFULLY_OPERATION_MESSAGE,
"TRIGGER Node " + nodeDefinitionId + "from ProcessInstance with id: " + processInstance.getId());
Expand All @@ -199,7 +199,7 @@ public CompletableFuture<String> retriggerNodeInstance(String serviceURL, Proces
pInstance.retriggerNodeInstance(nodeInstanceId);

if (pInstance.status() == org.kie.kogito.process.ProcessInstance.STATE_ERROR) {
throw new ProcessInstanceExecutionException(pInstance.id(), pInstance.error().get().failedNodeId(), pInstance.error().get().errorMessage());
throw ProcessInstanceExecutionException.fromError(pInstance);
} else {
return String.format(SUCCESSFULLY_OPERATION_MESSAGE,
"RETRIGGER Node instance " + nodeInstanceId + "from ProcessInstance with id: " + processInstance.getId());
Expand All @@ -213,7 +213,7 @@ public CompletableFuture<String> cancelNodeInstance(String serviceURL, ProcessIn
pInstance.cancelNodeInstance(nodeInstanceId);

if (pInstance.status() == org.kie.kogito.process.ProcessInstance.STATE_ERROR) {
throw new ProcessInstanceExecutionException(pInstance.id(), pInstance.error().get().failedNodeId(), pInstance.error().get().errorMessage());
throw ProcessInstanceExecutionException.fromError(pInstance);
} else {
return String.format(SUCCESSFULLY_OPERATION_MESSAGE,
"CANCEL Node instance " + nodeInstanceId + "from ProcessInstance with id: " + processInstance.getId());
Expand Down

0 comments on commit fc0287c

Please sign in to comment.