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

[incubator-kie-issues#1637] Add SLA due date to UserTaskInstances #2151

Merged
merged 1 commit into from
Dec 18, 2024
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 @@ -370,6 +370,7 @@ type UserTaskInstance {
comments: [Comment!]
attachments: [Attachment!]
externalReferenceId : String
slaDueDate: DateTime
}

input UserTaskInstanceArgument {
Expand Down Expand Up @@ -489,4 +490,4 @@ input JobOrderBy {
retries: OrderBy
lastUpdate: OrderBy
executionCounter: OrderBy
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.kie.kogito.index.model;

import java.time.ZonedDateTime;

import com.fasterxml.jackson.databind.node.ObjectNode;

public class UserTaskInstance extends UserTaskInstanceMeta {
Expand All @@ -29,6 +31,7 @@ public class UserTaskInstance extends UserTaskInstanceMeta {
private ObjectNode outputs;
private String endpoint;
private String externalReferenceId;
private ZonedDateTime slaDueDate;

public String getProcessId() {
return processId;
Expand Down Expand Up @@ -67,6 +70,7 @@ public String toString() {
", inputs=" + inputs +
", outputs=" + outputs +
", endpoint='" + endpoint + '\'' +
", slaDueDate=" + slaDueDate +
"} " + super.toString();
}

Expand Down Expand Up @@ -103,4 +107,12 @@ public String getExternalReferenceId() {
public void setExternalReferenceId(String externalReferenceId) {
this.externalReferenceId = externalReferenceId;
}

public ZonedDateTime getSlaDueDate() {
return slaDueDate;
}

public void setSlaDueDate(ZonedDateTime slaDueDate) {
this.slaDueDate = slaDueDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public UserTaskInstance merge(UserTaskInstance task, UserTaskInstanceDataEvent<?
task.setLastUpdate(toZonedDateTime(event.getData().getEventDate()));
task.setReferenceName(event.getData().getUserTaskReferenceName());
task.setExternalReferenceId(event.getData().getExternalReferenceId());
task.setSlaDueDate(toZonedDateTime(event.getData().getSlaDueDate()));
LOGGER.debug("value after merging: {}", task);
return task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class UserTaskInstanceMarshaller extends AbstractMarshaller implements Me
protected static final String COMMENTS = "comments";
protected static final String ATTACHMENTS = "attachments";
protected static final String EXTERNAL_REFERENCE_ID = "externalReferenceId";
protected static final String SLA_DUE_DATE = "slaDueDate";

public UserTaskInstanceMarshaller(ObjectMapper mapper) {
super(mapper);
Expand Down Expand Up @@ -91,6 +92,7 @@ public UserTaskInstance readFrom(ProtoStreamReader reader) throws IOException {
ut.setComments(reader.readCollection(COMMENTS, new ArrayList<>(), Comment.class));
ut.setAttachments(reader.readCollection(ATTACHMENTS, new ArrayList<>(), Attachment.class));
ut.setExternalReferenceId(reader.readString(EXTERNAL_REFERENCE_ID));
ut.setSlaDueDate(dateToZonedDateTime(reader.readDate(SLA_DUE_DATE)));
return ut;
}

Expand Down Expand Up @@ -121,6 +123,7 @@ public void writeTo(ProtoStreamWriter writer, UserTaskInstance ut) throws IOExce
writer.writeCollection(COMMENTS, ut.getComments(), Comment.class);
writer.writeCollection(ATTACHMENTS, ut.getAttachments(), Attachment.class);
writer.writeString(EXTERNAL_REFERENCE_ID, ut.getExternalReferenceId());
writer.writeDate(SLA_DUE_DATE, zonedDateTimeToDate(ut.getSlaDueDate()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import static org.kie.kogito.index.infinispan.protostream.UserTaskInstanceMarshaller.REFERENCE_NAME;
import static org.kie.kogito.index.infinispan.protostream.UserTaskInstanceMarshaller.ROOT_PROCESS_ID;
import static org.kie.kogito.index.infinispan.protostream.UserTaskInstanceMarshaller.ROOT_PROCESS_INSTANCE_ID;
import static org.kie.kogito.index.infinispan.protostream.UserTaskInstanceMarshaller.SLA_DUE_DATE;
import static org.kie.kogito.index.infinispan.protostream.UserTaskInstanceMarshaller.STARTED;
import static org.kie.kogito.index.infinispan.protostream.UserTaskInstanceMarshaller.STATE;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -102,6 +103,7 @@ static void setup() {
TASK.setLastUpdate(ZonedDateTime.now(ZoneOffset.UTC).truncatedTo(ChronoUnit.MILLIS));
TASK.setEndpoint("endpoint");
TASK.setExternalReferenceId("externalReferenceId");
TASK.setSlaDueDate(time);
TASK.setComments(List.of(Comment.builder()
.id("attId")
.content("Text comment")
Expand Down Expand Up @@ -147,6 +149,7 @@ void testReadFrom() throws IOException {
when(reader.readCollection(eq(COMMENTS), any(), eq(Comment.class))).thenReturn(TASK.getComments());
when(reader.readCollection(eq(ATTACHMENTS), any(), eq(Attachment.class))).thenReturn(TASK.getAttachments());
when(reader.readString(EXTERNAL_REFERENCE_ID)).thenReturn(TASK.getExternalReferenceId());
when(reader.readDate(SLA_DUE_DATE)).thenReturn(marshaller.zonedDateTimeToDate(TASK.getSlaDueDate()));

UserTaskInstance task = marshaller.readFrom(reader);

Expand Down Expand Up @@ -178,6 +181,7 @@ void testReadFrom() throws IOException {
inOrder.verify(reader).readCollection(COMMENTS, new ArrayList<>(), Comment.class);
inOrder.verify(reader).readCollection(ATTACHMENTS, new ArrayList<>(), Attachment.class);
inOrder.verify(reader).readString(EXTERNAL_REFERENCE_ID);
inOrder.verify(reader).readDate(SLA_DUE_DATE);
verifyNoMoreInteractions(reader);
}

Expand Down Expand Up @@ -214,6 +218,7 @@ void testWriteTo() throws IOException {
inOrder.verify(writer).writeCollection(COMMENTS, TASK.getComments(), Comment.class);
inOrder.verify(writer).writeCollection(ATTACHMENTS, TASK.getAttachments(), Attachment.class);
inOrder.verify(writer).writeString(EXTERNAL_REFERENCE_ID, TASK.getExternalReferenceId());
inOrder.verify(writer).writeDate(SLA_DUE_DATE, marshaller.zonedDateTimeToDate(TASK.getSlaDueDate()));
verifyNoMoreInteractions(writer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public class UserTaskInstanceEntity extends AbstractEntity {
private List<CommentEntity> comments;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userTask", orphanRemoval = true, fetch = FetchType.LAZY)
private List<AttachmentEntity> attachments;

private String externalReferenceId;
private ZonedDateTime slaDueDate;

public String getExternalReferenceId() {
return externalReferenceId;
Expand Down Expand Up @@ -294,6 +294,14 @@ public void setAttachments(List<AttachmentEntity> attachments) {
this.attachments = attachments;
}

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 @@ -338,6 +346,7 @@ public String toString() {
", endpoint='" + endpoint + '\'' +
", comments='" + comments + '\'' +
", attachments='" + attachments + '\'' +
", slaDueDate=" + slaDueDate +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ private void indexState(UserTaskInstanceEntity task, UserTaskInstanceStateDataEv
task.setLastUpdate(toZonedDateTime(event.getData().getEventDate()));
task.setReferenceName(event.getData().getUserTaskReferenceName());
task.setExternalReferenceId(body.getExternalReferenceId());
task.setSlaDueDate(toZonedDateTime(body.getSlaDueDate()));
}

private String getEndpoint(URI source, String pId, String taskName, String taskId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 tasks ADD sla_due_date timestamp;
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class UserTaskInstanceEntity {

private String externalReferenceId;

private Long slaDueDate;

public String getId() {
return id;
}
Expand Down Expand Up @@ -278,6 +280,14 @@ public String getExternalReferenceId() {
return externalReferenceId;
}

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 @@ -322,6 +332,7 @@ public String toString() {
", endpoint='" + endpoint + '\'' +
", comments='" + comments + '\'' +
", attachments='" + attachments + '\'' +
", slaDueDate=" + slaDueDate +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public UserTaskInstanceEntity mapToEntity(String key, UserTaskInstance instance)
entity.setComments(Optional.ofNullable(instance.getComments()).map(comments -> comments.stream().map(this::fromComment).collect(toList())).orElse(null));
entity.setAttachments(Optional.ofNullable(instance.getAttachments()).map(attachments -> attachments.stream().map(this::fromAttachment).collect(toList())).orElse(null));
entity.setExternalReferenceId(instance.getExternalReferenceId());
entity.setSlaDueDate(zonedDateTimeToInstant(instance.getSlaDueDate()));
return entity;
}

Expand Down Expand Up @@ -115,6 +116,7 @@ public UserTaskInstance mapToModel(UserTaskInstanceEntity entity) {
instance.setComments(Optional.ofNullable(entity.getComments()).map(comments -> comments.stream().map(this::toComment).collect(toList())).orElse(null));
instance.setAttachments(Optional.ofNullable(entity.getAttachments()).map(attachments -> attachments.stream().map(this::toAttachment).collect(toList())).orElse(null));
instance.setExternalReferenceId(entity.getExternalReferenceId());
instance.setSlaDueDate(instantToZonedDateTime(entity.getSlaDueDate()));
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static void setup() {
userTaskInstance.setComments(List.of(comment));
userTaskInstance.setAttachments(List.of(attachment));
userTaskInstance.setExternalReferenceId(externalReferenceId);
userTaskInstance.setSlaDueDate(time);

userTaskInstanceEntity = new UserTaskInstanceEntity();
userTaskInstanceEntity.setId(testId);
Expand All @@ -142,6 +143,7 @@ static void setup() {
userTaskInstanceEntity.setComments(List.of(commentEntity));
userTaskInstanceEntity.setAttachments(List.of(attachmentEntity));
userTaskInstanceEntity.setExternalReferenceId(externalReferenceId);
userTaskInstanceEntity.setSlaDueDate(zonedDateTimeToInstant(time));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 tasks ADD COLUMN IF NOT EXISTS sla_due_date timestamp;
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ message UserTaskInstance {
/* @Field(store = Store.YES) */
repeated Attachment attachments = 24;
optional string externalReferenceId = 25;
optional int64 slaDueDate = 26;
}

/* @Indexed */
Expand Down Expand Up @@ -279,6 +280,7 @@ message UserTaskInstanceMeta {
/* @Field(store = Store.YES) */
repeated Attachment attachments = 18;
optional string externalReferenceId = 25;
optional int64 slaDueDate = 26;
}

/* @Indexed */
Expand Down
Loading