Skip to content

Commit

Permalink
Expose submissionId via the Java bindings (#11839)
Browse files Browse the repository at this point in the history
* Expose submissionId via the Java bindings

Closes #11705

Will need to be forward-ported to `main` once merged.

changelog_begin
[Java Bindings] submissionId is now exposed via the bindings, see issue #11705
changelog_end

* Address #11839 (comment)
  • Loading branch information
stefanobaghino-da authored Nov 23, 2021
1 parent b27e93c commit fd03f9c
Show file tree
Hide file tree
Showing 5 changed files with 681 additions and 11 deletions.
4 changes: 4 additions & 0 deletions language-support/java/bindings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ da_scala_test_suite(
"@maven//:org_scalatestplus_scalacheck_1_15",
"@maven//:org_scala_lang_modules_scala_collection_compat",
],
scalacopts = [
"-P:silencer:globalFilters=DeduplicationTime.*deprecated", # deprecated field that needs to be tested
"-P:silencer:globalFilters=DEDUPLICATION_TIME.*deprecated", # deprecated field that needs to be tested
],
deps = [
":bindings-java",
":bindings-java-tests-lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,61 @@ public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull String submissionId,
@NonNull String party,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull List<@NonNull Command> commands) {
return CommandServiceOuterClass.SubmitAndWaitRequest.newBuilder()
.setCommands(
SubmitCommandsRequest.toProto(
ledgerId,
workflowId,
applicationId,
commandId,
submissionId,
party,
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
commands))
.build();
}

public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
@NonNull String ledgerId,
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull List<@NonNull String> actAs,
@NonNull List<@NonNull String> readAs,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull List<@NonNull Command> commands) {
return CommandServiceOuterClass.SubmitAndWaitRequest.newBuilder()
.setCommands(
SubmitCommandsRequest.toProto(
ledgerId,
workflowId,
applicationId,
commandId,
actAs,
readAs,
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
commands))
.build();
}

