Skip to content

Commit

Permalink
[Communication] Revert "[Communication] Change SMS APIs to be pageable (
Browse files Browse the repository at this point in the history
#20042)" (#20104)

* Revert "[Communication] Change SMS APIs to be pageable (#20042)"

This reverts commit 9c5d7bf.

* Changes to keep

* Update versions in the package POM

* Include other valid APIView feedback

* PR feedback

* remove unused logger
  • Loading branch information
ankitarorabit authored Mar 26, 2021
1 parent 438a0cb commit 221def1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 66 deletions.
4 changes: 1 addition & 3 deletions sdk/communication/azure-communication-sms/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Release History
## 1.0.0 (2021-03-29)

### Breaking Change
- Changed the return type of the batch `Send` in `SmsClient` and `SmsAsyncClient` to `PagedIterable<SmsSendResult>` and `PagedFlux<SmsSendResult>`, respectively.
Updated `azure-communication-sms` version

## 1.0.0-beta.4 (2021-03-09)
### Added
Expand Down
9 changes: 5 additions & 4 deletions sdk/communication/azure-communication-sms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ SmsSendOptions options = new SmsSendOptions();
options.setDeliveryReportEnabled(true);
options.setTag("Marketing");

Iterable<SmsSendResult> sendResults = smsClient.send(
Iterable<SmsSendResult> sendResults = smsClient.sendWithResponse(
"<from-phone-number>",
Arrays.asList("<to-phone-number1>", "<to-phone-number2>"),
"Weekly Promotion",
options /* Optional */,
Context.NONE);
Context.NONE).getValue();

