Skip to content

Commit

Permalink
fix: add single target boolean on bridge command
Browse files Browse the repository at this point in the history
  - in order to differentiate old single and multi reply, a boolean has been added to new bridge payload
  • Loading branch information
guillaumelamirand committed Apr 12, 2024
1 parent f26a9fc commit 4eafc5e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.cockpit.api.command.legacy.CockpitReplyType;
import io.gravitee.cockpit.api.command.v1.bridge.BridgeReply;
import io.gravitee.cockpit.api.command.v1.bridge.BridgeReplyPayload;
import io.gravitee.exchange.api.command.CommandStatus;
import io.gravitee.exchange.api.command.ReplyAdapter;
import io.reactivex.rxjava3.core.Single;
import java.util.List;
Expand Down Expand Up @@ -46,12 +47,13 @@ public Single<io.gravitee.cockpit.api.command.v1.bridge.BridgeReply> adapt(
.organizationId(bridgeSimpleReply.getOrganizationId())
.installationId(bridgeSimpleReply.getInstallationId())
.content(bridgeSimpleReply.getPayloadAsString())
.error(bridgeSimpleReply.getCommandStatus() == CommandStatus.ERROR)
.build()
)
.toList();
return new io.gravitee.cockpit.api.command.v1.bridge.BridgeReply(
reply.getCommandId(),
new BridgeReplyPayload(contents)
new BridgeReplyPayload(false, contents)
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.gravitee.cockpit.api.command.legacy.CockpitReplyType;
import io.gravitee.cockpit.api.command.v1.bridge.BridgeReply;
import io.gravitee.cockpit.api.command.v1.bridge.BridgeReplyPayload;
import io.gravitee.exchange.api.command.CommandStatus;
import io.gravitee.exchange.api.command.ReplyAdapter;
import io.reactivex.rxjava3.core.Single;
import java.util.List;
Expand All @@ -39,13 +40,15 @@ public Single<io.gravitee.cockpit.api.command.v1.bridge.BridgeReply> adapt(
new io.gravitee.cockpit.api.command.v1.bridge.BridgeReply(
reply.getCommandId(),
new BridgeReplyPayload(
true,
List.of(
BridgeReplyPayload.BridgeReplyContent
.builder()
.environmentId(reply.getEnvironmentId())
.organizationId(reply.getOrganizationId())
.installationId(reply.getInstallationId())
.content(reply.getPayloadAsString())
.error(reply.getCommandStatus() == CommandStatus.ERROR)
.build()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ public Single<BridgeReply> adapt(
) {
return Single.fromCallable(() -> {
BridgeReplyPayload replyPayload = reply.getPayload();
if (replyPayload.contents() != null) {
if (replyPayload.contents().size() == 1) {
if (
replyPayload != null &&
replyPayload.contents() != null &&
!replyPayload.contents().isEmpty()
) {
if (replyPayload.singleTarget()) {
BridgeReplyPayload.BridgeReplyContent bridgeReplyContent =
replyPayload.contents().get(0);
return createSimpleReplyFrom(reply, bridgeReplyContent);
} else if (replyPayload.contents().size() > 1) {
} else {
List<BridgeSimpleReply> simpleReplies = replyPayload
.contents()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public record BridgeReplyPayload(List<BridgeReplyContent> contents)
public record BridgeReplyPayload(
boolean singleTarget,
List<BridgeReplyContent> contents
)
implements Payload {
@Builder
@AllArgsConstructor
Expand Down

0 comments on commit 4eafc5e

Please sign in to comment.