Skip to content

Commit

Permalink
feat (DEVEXP-166): Batches update
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier committed Nov 6, 2023
1 parent b02440e commit ef92341
Show file tree
Hide file tree
Showing 18 changed files with 979 additions and 28 deletions.
12 changes: 12 additions & 0 deletions client/src/main/com/sinch/sdk/domains/sms/BatchesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sinch.sdk.domains.sms.models.Batch;
import com.sinch.sdk.domains.sms.models.DryRun;
import com.sinch.sdk.domains.sms.models.requests.BatchesListRequestParameters;
import com.sinch.sdk.domains.sms.models.requests.UpdateBaseBatchRequest;
import com.sinch.sdk.domains.sms.models.responses.BatchesListResponse;

/**
Expand Down Expand Up @@ -62,4 +63,15 @@ DryRun dryRun(boolean perRecipient, int numberOfRecipient, BaseBatch<?> batch)
* @since 1.0
*/
BatchesListResponse list(BatchesListRequestParameters parameters) throws ApiException;

/**
* This operation updates all specified parameters of a batch that matches the provided batch ID.
*
* @param batchId The batch ID you received from sending a message
* @param <T> A type of Batch
* @return Batch information
* @since 1.0
*/
<T extends Batch<?>> T update(String batchId, UpdateBaseBatchRequest<?> batch)
throws ApiException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.sinch.sdk.domains.sms.models.DryRun;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListDto;
import com.sinch.sdk.domains.sms.models.requests.BatchesListRequestParameters;
import com.sinch.sdk.domains.sms.models.requests.UpdateBaseBatchRequest;
import com.sinch.sdk.domains.sms.models.responses.BatchesListResponse;
import com.sinch.sdk.models.Configuration;
import java.time.Instant;
Expand Down Expand Up @@ -76,4 +77,12 @@ public BatchesListResponse list(BatchesListRequestParameters parameters) throws
return new BatchesListResponse(
this, new Page<>(guardParameters, content.getLeft(), content.getRight()));
}

public <T extends Batch<?>> T update(String batchId, UpdateBaseBatchRequest<?> batch)
throws ApiException {
return BatchDtoConverter.convert(
getApi()
.updateBatchMessage(
configuration.getProjectId(), batchId, BatchDtoConverter.convert(batch)));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.sinch.sdk.domains.sms.adapters.converters;

import static com.sinch.sdk.domains.sms.models.dto.v1.BinaryRequestDto.TypeEnum.MT_BINARY;
import static com.sinch.sdk.domains.sms.models.dto.v1.MediaRequestDto.TypeEnum.MT_MEDIA;
import static com.sinch.sdk.domains.sms.models.dto.v1.TextRequestDto.TypeEnum.MT_TEXT;

import com.sinch.sdk.core.exceptions.ApiException;
import com.sinch.sdk.core.models.AbstractOpenApiSchema;
import com.sinch.sdk.core.models.pagination.PageToken;
Expand All @@ -17,6 +13,9 @@
import com.sinch.sdk.domains.sms.models.MediaBody;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListBatchesInnerDto;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiBatchListDto;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiUpdateBinaryMtMessageDto;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiUpdateMmsMtMessageDto;
import com.sinch.sdk.domains.sms.models.dto.v1.ApiUpdateTextMtMessageDto;
import com.sinch.sdk.domains.sms.models.dto.v1.BinaryRequestDto;
import com.sinch.sdk.domains.sms.models.dto.v1.BinaryResponseDto;
import com.sinch.sdk.domains.sms.models.dto.v1.MediaBodyDto;
Expand All @@ -25,9 +24,14 @@
import com.sinch.sdk.domains.sms.models.dto.v1.SendSMSRequestDto;
import com.sinch.sdk.domains.sms.models.dto.v1.TextRequestDto;
import com.sinch.sdk.domains.sms.models.dto.v1.TextResponseDto;
import com.sinch.sdk.domains.sms.models.dto.v1.UpdateBatchMessageRequestDto;
import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchBinaryRequest;
import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchMediaRequest;
import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest;
import com.sinch.sdk.domains.sms.models.requests.UpdateBaseBatchRequest;
import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchBinaryRequest;
import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchMediaRequest;
import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchTextRequest;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -138,10 +142,22 @@ public static SendSMSRequestDto convert(BaseBatch<?> value) {
}
}

public static UpdateBatchMessageRequestDto convert(UpdateBaseBatchRequest<?> value) {
if (value instanceof UpdateSmsBatchBinaryRequest) {
return convert((UpdateSmsBatchBinaryRequest) value);
} else if (value instanceof UpdateSmsBatchMediaRequest) {
return convert((UpdateSmsBatchMediaRequest) value);
} else if (value instanceof UpdateSmsBatchTextRequest) {
return convert((UpdateSmsBatchTextRequest) value);
} else {
throw new ApiException("Unexpected class:" + value.getClass().getName());
}
}

