Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Communication - Purchase Search Follow-up PR #16887

Merged
merged 5 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions sdk/communication/azure-communication-administration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,10 @@ for (String areaCode
}
```

### Purchase Search

<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L334-L335 -->
```java
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
phoneNumberClient.purchaseSearch(phoneNumberSearchId);
```

### Configure Phone Number

<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L346-L347 -->
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L338-L338 -->
```java
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
phoneNumberClient.configureNumber(phoneNumber, pstnConfiguration);
```

Expand All @@ -262,7 +253,7 @@ The Phone Number Client supports a variety of long running operations that allow

### Create Search

<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L354-L378 -->
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L345-L369 -->
```java
String phonePlanId = "PHONE_PLAN_ID";

Expand Down Expand Up @@ -292,7 +283,7 @@ for (String phoneNumber: result.getPhoneNumbers()) {
```

### Purchase Search
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L385-L391 -->
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L376-L382 -->
```java
Duration duration = Duration.ofSeconds(1);
String phoneNumberSearchId = "SEARCH_ID_TO_PURCHASE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
public final class PhoneNumberAsyncClient {
private final ClientLogger logger = new ClientLogger(PhoneNumberAsyncClient.class);
private final PhoneNumberAdministrationsImpl phoneNumberAdministrations;
private final Duration defaultPollInterval = Duration.ofSeconds(1);

PhoneNumberAsyncClient(PhoneNumberAdminClientImpl phoneNumberAdminClient) {
this.phoneNumberAdministrations = phoneNumberAdminClient.getPhoneNumberAdministrations();
Expand Down Expand Up @@ -735,8 +736,7 @@ Mono<Response<Void>> cancelSearchWithResponse(String searchId, Context context)
* @param searchId ID of the search
* @return A {@link Mono} for the asynchronous return
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> purchaseSearch(String searchId) {
private Mono<Void> purchaseSearch(String searchId) {
return purchaseSearchWithResponse(searchId).flatMap(FluxUtil::toMono);
}

Expand All @@ -746,12 +746,11 @@ public Mono<Void> purchaseSearch(String searchId) {
* @param searchId ID of the search
* @return A {@link Mono} containing a {@link Response} for the operation
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<Void>> purchaseSearchWithResponse(String searchId) {
private Mono<Response<Void>> purchaseSearchWithResponse(String searchId) {
return purchaseSearchWithResponse(searchId, null);
}

Mono<Response<Void>> purchaseSearchWithResponse(String searchId, Context context) {
private Mono<Response<Void>> purchaseSearchWithResponse(String searchId, Context context) {
Objects.requireNonNull(searchId, "'searchId' cannot be null.");

try {
Expand Down Expand Up @@ -779,7 +778,11 @@ Mono<Response<Void>> purchaseSearchWithResponse(String searchId, Context context
public PollerFlux<PhoneNumberSearch, PhoneNumberSearch> beginCreateSearch(
CreateSearchOptions options, Duration pollInterval) {
Objects.requireNonNull(options, "'options' cannot be null.");
Objects.requireNonNull(pollInterval, "'pollInterval' cannot be null.");

if (pollInterval == null) {
pollInterval = defaultPollInterval;
}

return new PollerFlux<PhoneNumberSearch, PhoneNumberSearch>(pollInterval,
createSearchActivationOperation(options),
createSearchPollOperation(),
Expand Down Expand Up @@ -849,7 +852,10 @@ Mono<PhoneNumberSearch>> createSearchFetchResultOperation() {
@ServiceMethod(returns = ReturnType.COLLECTION)
public PollerFlux<Void, Void> beginPurchaseSearch(String searchId, Duration pollInterval) {
Objects.requireNonNull(searchId, "'searchId' can not be null.");
Objects.requireNonNull(pollInterval, "'pollInterval' can not be null.");

if (pollInterval == null) {
pollInterval = defaultPollInterval;
}

return new PollerFlux<Void, Void>(pollInterval,
purchaseSearchActivationOperation(searchId),
Expand All @@ -858,11 +864,10 @@ public PollerFlux<Void, Void> beginPurchaseSearch(String searchId, Duration poll
purchaseSearchFetchResultOperation());
}

private Function<PollingContext<Void>, Mono<Void>> purchaseSearchActivationOperation(String searchId) {

private Function<PollingContext<Void>,
Mono<Void>> purchaseSearchActivationOperation(String searchId) {
return (pollingContext) -> {
Mono<Void> response = purchaseSearch(searchId);
return response;
return purchaseSearch(searchId);
};
}

Expand All @@ -871,13 +876,12 @@ private Function<PollingContext<Void>, Mono<Void>> purchaseSearchActivationOpera
return (pollingContext) -> getSearchById(searchId)
.flatMap(getSearchResponse -> {
SearchStatus statusResponse = getSearchResponse.getStatus();
if (statusResponse.equals(SearchStatus.RESERVED)
|| statusResponse.equals(SearchStatus.EXPIRED)
|| statusResponse.equals(SearchStatus.SUCCESS)) {
if (statusResponse.equals(SearchStatus.SUCCESS)) {
return Mono.just(new PollResponse<>(
LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, null));
}
if (statusResponse.equals(SearchStatus.ERROR)) {
if (statusResponse.equals(SearchStatus.ERROR)
|| statusResponse.equals(SearchStatus.EXPIRED)) {
return Mono.just(new PollResponse<>(
LongRunningOperationStatus.FAILED, null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,28 +503,6 @@ public Response<Void> cancelSearchWithResponse(String searchId, Context context)
return phoneNumberAsyncClient.cancelSearchWithResponse(searchId, context).block();
}

/**
* Purchases the phone number search.
*
* @param searchId ID of the search
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void purchaseSearch(String searchId) {
phoneNumberAsyncClient.purchaseSearch(searchId).block();
}

/**
* Purchases the phone number search.
*
* @param searchId ID of the search
* @param context A {@link Context} representing the request context.
* @return A {@link Response} for the operation
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Void> purchaseSearchWithResponse(String searchId, Context context) {
return phoneNumberAsyncClient.purchaseSearchWithResponse(searchId, context).block();
}

/**
* Initiates a search and returns a {@link PhoneNumberSearch} usable by other functions
* This function returns a Long Running Operation poller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,6 @@ public PhoneNumberSearch createPhoneNumberSearch() {
return phoneNumberSearch;
}

/**
* Sample code to purchase a phone number search
*/
public void purchasePhoneNumberSearch() {
String phoneNumberSearchId = "SEARCH_ID_TO_PURCHASE";
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();
phoneNumberClient.purchaseSearch(phoneNumberSearchId);
}

/**
* Sample code to configure a phone number
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,26 +346,6 @@ public void getSearchByIdWithResponse(HttpClient httpClient) {
.verifyComplete();
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void purchaseSearch(HttpClient httpClient) {
Mono<Void> mono = this.getClient(httpClient).purchaseSearch(SEARCH_ID_TO_PURCHASE);

StepVerifier.create(mono).verifyComplete();
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void purchaseSearchWithResponse(HttpClient httpClient) {
Mono<Response<Void>> mono = this.getClient(httpClient).purchaseSearchWithResponse(SEARCH_ID_TO_PURCHASE, Context.NONE);

StepVerifier.create(mono)
.assertNext(item -> {
assertEquals(202, item.getStatusCode());
})
.verifyComplete();
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void cancelSearch(HttpClient httpClient) {
Expand Down Expand Up @@ -531,15 +511,18 @@ public void beginCreateSearch(HttpClient httpClient) {
@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void beginPurchaseSearch(HttpClient httpClient) {
Duration pollInterval = Duration.ofSeconds(5);
Duration pollInterval = Duration.ofSeconds(1);
PhoneNumberAsyncClient client = this.getClient(httpClient);
PollerFlux<Void, Void> poller =
this.getClient(httpClient).beginPurchaseSearch(SEARCH_ID, pollInterval);
poller.takeUntil(apr -> apr.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED);
Mono<PhoneNumberSearch> mono = this.getClient(httpClient).getSearchById(SEARCH_ID);
StepVerifier.create(mono)
client.beginPurchaseSearch(SEARCH_ID, pollInterval);
poller.takeUntil(apr -> apr.getStatus() == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED)
.blockLast();
Mono<PhoneNumberSearch> testResult = client.getSearchById(SEARCH_ID);
StepVerifier.create(testResult)
.assertNext(item -> {
assertEquals(SearchStatus.SUCCESS, item.getStatus());
});
})
.verifyComplete();
}

private PhoneNumberAsyncClient getClient(HttpClient httpClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,6 @@ public void getSearchByIdWithResponse(HttpClient httpClient) {
assertEquals(SEARCH_ID, response.getValue().getSearchId());
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void purchaseSearch(HttpClient httpClient) {
this.getClient(httpClient).purchaseSearch(SEARCH_ID_TO_PURCHASE);
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void purchaseSearchWithResponse(HttpClient httpClient) {
Response<Void> response = this.getClient(httpClient).purchaseSearchWithResponse(SEARCH_ID_TO_PURCHASE, Context.NONE);

assertEquals(202, response.getStatusCode());
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void cancelSearch(HttpClient httpClient) {
Expand Down
Loading