Skip to content

Commit

Permalink
fix(server): Use Optionals for optional UserTaskTriggerReference fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Snarr committed Dec 4, 2024
1 parent 806d5a1 commit 04dbd13
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,8 +21,8 @@ public class UserTaskTriggerReferenceModel extends LHSerializable<UserTaskTrigge
private NodeRunIdModel nodeRunId;
private int userTaskEventNumber;

private String userId;
private String userGroup;
private Optional<String> userId;
private Optional<String> userGroup;

public UserTaskTriggerReferenceModel() {}

Expand All @@ -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
Expand All @@ -42,9 +44,15 @@ public Class<UserTaskTriggerReference> 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;
}
Expand All @@ -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
Expand Down

0 comments on commit 04dbd13

Please sign in to comment.