private static SendSMSRequestDto convert(SendSmsBatchBinaryRequest value) {
BinaryRequestDto dto =
new BinaryRequestDto()
.type(MT_BINARY.getValue())
.type(BinaryRequestDto.TypeEnum.MT_BINARY.getValue())
.to(new ArrayList<>(value.getTo()))
.body(value.getBody());
value.getFrom().ifPresent(dto::from);
Expand All @@ -162,7 +178,7 @@ private static SendSMSRequestDto convert(SendSmsBatchBinaryRequest value) {

private static SendSMSRequestDto convert(SendSmsBatchMediaRequest value) {
MediaRequestDto dto =
new MediaRequestDto(MT_MEDIA.getValue())
new MediaRequestDto(MediaRequestDto.TypeEnum.MT_MEDIA.getValue())
.to(new ArrayList<>(value.getTo()))
.body(convert(value.getBody()));
value.getFrom().ifPresent(dto::from);
Expand All @@ -180,7 +196,7 @@ private static SendSMSRequestDto convert(SendSmsBatchMediaRequest value) {
private static SendSMSRequestDto convert(SendSmsBatchTextRequest value) {
TextRequestDto dto =
new TextRequestDto()
.type(MT_TEXT.getValue())
.type(TextRequestDto.TypeEnum.MT_TEXT.getValue())
.to(new ArrayList<>(value.getTo()))
.body(value.getBody());
value.getFrom().ifPresent(dto::from);
Expand All @@ -199,6 +215,55 @@ private static SendSMSRequestDto convert(SendSmsBatchTextRequest value) {
return new SendSMSRequestDto(dto);
}

private static UpdateBatchMessageRequestDto convert(UpdateSmsBatchTextRequest value) {
ApiUpdateTextMtMessageDto dto =
new ApiUpdateTextMtMessageDto().type(ApiUpdateTextMtMessageDto.TypeEnum.MT_TEXT.getValue());

value.getToAdd().ifPresent(f -> dto.toAdd(new ArrayList<>(f)));
value.getToRemove().ifPresent(f -> dto.toRemove(new ArrayList<>(f)));
value.getFrom().ifPresent(dto::from);
value.getBody().ifPresent(dto::body);
value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value()));
value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC)));
value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC)));
value.getCallbackUrl().ifPresent(dto::callbackUrl);
value.getParameters().ifPresent(f -> dto.setParameters(ParametersDtoConverter.convert(f)));
return new UpdateBatchMessageRequestDto(dto);
}

private static UpdateBatchMessageRequestDto convert(UpdateSmsBatchMediaRequest value) {
ApiUpdateMmsMtMessageDto dto =
new ApiUpdateMmsMtMessageDto().type(ApiUpdateMmsMtMessageDto.TypeEnum.MT_MEDIA.getValue());

value.getToAdd().ifPresent(f -> dto.toAdd(new ArrayList<>(f)));
value.getToRemove().ifPresent(f -> dto.toRemove(new ArrayList<>(f)));
value.getFrom().ifPresent(dto::from);
value.getBody().ifPresent(f -> dto.setBody(convert(f)));
value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value()));
value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC)));
value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC)));
value.getCallbackUrl().ifPresent(dto::callbackUrl);
value.getParameters().ifPresent(f -> dto.setParameters(ParametersDtoConverter.convert(f)));
value.isStrictValidation().ifPresent(dto::strictValidation);
return new UpdateBatchMessageRequestDto(dto);
}

private static UpdateBatchMessageRequestDto convert(UpdateSmsBatchBinaryRequest value) {
ApiUpdateBinaryMtMessageDto dto =
new ApiUpdateBinaryMtMessageDto()
.type(ApiUpdateBinaryMtMessageDto.TypeEnum.MT_BINARY.getValue());
value.getToAdd().ifPresent(f -> dto.toAdd(new ArrayList<>(f)));
value.getToRemove().ifPresent(f -> dto.toRemove(new ArrayList<>(f)));
value.getFrom().ifPresent(dto::from);
value.getBody().ifPresent(dto::setBody);
value.getDeliveryReport().ifPresent(f -> dto.setDeliveryReport(f.value()));
value.getSendAt().ifPresent(f -> dto.setSendAt(f.atOffset(ZoneOffset.UTC)));
value.getExpireAt().ifPresent(f -> dto.setExpireAt(f.atOffset(ZoneOffset.UTC)));
value.getCallbackUrl().ifPresent(dto::callbackUrl);
value.getUdh().ifPresent(dto::udh);
return new UpdateBatchMessageRequestDto(dto);
}

private static MediaBodyDto convert(MediaBody value) {
return new MediaBodyDto().url(value.getUrl()).message(value.getMessage().orElse(null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public static Builder builder() {
}

public static class Builder extends BaseBatch.Builder<String, Builder> {
private boolean flashMessage;
private boolean truncateConcat;
private int maxNumberOfMessageParts;
private int fromTon;
private int fromNpi;
private Boolean flashMessage;
private Boolean truncateConcat;
private Integer maxNumberOfMessageParts;
private Integer fromTon;
private Integer fromNpi;
private String udh;

private Builder() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static Builder builder() {

public static class Builder extends BaseBatch.Builder<MediaBody, Builder> {
private Parameters parameters;
private boolean strictValidation;
private Boolean strictValidation;

private Builder() {}

Expand All @@ -95,7 +95,7 @@ public Builder setParameters(Parameters parameters) {
return this;
}

public Builder setStrictValidation(boolean strictValidation) {
public Builder setStrictValidation(Boolean strictValidation) {
this.strictValidation = strictValidation;
return this;
}
Expand Down
Loading

0 comments on commit ef92341

Please sign in to comment.