From ef9234188751a0bedee1c6545f4714ed2cc33524 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 6 Nov 2023 15:02:05 +0100 Subject: [PATCH] feat (DEVEXP-166): Batches update --- .../sinch/sdk/domains/sms/BatchesService.java | 12 ++ .../domains/sms/adapters/BatchesService.java | 9 + .../converters/BatchDtoConverter.java | 79 ++++++- .../requests/SendSmsBatchBinaryRequest.java | 10 +- .../requests/SendSmsBatchMediaRequest.java | 4 +- .../requests/UpdateBaseBatchRequest.java | 200 ++++++++++++++++++ .../requests/UpdateSmsBatchBinaryRequest.java | 74 +++++++ .../requests/UpdateSmsBatchMediaRequest.java | 105 +++++++++ .../requests/UpdateSmsBatchTextRequest.java | 72 +++++++ .../sms/adapters/BatchesServiceTest.java | 86 ++++++++ .../converters/BatchDtoConverterTest.java | 52 ++++- .../sms/adapters/api/v1/BatchesApi.java | 11 +- .../dto/v1/UpdateBatchMessageRequestDto.java | 53 +++++ .../dto/v1/UpdateSMSRequestDtoTest.java | 132 ++++++++++++ .../com/sinch/sample/sms/batches/Update.java | 42 ++++ .../sms/v1/UpdateSMSBinaryRequestDto.json | 18 ++ .../sms/v1/UpdateSMSMediaRequestDto.json | 26 +++ .../sms/v1/UpdateSMSTextRequestDto.json | 22 ++ 18 files changed, 979 insertions(+), 28 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateBaseBatchRequest.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchBinaryRequest.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchTextRequest.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/batches/Update.java create mode 100644 test-resources/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json create mode 100644 test-resources/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json diff --git a/client/src/main/com/sinch/sdk/domains/sms/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/BatchesService.java index a8c2173f..d7d75a26 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/BatchesService.java @@ -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; /** @@ -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 A type of Batch + * @return Batch information + * @since 1.0 + */ + > T update(String batchId, UpdateBaseBatchRequest batch) + throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java index 579f8ed3..ac8a7b96 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/BatchesService.java @@ -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; @@ -76,4 +77,12 @@ public BatchesListResponse list(BatchesListRequestParameters parameters) throws return new BatchesListResponse( this, new Page<>(guardParameters, content.getLeft(), content.getRight())); } + + public > T update(String batchId, UpdateBaseBatchRequest batch) + throws ApiException { + return BatchDtoConverter.convert( + getApi() + .updateBatchMessage( + configuration.getProjectId(), batchId, BatchDtoConverter.convert(batch))); + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverter.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverter.java index 275ebe66..dcb6d870 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverter.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverter.java @@ -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; @@ -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; @@ -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; @@ -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); @@ -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); @@ -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); @@ -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)); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java index 53c7500d..99a9c7e5 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java @@ -119,11 +119,11 @@ public static Builder builder() { } public static class Builder extends BaseBatch.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() {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchMediaRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchMediaRequest.java index 25a54da6..801014f6 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchMediaRequest.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchMediaRequest.java @@ -86,7 +86,7 @@ public static Builder builder() { public static class Builder extends BaseBatch.Builder { private Parameters parameters; - private boolean strictValidation; + private Boolean strictValidation; private Builder() {} @@ -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; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateBaseBatchRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateBaseBatchRequest.java new file mode 100644 index 00000000..93da139b --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateBaseBatchRequest.java @@ -0,0 +1,200 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReport; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +/** + * Base class for Batch types + * + * @param Type of batch + * @since 1.0 + */ +public class UpdateBaseBatchRequest { + + private final String from; + + private final T body; + + private final Collection toAdd; + + private final Collection toRemove; + + private final DeliveryReport deliveryReport; + + private final Instant sendAt; + + private final Instant expireAt; + + private final String callbackUrl; + + /** + * @param toAdd List of phone numbers and group IDs to add to the batch. + * @param toRemove List of phone numbers and group IDs to remove from the batch. + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + */ + public UpdateBaseBatchRequest( + Collection toAdd, + Collection toRemove, + String from, + T body, + DeliveryReport deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl) { + this.toAdd = toAdd; + this.toRemove = toRemove; + this.from = from; + this.body = body; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + } + + public static BatchBuilder batchBuilder() { + return new BatchBuilder<>(); + } + + public Optional> getToAdd() { + return Optional.ofNullable(toAdd); + } + + public Optional> getToRemove() { + return Optional.ofNullable(toRemove); + } + + public Optional getBody() { + return Optional.ofNullable(body); + } + + public Optional getFrom() { + return Optional.ofNullable(from); + } + + public Optional getDeliveryReport() { + return Optional.ofNullable(deliveryReport); + } + + public Optional getSendAt() { + return Optional.ofNullable(sendAt); + } + + public Optional getExpireAt() { + return Optional.ofNullable(expireAt); + } + + public Optional getCallbackUrl() { + return Optional.ofNullable(callbackUrl); + } + + @Override + public String toString() { + return "UpdateBaseBatchRequest{" + + "from='" + + from + + '\'' + + ", body=" + + body + + ", toAdd=" + + toAdd + + ", toRemove=" + + toRemove + + ", deliveryReport=" + + deliveryReport + + ", sendAt=" + + sendAt + + ", expireAt=" + + expireAt + + ", callbackUrl='" + + callbackUrl + + '\'' + + '}'; + } + + protected static class Builder> { + + public Collection toAdd; + + public Collection toRemove; + + public String from; + + public T body; + + public DeliveryReport deliveryReport; + + public Instant sendAt; + + public Instant expireAt; + + public String callbackUrl; + + public B setToAdd(Collection toAdd) { + this.toAdd = toAdd; + return self(); + } + + public B setToRemove(Collection toRemove) { + this.toRemove = toRemove; + return self(); + } + + public B setFrom(String from) { + this.from = from; + return self(); + } + + public B setBody(T body) { + this.body = body; + return self(); + } + + public B setDeliveryReport(DeliveryReport deliveryReport) { + this.deliveryReport = deliveryReport; + return self(); + } + + public B setSendAt(Instant sendAt) { + this.sendAt = sendAt; + return self(); + } + + public B setExpireAt(Instant expireAt) { + this.expireAt = expireAt; + return self(); + } + + public B setCallbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + return self(); + } + + public UpdateBaseBatchRequest build() { + return new UpdateBaseBatchRequest<>( + toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl); + } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + } + + public static class BatchBuilder extends UpdateBaseBatchRequest.Builder> { + @Override + protected BatchBuilder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchBinaryRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchBinaryRequest.java new file mode 100644 index 00000000..f076d78b --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchBinaryRequest.java @@ -0,0 +1,74 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReport; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class UpdateSmsBatchBinaryRequest extends UpdateBaseBatchRequest { + private final String udh; + /** + * @param toAdd List of phone numbers and group IDs to add to the batch.List of Phone numbers and + * group IDs that will receive the batch + * @param toRemove List of phone numbers and group IDs to remove from the batch + * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required if + * Automatic Default Originator not configured. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param udh The UDH header of a binary message HEX encoded. Max 140 bytes including the body. + */ + public UpdateSmsBatchBinaryRequest( + Collection toAdd, + Collection toRemove, + String from, + String body, + DeliveryReport deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + String udh) { + super(toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl); + this.udh = udh; + } + + public Optional getUdh() { + return Optional.ofNullable(udh); + } + + @Override + public String toString() { + return "UpdateSmsBatchBinaryRequest{" + "udh='" + udh + '\'' + "} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends UpdateBaseBatchRequest.Builder { + + private String udh; + + private Builder() {} + + public Builder setUdh(String udh) { + this.udh = udh; + return this; + } + + public UpdateSmsBatchBinaryRequest build() { + return new UpdateSmsBatchBinaryRequest( + toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl, udh); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java new file mode 100644 index 00000000..15dfadf8 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchMediaRequest.java @@ -0,0 +1,105 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReport; +import com.sinch.sdk.domains.sms.models.MediaBody; +import com.sinch.sdk.domains.sms.models.Parameters; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class UpdateSmsBatchMediaRequest extends UpdateBaseBatchRequest { + private final Parameters parameters; + private final Boolean strictValidation; + /** + * @param toAdd List of phone numbers and group IDs to add to the batch. + * @param toRemove List of phone numbers and group IDs to remove from the batch. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param parameters Contains the parameters that will be used for customizing the message for + * each recipient. + * @param strictValidation Whether or not you want the media included in your message to be + * checked against Sinch MMS channel best practices. If set to true, your message will be + * rejected if it doesn't conform to the listed recommendations, otherwise no validation will + * be performed + */ + public UpdateSmsBatchMediaRequest( + Collection toAdd, + Collection toRemove, + String from, + MediaBody body, + DeliveryReport deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + Parameters parameters, + Boolean strictValidation) { + super(toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl); + this.parameters = parameters; + this.strictValidation = strictValidation; + } + + public Optional getParameters() { + return Optional.ofNullable(parameters); + } + + public Optional isStrictValidation() { + return Optional.ofNullable(strictValidation); + } + + @Override + public String toString() { + return "UpdateSmsBatchMediaRequest{" + + "parameters=" + + parameters + + ", strictValidation=" + + strictValidation + + "} " + + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends UpdateBaseBatchRequest.Builder { + private Parameters parameters; + private Boolean strictValidation; + + private Builder() {} + + public Builder setParameters(Parameters parameters) { + this.parameters = parameters; + return this; + } + + public Builder setStrictValidation(Boolean strictValidation) { + this.strictValidation = strictValidation; + return this; + } + + public UpdateSmsBatchMediaRequest build() { + return new UpdateSmsBatchMediaRequest( + toAdd, + toRemove, + from, + body, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + parameters, + strictValidation); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchTextRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchTextRequest.java new file mode 100644 index 00000000..ba2636d5 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/UpdateSmsBatchTextRequest.java @@ -0,0 +1,72 @@ +package com.sinch.sdk.domains.sms.models.requests; + +import com.sinch.sdk.domains.sms.models.DeliveryReport; +import com.sinch.sdk.domains.sms.models.Parameters; +import java.time.Instant; +import java.util.Collection; +import java.util.Optional; + +public class UpdateSmsBatchTextRequest extends UpdateBaseBatchRequest { + private final Parameters parameters; + /** + * @param toAdd List of phone numbers and group IDs to add to the batch. + * @param toRemove List of phone numbers and group IDs to remove from the batch. + * @param body The message content + * @param deliveryReport Request delivery report callback. Note that delivery reports can be + * fetched from the API regardless of this setting + * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately + * @param expireAt If set, the system will stop trying to deliver the message at this point. Must + * be after send_at. Default and max is 3 days after send_at + * @param callbackUrl Override the default callback URL for this batch. Must be valid URL. + * @param parameters Contains the parameters that will be used for customizing the message for + * each recipient. + */ + public UpdateSmsBatchTextRequest( + Collection toAdd, + Collection toRemove, + String from, + String body, + DeliveryReport deliveryReport, + Instant sendAt, + Instant expireAt, + String callbackUrl, + Parameters parameters) { + super(toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl); + this.parameters = parameters; + } + + public Optional getParameters() { + return Optional.ofNullable(parameters); + } + + @Override + public String toString() { + return "UpdateSmsBatchTextRequest{" + "parameters=" + parameters + "} " + super.toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends UpdateBaseBatchRequest.Builder { + private Parameters parameters; + + private Builder() {} + + public Builder setParameters(Parameters parameters) { + this.parameters = parameters; + return this; + } + + public UpdateSmsBatchTextRequest build() { + return new UpdateSmsBatchTextRequest( + toAdd, toRemove, from, body, deliveryReport, sendAt, expireAt, callbackUrl, parameters); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java index c84ae5c9..18a54cf2 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java @@ -27,6 +27,9 @@ 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.UpdateSmsBatchBinaryRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchMediaRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchTextRequest; import com.sinch.sdk.domains.sms.models.responses.BatchesListResponse; import com.sinch.sdk.models.Configuration; import java.time.Instant; @@ -193,6 +196,47 @@ public class BatchesServiceTest extends BaseTest { .setParameters(parameters) .build(); + public static final UpdateSmsBatchTextRequest updateSmsBatchTextRequest = + UpdateSmsBatchTextRequest.builder() + .setToAdd(to) + .setFrom(from) + .setBody(body) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setParameters(parameters) + .build(); + + public static final UpdateSmsBatchMediaRequest updateSmsBatchMediaRequest = + UpdateSmsBatchMediaRequest.builder() + .setToRemove(to) + .setFrom(from) + .setBody( + new MediaBody( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png", + "Media message from Sinch!")) + .setDeliveryReport(DeliveryReport.SUMMARY) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setCallbackUrl(callbackUrl) + .setStrictValidation(true) + .setParameters(parameters) + .build(); + + public static final UpdateSmsBatchBinaryRequest updateSmsBatchBinaryRequest = + UpdateSmsBatchBinaryRequest.builder() + .setToAdd(Arrays.asList("+15551231234", "+15987365412")) + .setToRemove(Arrays.asList("+0123456789", "+9876543210")) + .setFrom(from) + .setBody(body) + .setDeliveryReport(DeliveryReport.FULL) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setUdh(udh) + .build(); + @GivenJsonResource("/domains/sms/v1/BinaryResponseDto.json") public SendSMS201ResponseDto binaryResponseDto; @@ -384,4 +428,46 @@ void list() throws ApiException { .setFeedbackEnabled(false) .build()); } + + @Test + void updateText() throws ApiException { + + when(api.updateBatchMessage( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(updateSmsBatchTextRequest)))) + .thenReturn(textResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchTextRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchText); + } + + @Test + void updateMedia() throws ApiException { + + when(api.updateBatchMessage( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(updateSmsBatchMediaRequest)))) + .thenReturn(mediaResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchMediaRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchMedia); + } + + @Test + void updateBinary() throws ApiException { + + when(api.updateBatchMessage( + eq(configuration.getProjectId()), + eq("foo text batch id"), + eq(BatchDtoConverter.convert(updateSmsBatchBinaryRequest)))) + .thenReturn(binaryResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchBinaryRequest); + + Assertions.assertThat(response).usingRecursiveComparison().isEqualTo(batchBinary); + } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java index 7bedf935..ba76e12c 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java @@ -23,6 +23,7 @@ import com.sinch.sdk.domains.sms.models.dto.v1.SendSMS201ResponseDto; import com.sinch.sdk.domains.sms.models.dto.v1.SendSMSRequestDto; import com.sinch.sdk.domains.sms.models.dto.v1.TextResponseDto; +import com.sinch.sdk.domains.sms.models.dto.v1.UpdateBatchMessageRequestDto; import java.util.Collection; import java.util.Map; import java.util.Optional; @@ -42,13 +43,22 @@ class BatchDtoConverterTest extends BaseTest { public SendSMS201ResponseDto mediaResponseDto; @GivenJsonResource("/domains/sms/v1/SendSMSBinaryRequestDto.json") - public SendSMSRequestDto binaryRequestDto; + public SendSMSRequestDto sendBinaryRequestDto; @GivenJsonResource("/domains/sms/v1/SendSMSTextRequestDto.json") - public SendSMSRequestDto textRequestDto; + public SendSMSRequestDto sendTextRequestDto; @GivenJsonResource("/domains/sms/v1/SendSMSMediaRequestDto.json") - public SendSMSRequestDto mediaRequestDto; + public SendSMSRequestDto sendMediaRequestDto; + + @GivenJsonResource("/domains/sms/v1/UpdateSMSTextRequestDto.json") + public UpdateBatchMessageRequestDto updateTextRequestDto; + + @GivenJsonResource("/domains/sms/v1/UpdateSMSMediaRequestDto.json") + public UpdateBatchMessageRequestDto updateMediaRequestDto; + + @GivenJsonResource("/domains/sms/v1/UpdateSMSBinaryRequestDto.json") + public UpdateBatchMessageRequestDto updateBinaryRequestDto; public static void compareWithDto(Batch client, SendSMS201ResponseDto dto) { Object obj = dto.getActualInstance(); @@ -168,26 +178,50 @@ void convertTextResponse() { } @Test - void convertBinaryRequest() { + void convertSendBinaryRequest() { org.assertj.core.api.Assertions.assertThat( BatchDtoConverter.convert(BatchesServiceTest.sendSmsBatchBinaryRequest)) .usingRecursiveComparison() - .isEqualTo(binaryRequestDto); + .isEqualTo(sendBinaryRequestDto); } @Test - void convertMediaRequest() { + void convertSendtediaRequest() { org.assertj.core.api.Assertions.assertThat( BatchDtoConverter.convert(BatchesServiceTest.sendSmsBatchMediaRequest)) .usingRecursiveComparison() - .isEqualTo(mediaRequestDto); + .isEqualTo(sendMediaRequestDto); } @Test - void convertTextRequest() { + void convertSendTextRequest() { org.assertj.core.api.Assertions.assertThat( BatchDtoConverter.convert(BatchesServiceTest.sendSmsBatchTextRequest)) .usingRecursiveComparison() - .isEqualTo(textRequestDto); + .isEqualTo(sendTextRequestDto); + } + + @Test + void convertUpdateTextRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchTextRequest)) + .usingRecursiveComparison() + .isEqualTo(updateTextRequestDto); + } + + @Test + void convertUpdateMediaRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchMediaRequest)) + .usingRecursiveComparison() + .isEqualTo(updateMediaRequestDto); + } + + @Test + void convertUpdateBinaryRequest() { + org.assertj.core.api.Assertions.assertThat( + BatchDtoConverter.convert(BatchesServiceTest.updateSmsBatchBinaryRequest)) + .usingRecursiveComparison() + .isEqualTo(updateBinaryRequestDto); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java index a161c8a8..e744df08 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java @@ -55,11 +55,12 @@ public BatchesApi( } /** - * Cancel a batch message A batch can be canceled aty point. If a batch is canceled while it's - * currently being delivered some messages currently being processed might still be delivered. The - * delivery report will indicate which messages were canceled and which weren't. Canceling a - * batch scheduled in the future will result in an empty delivery report while canceling an - * already sent batch would result in no change to the completed delivery report. + * Cancel a batch message A batch can be canceled at any point. If a batch is canceled while + * it's currently being delivered some messages currently being processed might still be + * delivered. The delivery report will indicate which messages were canceled and which + * weren't. Canceling a batch scheduled in the future will result in an empty delivery report + * while canceling an already sent batch would result in no change to the completed delivery + * report. * * @param servicePlanId Your service plan ID. You can find this on your * [Dashboard](https://dashboard.sinch.com/sms/api/rest). (required) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/UpdateBatchMessageRequestDto.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/UpdateBatchMessageRequestDto.java index d41b118d..17d2c358 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/UpdateBatchMessageRequestDto.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/dto/v1/UpdateBatchMessageRequestDto.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; @@ -75,6 +76,48 @@ public UpdateBatchMessageRequestDto deserialize(JsonParser jp, DeserializationCo throws IOException, JsonProcessingException { JsonNode tree = jp.readValueAsTree(); Object deserialized = null; + UpdateBatchMessageRequestDto newUpdateBatchMessageRequestDto = + new UpdateBatchMessageRequestDto(); + Map result2 = + tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + String discriminatorValue = (String) result2.get("type"); + switch (discriminatorValue) { + case "ApiUpdateBinaryMtMessage": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(ApiUpdateBinaryMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "ApiUpdateMmsMtMessage": + deserialized = tree.traverse(jp.getCodec()).readValueAs(ApiUpdateMmsMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "ApiUpdateTextMtMessage": + deserialized = tree.traverse(jp.getCodec()).readValueAs(ApiUpdateTextMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "mt_binary": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(ApiUpdateBinaryMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "mt_media": + deserialized = tree.traverse(jp.getCodec()).readValueAs(ApiUpdateMmsMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + case "mt_text": + deserialized = tree.traverse(jp.getCodec()).readValueAs(ApiUpdateTextMtMessageDto.class); + newUpdateBatchMessageRequestDto.setActualInstance(deserialized); + return newUpdateBatchMessageRequestDto; + default: + log.log( + Level.WARNING, + String.format( + "Failed to lookup discriminator value `%s` for UpdateBatchMessageRequestDto." + + " Possible values: ApiUpdateBinaryMtMessage ApiUpdateMmsMtMessage" + + " ApiUpdateTextMtMessage mt_binary mt_media mt_text", + discriminatorValue)); + } + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); @@ -251,6 +294,16 @@ public UpdateBatchMessageRequestDto(ApiUpdateTextMtMessageDto o) { schemas.put("ApiUpdateTextMtMessageDto", ApiUpdateTextMtMessageDto.class); JSONNavigator.registerDescendants( UpdateBatchMessageRequestDto.class, Collections.unmodifiableMap(schemas)); + // Initialize and register the discriminator mappings. + Map> mappings = new HashMap>(); + mappings.put("ApiUpdateBinaryMtMessage", ApiUpdateBinaryMtMessageDto.class); + mappings.put("ApiUpdateMmsMtMessage", ApiUpdateMmsMtMessageDto.class); + mappings.put("ApiUpdateTextMtMessage", ApiUpdateTextMtMessageDto.class); + mappings.put("mt_binary", ApiUpdateBinaryMtMessageDto.class); + mappings.put("mt_media", ApiUpdateMmsMtMessageDto.class); + mappings.put("mt_text", ApiUpdateTextMtMessageDto.class); + mappings.put("UpdateBatchMessage_request", UpdateBatchMessageRequestDto.class); + JSONNavigator.registerDiscriminator(UpdateBatchMessageRequestDto.class, "type", mappings); } @Override diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java new file mode 100644 index 00000000..66bcddf6 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/UpdateSMSRequestDtoTest.java @@ -0,0 +1,132 @@ +package com.sinch.sdk.domains.sms.models.dto.v1; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import java.time.OffsetDateTime; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +class UpdateSMSRequestDtoTest extends BaseTest { + @GivenTextResource("/domains/sms/v1/UpdateSMSBinaryRequestDto.json") + String jsonRequestBinaryDto; + + @GivenTextResource("/domains/sms/v1/UpdateSMSTextRequestDto.json") + String jsonRequestTextDto; + + @GivenTextResource("/domains/sms/v1/UpdateSMSMediaRequestDto.json") + String jsonRequestMediaDto; + + @Test + void serializeBinaryRequestDto() throws JsonProcessingException, JSONException { + + ApiUpdateBinaryMtMessageDto binaryRequestDTO = + new ApiUpdateBinaryMtMessageDto() + .toAdd(Arrays.asList("+15551231234", "+15987365412")) + .toRemove(Arrays.asList("+0123456789", "+9876543210")) + .body("Hi ${name}! How are you?") + .udh("foo udh") + .from("+15551231234") + .type("mt_binary") + .deliveryReport("full") + .sendAt(OffsetDateTime.parse("2019-08-24T14:19:22Z")) + .expireAt(OffsetDateTime.parse("2019-08-24T14:21:22Z")) + .callbackUrl("callback url"); + UpdateBatchMessageRequestDto sendSMSRequestDto = + new UpdateBatchMessageRequestDto(binaryRequestDTO); + + String serializedString = objectMapper.writeValueAsString(sendSMSRequestDto); + + JSONAssert.assertEquals(jsonRequestBinaryDto, serializedString, true); + } + + @Test + void serializeTextRequestDto() throws JsonProcessingException, JSONException { + + ParameterObjDto parameterObjDto = new ParameterObjDto(); + parameterObjDto.put( + "an identifier", + Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( + ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, + Stream.of( + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto + .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, + "msisdn value"), + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + ApiUpdateTextMtMessageDto textRequestDTO = + new ApiUpdateTextMtMessageDto() + .toAdd(Arrays.asList("+15551231234", "+15551256344")) + .body("Hi ${name}! How are you?") + .from("+15551231234") + .type("mt_text") + .deliveryReport("none") + .sendAt(OffsetDateTime.parse("2019-08-24T14:19:22Z")) + .expireAt(OffsetDateTime.parse("2019-08-24T14:21:22Z")) + .callbackUrl("callback url") + .parameters(parameterObjDto); + + UpdateBatchMessageRequestDto sendSMSRequestDto = + new UpdateBatchMessageRequestDto(textRequestDTO); + + String serializedString = objectMapper.writeValueAsString(sendSMSRequestDto); + + JSONAssert.assertEquals(jsonRequestTextDto, serializedString, true); + } + + @Test + void serializeMediaRequestDto() throws JsonProcessingException, JSONException { + + ParameterObjDto parameterObjDto = new ParameterObjDto(); + parameterObjDto.put( + "an identifier", + Stream.of(new AbstractMap.SimpleEntry<>("a key", "a value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + parameterObjDto.put( + ParameterObjDto.JSON_PROPERTY_LEFT_CURLY_BRACKET_PARAMETER_KEY_RIGHT_CURLY_BRACKET, + Stream.of( + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto + .JSON_PROPERTY_LEFT_CURLY_BRACKET_MSISDN_RIGHT_CURLY_BRACKET, + "msisdn value"), + new AbstractMap.SimpleEntry<>( + ParameterObjParameterKeyDto.JSON_PROPERTY_DEFAULT, "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); + + ApiUpdateMmsMtMessageDto mediaRequestDTO = + new ApiUpdateMmsMtMessageDto() + .type("mt_media") + .toRemove(Arrays.asList("+15551231234", "+15551256344")) + .body( + new MediaBodyDto() + .url( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") + .message("Media message from Sinch!")) + .from("+15551231234") + .deliveryReport("summary") + .sendAt(OffsetDateTime.parse("2019-08-24T14:16:22Z")) + .expireAt(OffsetDateTime.parse("2019-08-24T14:17:22Z")) + .callbackUrl("callback url") + .strictValidation(true) + .parameters(parameterObjDto); + + UpdateBatchMessageRequestDto sendSMSRequestDto = + new UpdateBatchMessageRequestDto(mediaRequestDTO); + + String serializedString = objectMapper.writeValueAsString(sendSMSRequestDto); + + JSONAssert.assertEquals(jsonRequestMediaDto, serializedString, true); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/Update.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/Update.java new file mode 100644 index 00000000..9f661161 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/Update.java @@ -0,0 +1,42 @@ +package com.sinch.sample.sms.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.models.BatchText; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchTextRequest; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class Update extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Update.class.getName()); + + public Update() throws IOException {} + + public static void main(String[] args) { + try { + new Update().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + LOGGER.info("Updating batch: " + batchId); + BatchText value = + client + .sms() + .batches() + .update( + batchId, + UpdateSmsBatchTextRequest.builder() + .setToRemove(Collections.singletonList("+33745149803")) + .setToAdd(Collections.singletonList("+33745149803")) + .setBody("the body updated") + .setFrom("+33123456789") + .build()); + + LOGGER.info("Response: " + value); + } +} diff --git a/test-resources/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json new file mode 100644 index 00000000..2df9a741 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSBinaryRequestDto.json @@ -0,0 +1,18 @@ +{ + "to_add": [ + "+15551231234", + "+15987365412" + ], + "to_remove": [ + "+0123456789", + "+9876543210" + ], + "from": "+15551231234", + "body": "Hi ${name}! How are you?", + "type": "mt_binary", + "delivery_report": "full", + "send_at": "2019-08-24T14:19:22Z", + "expire_at": "2019-08-24T14:21:22Z", + "callback_url": "callback url", + "udh": "foo udh" +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json new file mode 100644 index 00000000..a17cdf9f --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSMediaRequestDto.json @@ -0,0 +1,26 @@ +{ + "to_remove": [ + "+15551231234", + "+15551256344" + ], + "from": "+15551231234", + "body": { + "message": "Media message from Sinch!", + "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" + }, + "parameters": { + "{parameter_key}": { + "{msisdn}": "msisdn value", + "default": "default value" + }, + "an identifier": { + "a key": "a value" + } + }, + "type": "mt_media", + "delivery_report": "summary", + "send_at": "2019-08-24T14:16:22Z", + "expire_at": "2019-08-24T14:17:22Z", + "callback_url": "callback url", + "strict_validation": true +} \ No newline at end of file diff --git a/test-resources/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json new file mode 100644 index 00000000..fe552725 --- /dev/null +++ b/test-resources/src/test/resources/domains/sms/v1/UpdateSMSTextRequestDto.json @@ -0,0 +1,22 @@ +{ + "to_add": [ + "+15551231234", + "+15551256344" + ], + "from": "+15551231234", + "body": "Hi ${name}! How are you?", + "type": "mt_text", + "delivery_report": "none", + "send_at": "2019-08-24T14:19:22Z", + "expire_at": "2019-08-24T14:21:22Z", + "callback_url": "callback url", + "parameters": { + "{parameter_key}": { + "{msisdn}": "msisdn value", + "default": "default value" + }, + "an identifier": { + "a key": "a value" + } + } +} \ No newline at end of file