Skip to content

[Fix apache/incubator-kie-issues#1857] Adding triggerCount #2204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
retrigger: Boolean
errorMessage: String
}

enum MilestoneStatus {
Expand Down Expand Up @@ -207,13 +210,18 @@ input ProcessInstanceErrorArgument {
}

input NodeInstanceArgument {
and: [NodeInstanceArgument!]
or: [NodeInstanceArgument!]
not: NodeInstanceArgument
id: IdArgument
name: StringArgument
definitionId: StringArgument
nodeId: StringArgument
type: StringArgument
enter: DateArgument
exit: DateArgument
errorMessage: StringArgument
retrigger: BooleanArgument
}

input MilestoneStatusArgument {
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 Boolean retrigger;

private String errorMessage;

public Boolean isRetrigger() {
return retrigger;
}

public void setRetrigger(Boolean retrigger) {
this.retrigger = retrigger;
}

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 @@ -111,6 +111,7 @@ public static ProcessInstanceNodeDataEvent createProcessInstanceNodeDataEvent(St
.nodeType(nodeType)
.eventDate(new Date())
.eventType(eventType)
.setRetrigger(false)
.build();

ProcessInstanceNodeDataEvent event = new ProcessInstanceNodeDataEvent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ void testProcessInstanceQuery() {
processInstanceId);
}

@Test
void testProcessRetriggerQuery() {
String processId = "no_retrigger";
String processInstanceId = UUID.randomUUID().toString();
String subProcessId = processId + "_sub";
String subProcessInstanceId = UUID.randomUUID().toString();
ProcessInstanceStorage storage = getStorage();
storage.indexState(TestUtils.createProcessInstanceEvent(processInstanceId, processId, subProcessId, subProcessInstanceId, COMPLETED.ordinal()));
storage.indexNode(TestUtils.createProcessInstanceNodeDataEvent(processInstanceId, processId, "1", "1", "Javierito", "type", 1));
storage.indexError(TestUtils.createProcessInstanceErrorDataEvent(processInstanceId, processId, "1", "kkdevaca", "1", "1"));
queryAndAssert(assertWithId(), storage, singletonList(equalTo("nodes.retrigger", false)), null, null, null, processInstanceId);
}
}
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,19 @@
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);
if (pi.getNodes() != null) {
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,9 @@ public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent<?> dat
nodeInstance.setName(body.getNodeName());
nodeInstance.setType(body.getNodeType());
nodeInstance.setSlaDueDate(toZonedDateTime(body.getSlaDueDate()));
if (body.isRetrigger() != null) {
nodeInstance.setRetrigger(body.isRetrigger());
}
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 @@ -56,6 +56,8 @@ public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent<?> dat
pi.setCreatedBy(event.getData().getEventUser());
} else if (event.getData().getEventType() == ProcessInstanceStateEventBody.EVENT_TYPE_STARTED) {
pi.setEnd(toZonedDateTime(event.getData().getEventDate()));
} else if (event.getData().getEventType() == ProcessInstanceStateEventBody.EVENT_TYPE_RETRIGGERED) {
pi.setError(null);
}
pi.setBusinessKey(event.getData().getBusinessKey());
pi.setAddons(isNullOrEmpty(event.getKogitoAddons()) ? null : Set.of(event.getKogitoAddons().split(",")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public NodeInstance readFrom(ProtoStreamReader reader) throws IOException {
node.setDefinitionId(reader.readString("definitionId"));
node.setNodeId(reader.readString("nodeId"));
node.setSlaDueDate(dateToZonedDateTime(reader.readDate("slaDueDate")));
node.setRetrigger(reader.readBoolean("retrigger"));
node.setErrorMessage(reader.readString("errorMessage"));

return node;
}

Expand All @@ -56,6 +59,8 @@ public void writeTo(ProtoStreamWriter writer, NodeInstance node) throws IOExcept
writer.writeString("definitionId", node.getDefinitionId());
writer.writeString("nodeId", node.getNodeId());
writer.writeDate("slaDueDate", zonedDateTimeToDate(node.getSlaDueDate()));
writer.writeBoolean("retrigger", node.isRetrigger());
writer.writeString("errorMessage", node.getErrorMessage());
}

@Override
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 Boolean retrigger;
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 Boolean isRetrigger() {
return retrigger;
}

public void setRetrigger(Boolean isRetrigger) {
this.retrigger = isRetrigger;
}

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,9 @@ private NodeInstanceEntity updateNode(NodeInstanceEntity nodeInstance, ProcessIn
nodeInstance.setName(body.getNodeName());
nodeInstance.setType(body.getNodeType());
nodeInstance.setSlaDueDate(toZonedDateTime(body.getSlaDueDate()));
if (body.isRetrigger() != null) {
nodeInstance.setRetrigger(body.isRetrigger());
}
ZonedDateTime eventDate = toZonedDateTime(body.getEventDate());
switch (body.getEventType()) {
case EVENT_TYPE_ENTER:
Expand Down Expand Up @@ -220,6 +225,8 @@ private void indexState(ProcessInstanceEntity pi, ProcessInstanceStateEventBody
pi.setCreatedBy(data.getEventUser());
} else if (data.getEventType() == ProcessInstanceStateEventBody.EVENT_TYPE_ENDED) {
pi.setEnd(toZonedDateTime(data.getEventDate()));
} else if (data.getEventType() == ProcessInstanceStateEventBody.EVENT_TYPE_RETRIGGERED) {
pi.setError(null);
}
pi.setBusinessKey(data.getBusinessKey());
pi.setUpdatedBy(data.getEventUser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void testProcessInstanceNodeEvent() {
.hasSize(1);

Assertions.assertThat(processInstance.getNodes().get(0))
.hasNoNullFieldsOrPropertiesExcept("exit", "slaDueDate")
.hasNoNullFieldsOrPropertiesExcept("exit", "slaDueDate", "errorMessage", "retrigger")
.hasFieldOrPropertyWithValue("name", "nodeName")
.hasFieldOrPropertyWithValue("type", "BoundaryEventNode")
.hasFieldOrPropertyWithValue("definitionId", nodeDefinitionId)
Expand All @@ -125,7 +125,7 @@ public void testProcessInstanceNodeEvent() {
.hasSize(1);

Assertions.assertThat(processInstance.getNodes().get(0))
.hasNoNullFieldsOrPropertiesExcept("slaDueDate")
.hasNoNullFieldsOrPropertiesExcept("slaDueDate", "errorMessage", "retrigger")
.hasFieldOrPropertyWithValue("name", "nodeName")
.hasFieldOrPropertyWithValue("type", "BoundaryEventNode")
.hasFieldOrPropertyWithValue("definitionId", nodeDefinitionId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

ALTER TABLE nodes ADD COLUMN retrigger boolean default false;
ALTER TABLE nodes ADD COLUMN error_message varchar(4000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nip picking here, but maybe setting size to max?

Copy link
Contributor Author

@fjtirado fjtirado Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe 4000 is the max for ansi, isnt it? (at least is the value for max used in other scripts so far)
But If you know a better common max, I´ll set that one ;)

Copy link
Contributor Author

@fjtirado fjtirado Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used 4000 (which is the max for varchar in Oracle), because is also 4000 here

ALTER TABLE processes ADD COLUMN node_instance_id varchar(255);
Loading