Skip to content
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

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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,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,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 @@ -109,7 +109,7 @@ public void testProcessInstanceNodeEvent() {
.hasSize(1);

Assertions.assertThat(processInstance.getNodes().get(0))
.hasNoNullFieldsOrPropertiesExcept("exit", "slaDueDate")
.hasNoNullFieldsOrPropertiesExcept("exit", "slaDueDate", "errorMessage")
.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")
.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 trigger_count integer;
ALTER TABLE nodes ADD COLUMN error_message varchar(4000);
ALTER TABLE processes ADD COLUMN node_instance_id varchar(255);
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
@@ -0,0 +1,21 @@
/*
* 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 trigger_count int4, ADD COLUMN error_message VARCHAR(65535);
ALTER TABLE processes ADD COLUMN node_instance_id VARCHAR(255);
Loading