From 04dbd137487f60fb61076d902296b6cb6f652c3c Mon Sep 17 00:00:00 2001 From: Snarr Date: Tue, 3 Dec 2024 20:08:07 -0500 Subject: [PATCH] fix(server): Use Optionals for optional UserTaskTriggerReference fields --- .../UserTaskTriggerReferenceModel.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/io/littlehorse/common/model/getable/core/taskrun/UserTaskTriggerReferenceModel.java b/server/src/main/java/io/littlehorse/common/model/getable/core/taskrun/UserTaskTriggerReferenceModel.java index ec5d3fd4f..c472f5da1 100644 --- a/server/src/main/java/io/littlehorse/common/model/getable/core/taskrun/UserTaskTriggerReferenceModel.java +++ b/server/src/main/java/io/littlehorse/common/model/getable/core/taskrun/UserTaskTriggerReferenceModel.java @@ -1,5 +1,7 @@ package io.littlehorse.common.model.getable.core.taskrun; +import java.util.Optional; + import com.google.protobuf.Message; import io.littlehorse.common.LHSerializable; import io.littlehorse.common.model.getable.core.usertaskrun.UserTaskRunModel; @@ -19,8 +21,8 @@ public class UserTaskTriggerReferenceModel extends LHSerializable userId; + private Optional userGroup; public UserTaskTriggerReferenceModel() {} @@ -29,8 +31,8 @@ public UserTaskTriggerReferenceModel(UserTaskRunModel utr, ProcessorExecutionCon // Trust in the Force userTaskEventNumber = utr.getEvents().size(); - this.userId = utr.getUserId(); - this.userGroup = utr.getUserGroup(); + this.userId = Optional.of(utr.getUserId()); + this.userGroup = Optional.of(utr.getUserGroup()); } @Override @@ -42,9 +44,15 @@ public Class getProtoBaseClass() { public UserTaskTriggerReference.Builder toProto() { UserTaskTriggerReference.Builder out = UserTaskTriggerReference.newBuilder() .setNodeRunId(nodeRunId.toProto()) - .setUserTaskEventNumber(userTaskEventNumber) - .setUserId(this.userId) - .setUserGroup(this.userGroup); + .setUserTaskEventNumber(userTaskEventNumber); + + if (userId.isPresent()) { + out.setUserId(this.userId.get()); + } + + if (userGroup.isPresent()) { + out.setUserGroup(this.userGroup.get()); + } return out; } @@ -54,8 +62,8 @@ public void initFrom(Message proto, ExecutionContext context) { UserTaskTriggerReference p = (UserTaskTriggerReference) proto; nodeRunId = LHSerializable.fromProto(p.getNodeRunId(), NodeRunIdModel.class, context); userTaskEventNumber = p.getUserTaskEventNumber(); - userId = p.getUserId(); - userGroup = p.getUserGroup(); + userId = Optional.ofNullable(p.getUserId()); + userGroup = Optional.ofNullable(p.getUserGroup()); } @Override