for (SmsSendResult result : sendResults) {
System.out.println("Message Id: " + result.getMessageId());
Expand All @@ -131,20 +131,21 @@ for (SmsSendResult result : sendResults) {
SMS operations will throw an exception if the request to the server fails.
Exceptions will not be thrown if the error is caused by an individual message, only if something fails with the overall request.
Please use the `isSuccessful()` flag to validate each individual result to verify if the message was sent.
<!-- embedme src/samples/java/com/azure/communication/sms/samples/quickstart/ReadmeSamples.java#L153-L175 -->
<!-- embedme src/samples/java/com/azure/communication/sms/samples/quickstart/ReadmeSamples.java#L153-L176 -->
```java
try {
SmsSendOptions options = new SmsSendOptions();
options.setDeliveryReportEnabled(true);
options.setTag("Marketing");

PagedIterable<SmsSendResult> smsSendResults = smsClient.send(
Response<Iterable<SmsSendResult>> sendResults = smsClient.sendWithResponse(
"<from-phone-number>",
Arrays.asList("<to-phone-number1>", "<to-phone-number2>"),
"Weekly Promotion",
options /* Optional */,
Context.NONE);

Iterable<SmsSendResult> smsSendResults = sendResults.getValue();
for (SmsSendResult result : smsSendResults) {
if (result.isSuccessful()) {
System.out.println("Successfully sent this message: " + result.getMessageId() + " to " + result.getTo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
Expand Down Expand Up @@ -97,9 +95,10 @@ Mono<SmsSendResult> send(String from, String to, String message, SmsSendOptions
* @param message message to send to recipient.
* @return response for a successful send Sms request.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<SmsSendResult> send(String from, Iterable<String> to, String message) {
return send(from, to, message, null, null);
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Iterable<SmsSendResult>> send(String from, Iterable<String> to, String message) {
return sendWithResponse(from, to, message, null)
.map(response -> response.getValue());
}

/**
Expand All @@ -112,39 +111,28 @@ public PagedFlux<SmsSendResult> send(String from, Iterable<String> to, String me
* for this message to the Azure Resource Event Grid.
* @return response for a successful send Sms request.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedFlux<SmsSendResult> send(String from, Iterable<String> to, String message, SmsSendOptions options) {
return send(from, to, message, options, null);
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Iterable<SmsSendResult>>> sendWithResponse(String from, Iterable<String> to, String message, SmsSendOptions options) {
return sendWithResponse(from, to, message, options, null);
}

PagedFlux<SmsSendResult> send(String from, Iterable<String> to, String message, SmsSendOptions options, Context context) {
Mono<Response<Iterable<SmsSendResult>>> sendWithResponse(String from, Iterable<String> to, String message, SmsSendOptions options, Context context) {
try {
Objects.requireNonNull(from, "'from' cannot be null.");
Objects.requireNonNull(to, "'to' cannot be null.");
SendMessageRequest request = createSendMessageRequest(from, to, message, options);

Mono<Response<List<SmsSendResult>>> responseMono = withContext(contextValue -> {
return withContext(contextValue -> {
if (context != null) {
contextValue = context;
}
return this.smsClient.sendWithResponseAsync(request, contextValue)
.flatMap((Response<SmsSendResponse> response) -> {
List<SmsSendResult> smsSendResults = convertSmsSendResults(response.getValue().getValue());
return Mono.just(new SimpleResponse<List<SmsSendResult>>(response, smsSendResults));
Iterable<SmsSendResult> smsSendResults = convertSmsSendResults(response.getValue().getValue());
return Mono.just(new SimpleResponse<Iterable<SmsSendResult>>(response, smsSendResults));
});
});

return new PagedFlux<>(() -> responseMono.map(response -> new PagedResponseBase<Void, SmsSendResult>(
response.getRequest(),
response.getStatusCode(),
response.getHeaders(),
response.getValue(),
null,
null
)));

} catch (RuntimeException ex) {
return new PagedFlux<>(() -> monoError(logger, ex));
return monoError(logger, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;

/**
Expand Down Expand Up @@ -59,8 +59,8 @@ public SmsSendResult send(String from, String to, String message, SmsSendOptions
* @return response for a successful send Sms request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PagedIterable<SmsSendResult> send(String from, Iterable<String> to, String message) {
return new PagedIterable<>(smsAsyncClient.send(from, to, message));
public Iterable<SmsSendResult> send(String from, Iterable<String> to, String message) {
return smsAsyncClient.send(from, to, message).block();
}

/**
Expand All @@ -75,7 +75,7 @@ public PagedIterable<SmsSendResult> send(String from, Iterable<String> to, Strin
* @return response for a successful send Sms request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PagedIterable<SmsSendResult> send(String from, Iterable<String> to, String message, SmsSendOptions options, Context context) {
return new PagedIterable<>(smsAsyncClient.send(from, to, message, options, context));
public Response<Iterable<SmsSendResult>> sendWithResponse(String from, Iterable<String> to, String message, SmsSendOptions options, Context context) {
return smsAsyncClient.sendWithResponse(from, to, message, options, context).block();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.identity.DefaultAzureCredentialBuilder;

Expand Down Expand Up @@ -117,12 +117,12 @@ public void sendMessageToGroupWithOptions() {
options.setDeliveryReportEnabled(true);
options.setTag("Marketing");

Iterable<SmsSendResult> sendResults = smsClient.send(
Iterable<SmsSendResult> sendResults = smsClient.sendWithResponse(
"<from-phone-number>",
Arrays.asList("<to-phone-number1>", "<to-phone-number2>"),
"Weekly Promotion",
options /* Optional */,
Context.NONE);
Context.NONE).getValue();

for (SmsSendResult result : sendResults) {
System.out.println("Message Id: " + result.getMessageId());
Expand Down Expand Up @@ -155,13 +155,14 @@ public void sendMessageTroubleShooting() {
options.setDeliveryReportEnabled(true);
options.setTag("Marketing");

PagedIterable<SmsSendResult> smsSendResults = smsClient.send(
Response<Iterable<SmsSendResult>> sendResults = smsClient.sendWithResponse(
"<from-phone-number>",
Arrays.asList("<to-phone-number1>", "<to-phone-number2>"),
"Weekly Promotion",
options /* Optional */,
Context.NONE);

Iterable<SmsSendResult> smsSendResults = sendResults.getValue();
for (SmsSendResult result : smsSendResults) {
if (result.isSuccessful()) {
System.out.println("Successfully sent this message: " + result.getMessageId() + " to " + result.getTo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import com.azure.communication.sms.models.SmsSendResult;
import com.azure.core.credential.TokenCredential;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.identity.DefaultAzureCredentialBuilder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import com.azure.core.http.HttpClient;
import com.azure.core.http.rest.Response;

import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
Expand Down Expand Up @@ -62,9 +61,11 @@ public void sendSmsToGroup(HttpClient httpClient) {
asyncClient = setupAsyncClient(builder, "sendSmsToGroup");

// Action & Assert
StepVerifier.create(asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE).next())
.assertNext(result -> {
assertHappyPath(result);
StepVerifier.create(asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE))
.assertNext((Iterable<SmsSendResult> sendResults) -> {
for (SmsSendResult result : sendResults) {
assertHappyPath(result);
}
})
.verifyComplete();
}
Expand All @@ -80,11 +81,13 @@ public void sendSmsToGroupWithOptions(HttpClient httpClient) {
options.setTag("New Tag");

// Action & Assert
PagedFlux<SmsSendResult> response = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE);
PagedIterable<SmsSendResult> sendResults = new PagedIterable<>(response);
for (SmsSendResult result : sendResults) {
assertHappyPath(result);
}
StepVerifier.create(asyncClient.sendWithResponse(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE, options))
.assertNext((Response<Iterable<SmsSendResult>> response) -> {
for (SmsSendResult result : response.getValue()) {
assertHappyPath(result);
}
})
.verifyComplete();
}

@ParameterizedTest
Expand All @@ -95,11 +98,12 @@ public void sendSmsToSingleNumber(HttpClient httpClient) {
asyncClient = setupAsyncClient(builder, "sendSmsToSingleNumber");

// Action & Assert
PagedFlux<SmsSendResult> response = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE);
PagedIterable<SmsSendResult> sendResults = new PagedIterable<>(response);
for (SmsSendResult result : sendResults) {
assertHappyPath(result);
}
Mono<SmsSendResult> response = asyncClient.send(FROM_PHONE_NUMBER, TO_PHONE_NUMBER, MESSAGE);
StepVerifier.create(response)
.assertNext(sendResult -> {
assertHappyPath(sendResult);
})
.verifyComplete();
}

@ParameterizedTest
Expand Down Expand Up @@ -153,17 +157,17 @@ public void sendToFakePhoneNumber(HttpClient httpClient) {
// Arrange
SmsClientBuilder builder = getSmsClientUsingConnectionString(httpClient);
asyncClient = setupAsyncClient(builder, "sendToFakePhoneNumber");
PagedFlux<SmsSendResult> smsSendResults = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList("+15550000000"), MESSAGE);
Mono<Iterable<SmsSendResult>> response = asyncClient.send(FROM_PHONE_NUMBER, Arrays.asList("+15550000000"), MESSAGE);

// Action & Assert
StepVerifier.create(smsSendResults)
StepVerifier.create(response)
.assertNext(item -> {
assertNotNull(item);
})
.verifyComplete();

Iterable<SmsSendResult> smsSendResultList = smsSendResults.collectList().block();
for (SmsSendResult result : smsSendResultList) {
Iterable<SmsSendResult> smsSendResults = response.block();
for (SmsSendResult result : smsSendResults) {
assertFalse(result.isSuccessful());
assertEquals(result.getHttpStatusCode(), 400);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.exception.HttpResponseException;
import com.azure.core.http.HttpClient;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.identity.DefaultAzureCredentialBuilder;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -71,8 +71,8 @@ public void sendSmsToGroupWithOptions(HttpClient httpClient) {
options.setDeliveryReportEnabled(true);
options.setTag("New Tag");
// Action & Assert
PagedIterable<SmsSendResult> sendResults = client.send(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE, options, Context.NONE);
for (SmsSendResult result : sendResults) {
Response<Iterable<SmsSendResult>> sendResults = client.sendWithResponse(FROM_PHONE_NUMBER, Arrays.asList(TO_PHONE_NUMBER, TO_PHONE_NUMBER), MESSAGE, options, Context.NONE);
for (SmsSendResult result : sendResults.getValue()) {
assertHappyPath(result);
}
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/communication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-chat</artifactId>
<version>1.0.0-beta.7</version> <!-- {x-version-update;com.azure:azure-communication-chat;current} -->
<version>1.0.0</version> <!-- {x-version-update;com.azure:azure-communication-chat;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-common</artifactId>
<version>1.0.0-beta.7</version> <!-- {x-version-update;com.azure:azure-communication-common;current} -->
<version>1.0.0</version> <!-- {x-version-update;com.azure:azure-communication-common;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-identity</artifactId>
<version>1.0.0-beta.7</version> <!-- {x-version-update;com.azure:azure-communication-identity;current} -->
<version>1.0.0</version> <!-- {x-version-update;com.azure:azure-communication-identity;current} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
Expand All @@ -44,7 +44,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-communication-sms</artifactId>
<version>1.0.0-beta.5</version> <!-- {x-version-update;com.azure:azure-communication-sms;current} -->
<version>1.0.0</version> <!-- {x-version-update;com.azure:azure-communication-sms;current} -->
</dependency>
</dependencies>

Expand Down

0 comments on commit 221def1

Please sign in to comment.