public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
@NonNull String ledgerId,
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull String submissionId,
@NonNull List<@NonNull String> actAs,
@NonNull List<@NonNull String> readAs,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
Expand All @@ -55,6 +110,7 @@ public static CommandServiceOuterClass.SubmitAndWaitRequest toProto(
workflowId,
applicationId,
commandId,
submissionId,
actAs,
readAs,
minLedgerTimeAbsolute,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SubmitCommandsRequest {
private final Optional<Instant> minLedgerTimeAbsolute;
private final Optional<Duration> minLedgerTimeRelative;
private final Optional<Duration> deduplicationTime;
private final Optional<String> submissionId;
private final List<Command> commands;

public SubmitCommandsRequest(
Expand Down Expand Up @@ -58,12 +59,83 @@ public SubmitCommandsRequest(
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull String submissionId,
@NonNull String party,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull List<@NonNull Command> commands) {
this(
workflowId,
applicationId,
commandId,
asList(party),
asList(),
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
Optional.of(submissionId),
commands);
}

public SubmitCommandsRequest(
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull List<@NonNull String> actAs,
@NonNull List<@NonNull String> readAs,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull List<@NonNull Command> commands) {
this(
workflowId,
applicationId,
commandId,
actAs,
readAs,
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
Optional.empty(),
commands);
}

public SubmitCommandsRequest(
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull String submissionId,
@NonNull List<@NonNull String> actAs,
@NonNull List<@NonNull String> readAs,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull List<@NonNull Command> commands) {
this(
workflowId,
applicationId,
commandId,
actAs,
readAs,
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
Optional.of(submissionId),
commands);
}

private SubmitCommandsRequest(
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull List<@NonNull String> actAs,
@NonNull List<@NonNull String> readAs,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull Optional<String> submissionId,
@NonNull List<@NonNull Command> commands) {
if (actAs.size() == 0) {
throw new IllegalArgumentException("actAs must have at least one element");
}
Expand All @@ -76,11 +148,11 @@ public SubmitCommandsRequest(
this.minLedgerTimeAbsolute = minLedgerTimeAbsolute;
this.minLedgerTimeRelative = minLedgerTimeRelative;
this.deduplicationTime = deduplicationTime;
this.submissionId = submissionId;
this.commands = commands;
}

public static SubmitCommandsRequest fromProto(CommandsOuterClass.Commands commands) {
String ledgerId = commands.getLedgerId();
String workflowId = commands.getWorkflowId();
String applicationId = commands.getApplicationId();
String commandId = commands.getCommandId();
Expand All @@ -101,13 +173,21 @@ public static SubmitCommandsRequest fromProto(CommandsOuterClass.Commands comman
commands.getMinLedgerTimeRel().getSeconds(),
commands.getMinLedgerTimeRel().getNanos()))
: Optional.empty();
Optional<Duration> deduplicationTime =
commands.hasDeduplicationTime()
? Optional.of(
Duration.ofSeconds(
commands.getDeduplicationTime().getSeconds(),
commands.getDeduplicationTime().getNanos()))
: Optional.empty();
Optional<Duration> deduplicationPeriod = Optional.empty();
switch (commands.getDeduplicationPeriodCase()) {
case DEDUPLICATION_DURATION:
com.google.protobuf.Duration d = commands.getDeduplicationDuration();
deduplicationPeriod = Optional.of(Duration.ofSeconds(d.getSeconds(), d.getNanos()));
break;
case DEDUPLICATION_TIME:
com.google.protobuf.Duration t = commands.getDeduplicationTime();
deduplicationPeriod = Optional.of(Duration.ofSeconds(t.getSeconds(), t.getNanos()));
break;
case DEDUPLICATIONPERIOD_NOT_SET:
default:
// Backwards compatibility: do not throw, this field could be empty from a previous version
}
String submissionId = commands.getSubmissionId();
ArrayList<Command> listOfCommands = new ArrayList<>(commands.getCommandsCount());
for (CommandsOuterClass.Command command : commands.getCommandsList()) {
listOfCommands.add(Command.fromProtoCommand(command));
Expand All @@ -123,11 +203,12 @@ public static SubmitCommandsRequest fromProto(CommandsOuterClass.Commands comman
readAs,
minLedgerTimeAbs,
minLedgerTimeRel,
deduplicationTime,
deduplicationPeriod,
submissionId.isEmpty() ? Optional.empty() : Optional.of(submissionId),
listOfCommands);
}

public static CommandsOuterClass.Commands toProto(
private static CommandsOuterClass.Commands toProto(
@NonNull String ledgerId,
@NonNull String workflowId,
@NonNull String applicationId,
Expand All @@ -137,6 +218,7 @@ public static CommandsOuterClass.Commands toProto(
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull Optional<String> submissionId,
@NonNull List<@NonNull Command> commands) {
if (actAs.size() == 0) {
throw new IllegalArgumentException("actAs must have at least one element");
Expand Down Expand Up @@ -171,6 +253,7 @@ public static CommandsOuterClass.Commands toProto(
com.google.protobuf.Duration.newBuilder()
.setSeconds(dedup.getSeconds())
.setNanos(dedup.getNano())));
submissionId.ifPresent(builder::setSubmissionId);
return builder.build();
}

Expand All @@ -179,6 +262,58 @@ public static CommandsOuterClass.Commands toProto(
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull List<@NonNull String> actAs,
@NonNull List<@NonNull String> readAs,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull List<@NonNull Command> commands) {
return toProto(
ledgerId,
workflowId,
applicationId,
commandId,
actAs,
readAs,
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
Optional.empty(),
commands);
}

public static CommandsOuterClass.Commands toProto(
@NonNull String ledgerId,
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull String submissionId,
@NonNull List<@NonNull String> actAs,
@NonNull List<@NonNull String> readAs,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull List<@NonNull Command> commands) {
return toProto(
ledgerId,
workflowId,
applicationId,
commandId,
actAs,
readAs,
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
Optional.of(submissionId),
commands);
}

public static CommandsOuterClass.Commands toProto(
@NonNull String ledgerId,
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull String submissionId,
@NonNull String party,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
Expand All @@ -197,6 +332,34 @@ public static CommandsOuterClass.Commands toProto(
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
Optional.of(submissionId),
commands);
}

public static CommandsOuterClass.Commands toProto(
@NonNull String ledgerId,
@NonNull String workflowId,
@NonNull String applicationId,
@NonNull String commandId,
@NonNull String party,
@NonNull Optional<Instant> minLedgerTimeAbsolute,
@NonNull Optional<Duration> minLedgerTimeRelative,
@NonNull Optional<Duration> deduplicationTime,
@NonNull List<@NonNull Command> commands) {
List<String> empty_read_as = new ArrayList<>();
List<String> act_as = new ArrayList<>();
act_as.add(party);
return toProto(
ledgerId,
workflowId,
applicationId,
commandId,
act_as,
empty_read_as,
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
Optional.empty(),
commands);
}

Expand Down Expand Up @@ -245,6 +408,11 @@ public Optional<Duration> getDeduplicationTime() {
return deduplicationTime;
}

@NonNull
public Optional<String> getSubmissionId() {
return submissionId;
}

@NonNull
public List<@NonNull Command> getCommands() {
return commands;
Expand All @@ -271,6 +439,8 @@ public String toString() {
+ minLedgerTimeRelative
+ ", deduplicationTime="
+ deduplicationTime
+ ", submissionId="
+ submissionId
+ ", commands="
+ commands
+ '}';
Expand All @@ -290,12 +460,12 @@ public boolean equals(Object o) {
&& Objects.equals(minLedgerTimeAbsolute, submitCommandsRequest1.minLedgerTimeAbsolute)
&& Objects.equals(minLedgerTimeRelative, submitCommandsRequest1.minLedgerTimeRelative)
&& Objects.equals(deduplicationTime, submitCommandsRequest1.deduplicationTime)
&& Objects.equals(submissionId, submitCommandsRequest1.submissionId)
&& Objects.equals(commands, submitCommandsRequest1.commands);
}

@Override
public int hashCode() {

return Objects.hash(
workflowId,
applicationId,
Expand All @@ -306,6 +476,7 @@ public int hashCode() {
minLedgerTimeAbsolute,
minLedgerTimeRelative,
deduplicationTime,
submissionId,
commands);
}
}
Loading

0 comments on commit fd03f9c

Please sign in to comment.