Skip to content

Commit

Permalink
[incubator-kie-issues#1629] Add SLA information to ProcessInstances &…
Browse files Browse the repository at this point in the history
… NodeInstances (apache#2145)

* [incubator-kie-issues#1629] Add SLA information to ProcessInstances & NodeInstances

* - add slaDueDate to ProcessInstanceEntity toString
  • Loading branch information
pefernan authored and rgdoliveira committed Nov 25, 2024
1 parent ae401d0 commit fe90635
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type ProcessInstance {
identity: String
createdBy: String
updatedBy: String
slaDueDate: DateTime
}

type ProcessInstanceError {
Expand Down Expand Up @@ -135,6 +136,7 @@ type NodeInstance {
exit: DateTime
definitionId: String!
nodeId: String!
slaDueDate: DateTime
}

enum MilestoneStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class NodeInstance {
@JsonProperty("leaveTime")
private ZonedDateTime exit;

private ZonedDateTime slaDueDate;

@JsonProperty("nodeDefinitionId")
private String definitionId;

Expand Down Expand Up @@ -97,6 +99,14 @@ public void setName(String name) {
this.name = name;
}

public ZonedDateTime getSlaDueDate() {
return slaDueDate;
}

public void setSlaDueDate(ZonedDateTime slaDueDate) {
this.slaDueDate = slaDueDate;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -125,6 +135,7 @@ public String toString() {
", type='" + type + '\'' +
", enter=" + enter +
", exit=" + exit +
", slaDueDate=" + slaDueDate +
", definitionId='" + definitionId + '\'' +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class ProcessInstanceMeta {
@JsonProperty("updatedBy")
private String updatedBy;
private ZonedDateTime lastUpdate;
private ZonedDateTime slaDueDate;

public String getId() {
return id;
Expand Down Expand Up @@ -186,6 +187,14 @@ public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}

public ZonedDateTime getSlaDueDate() {
return slaDueDate;
}

public void setSlaDueDate(ZonedDateTime slaDueDate) {
this.slaDueDate = slaDueDate;
}

@Override
public String toString() {
return "ProcessInstanceMeta{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent<?> dat
nodeInstance.setNodeId(body.getNodeDefinitionId());
nodeInstance.setName(body.getNodeName());
nodeInstance.setType(body.getNodeType());
nodeInstance.setSlaDueDate(toZonedDateTime(body.getSlaDueDate()));
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 @@ -63,6 +63,7 @@ public ProcessInstance merge(ProcessInstance pi, ProcessInstanceDataEvent<?> dat
pi.setLastUpdate(toZonedDateTime(event.getTime()));
pi.setDefinition(definitions(event));
pi.setUpdatedBy(event.getData().getEventUser());
pi.setSlaDueDate(toZonedDateTime(event.getData().getSlaDueDate()));
LOGGER.debug("Value after merging: {}", pi);
return pi;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public NodeInstance readFrom(ProtoStreamReader reader) throws IOException {
node.setExit(dateToZonedDateTime(reader.readDate("exit")));
node.setDefinitionId(reader.readString("definitionId"));
node.setNodeId(reader.readString("nodeId"));
node.setSlaDueDate(dateToZonedDateTime(reader.readDate("slaDueDate")));
return node;
}

Expand All @@ -54,6 +55,7 @@ public void writeTo(ProtoStreamWriter writer, NodeInstance node) throws IOExcept
writer.writeDate("exit", zonedDateTimeToDate(node.getExit()));
writer.writeString("definitionId", node.getDefinitionId());
writer.writeString("nodeId", node.getNodeId());
writer.writeDate("slaDueDate", zonedDateTimeToDate(node.getSlaDueDate()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class ProcessInstanceMarshaller extends AbstractMarshaller implements Mes
protected static final String MILESTONES = "milestones";
protected static final String CREATED_BY = "createdBy";
protected static final String UPDATED_BY = "updatedBy";
protected static final String SLA_DUE_DATE = "slaDueDate";

public ProcessInstanceMarshaller(ObjectMapper mapper) {
super(mapper);
Expand Down Expand Up @@ -84,6 +85,7 @@ public ProcessInstance readFrom(ProtoStreamReader reader) throws IOException {
pi.setVersion(reader.readString(VERSION));
pi.setCreatedBy(reader.readString(CREATED_BY));
pi.setUpdatedBy(reader.readString(UPDATED_BY));
pi.setSlaDueDate(dateToZonedDateTime(reader.readDate(SLA_DUE_DATE)));
return pi;
}

Expand All @@ -110,6 +112,7 @@ public void writeTo(ProtoStreamWriter writer, ProcessInstance pi) throws IOExcep
writer.writeString(VERSION, pi.getVersion());
writer.writeString(CREATED_BY, pi.getCreatedBy());
writer.writeString(UPDATED_BY, pi.getCreatedBy());
writer.writeDate(SLA_DUE_DATE, zonedDateTimeToDate(pi.getSlaDueDate()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class NodeInstanceEntity extends AbstractEntity {
private String type;
private ZonedDateTime enter;
private ZonedDateTime exit;
private ZonedDateTime slaDueDate;
private String definitionId;
@ManyToOne(cascade = CascadeType.ALL, optional = false)
@OnDelete(action = OnDeleteAction.CASCADE)
Expand Down Expand Up @@ -106,6 +107,14 @@ public void setExit(ZonedDateTime exit) {
this.exit = exit;
}

public ZonedDateTime getSlaDueDate() {
return slaDueDate;
}

public void setSlaDueDate(ZonedDateTime slaDueDate) {
this.slaDueDate = slaDueDate;
}

public ProcessInstanceEntity getProcessInstance() {
return processInstance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class ProcessInstanceEntity extends AbstractEntity {
private String createdBy;

private String updatedBy;

private ZonedDateTime slaDueDate;

@Convert(converter = JsonBinaryConverter.class)
@Column(columnDefinition = "jsonb")
private ObjectNode variables;
Expand Down Expand Up @@ -203,6 +206,14 @@ public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}

public ZonedDateTime getSlaDueDate() {
return slaDueDate;
}

public void setSlaDueDate(ZonedDateTime slaDueDate) {
this.slaDueDate = slaDueDate;
}

public ObjectNode getVariables() {
return variables;
}
Expand Down Expand Up @@ -286,6 +297,7 @@ public String toString() {
", lastUpdate=" + lastUpdate +
", createdBy=" + createdBy +
", updatedBy=" + updatedBy +
", slaDueDate=" + slaDueDate +
", variables=" + variables +
", nodes=" + nodes +
", milestones=" + milestones +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private NodeInstanceEntity updateNode(NodeInstanceEntity nodeInstance, ProcessIn
nodeInstance.setNodeId(body.getNodeDefinitionId());
nodeInstance.setName(body.getNodeName());
nodeInstance.setType(body.getNodeType());
nodeInstance.setSlaDueDate(toZonedDateTime(body.getSlaDueDate()));
ZonedDateTime eventDate = toZonedDateTime(body.getEventDate());
switch (body.getEventType()) {
case EVENT_TYPE_ENTER:
Expand Down Expand Up @@ -219,6 +220,7 @@ private void indexState(ProcessInstanceEntity pi, ProcessInstanceStateEventBody
pi.setLastUpdate(toZonedDateTime(data.getEventDate()));
pi.setAddons(addons);
pi.setEndpoint(endpoint);
pi.setSlaDueDate(toZonedDateTime(data.getSlaDueDate()));
}

private void indexVariable(ProcessInstanceEntity pi, ProcessInstanceVariableEventBody data) {
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")
.hasNoNullFieldsOrPropertiesExcept("exit", "slaDueDate")
.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))
.hasNoNullFieldsOrProperties()
.hasNoNullFieldsOrPropertiesExcept("slaDueDate")
.hasFieldOrPropertyWithValue("name", "nodeName")
.hasFieldOrPropertyWithValue("type", "BoundaryEventNode")
.hasFieldOrPropertyWithValue("definitionId", nodeDefinitionId)
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 processes ADD sla_due_date timestamp;
ALTER TABLE nodes ADD sla_due_date timestamp;
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class ProcessInstanceEntity {

String updatedBy;

Long slaDueDate;

public String getId() {
return id;
}
Expand Down Expand Up @@ -238,6 +240,14 @@ public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
}

public Long getSlaDueDate() {
return slaDueDate;
}

public void setSlaDueDate(Long slaDueDate) {
this.slaDueDate = slaDueDate;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -271,6 +281,8 @@ public static class NodeInstanceEntity {

String definitionId;

Long slaDueDate;

public String getId() {
return id;
}
Expand Down Expand Up @@ -327,6 +339,14 @@ public void setDefinitionId(String definitionId) {
this.definitionId = definitionId;
}

public Long getSlaDueDate() {
return slaDueDate;
}

public void setSlaDueDate(Long slaDueDate) {
this.slaDueDate = slaDueDate;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public ProcessInstanceEntity mapToEntity(String key, ProcessInstance instance) {
entity.setVersion(instance.getVersion());
entity.setCreatedBy(instance.getCreatedBy());
entity.setUpdatedBy(instance.getUpdatedBy());
entity.setSlaDueDate(zonedDateTimeToInstant(instance.getSlaDueDate()));
return entity;
}

Expand Down Expand Up @@ -108,6 +109,7 @@ public ProcessInstance mapToModel(ProcessInstanceEntity entity) {
instance.setVersion(entity.getVersion());
instance.setCreatedBy(entity.getCreatedBy());
instance.setUpdatedBy(entity.getCreatedBy());
instance.setSlaDueDate(instantToZonedDateTime(entity.getSlaDueDate()));
return instance;
}

Expand Down Expand Up @@ -146,6 +148,7 @@ NodeInstance toNodeInstance(ProcessInstanceEntity.NodeInstanceEntity entity) {
instance.setEnter(instantToZonedDateTime(entity.getEnter()));
instance.setExit(instantToZonedDateTime(entity.getExit()));
instance.setDefinitionId(entity.getDefinitionId());
instance.setSlaDueDate(instantToZonedDateTime(entity.getSlaDueDate()));
return instance;
}

Expand All @@ -162,6 +165,7 @@ ProcessInstanceEntity.NodeInstanceEntity fromNodeInstance(NodeInstance instance)
entity.setEnter(zonedDateTimeToInstant(instance.getEnter()));
entity.setExit(zonedDateTimeToInstant(instance.getExit()));
entity.setDefinitionId(instance.getDefinitionId());
entity.setSlaDueDate(zonedDateTimeToInstant(instance.getSlaDueDate()));
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 IF exists processes ADD COLUMN IF NOT EXISTS sla_due_date timestamp;
ALTER TABLE IF exists nodes ADD COLUMN IF NOT EXISTS sla_due_date timestamp;
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ message ProcessInstance {
optional string createdBy = 20;
/* @Field(store = Store.YES) */
optional string updatedBy = 21;
optional int64 slaDueDate = 22;
}

/* @Indexed */
Expand All @@ -177,6 +178,7 @@ message NodeInstance {
optional string definitionId = 6;
/* @Field(store = Store.YES) */
optional string nodeId = 7;
optional int64 slaDueDate = 8;
}

/* @Indexed */
Expand Down

0 comments on commit fe90635

Please sign in to comment.