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 - Added releasePhoneNumber Long Running Operation #16116

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.azure.communication.administration.models.UpdateNumberCapabilitiesResponse;
import com.azure.communication.administration.models.NumberConfiguration;
import com.azure.communication.administration.models.PhoneNumberSearch;
import com.azure.communication.administration.models.ReleaseStatus;
import com.azure.communication.administration.models.SearchStatus;
import com.azure.communication.administration.models.UpdateNumberCapabilitiesRequest;
import com.azure.communication.administration.models.UpdatePhoneNumberCapabilitiesResponse;
Expand Down Expand Up @@ -834,4 +835,65 @@ Mono<PhoneNumberSearch>> createSearchFetchResultOperation() {
return Mono.just(pollingContext.getLatestResponse().getValue());
};
}
/**
* Creates a release for the given phone numbers.
* This function returns a Long Running Operation poller that allows you to
* wait indefinitely until the operation is complete.
*
* @param phoneNumbers A list of {@link PhoneNumber} with the desired numbers to release
* @param pollInterval The time our long running operation will keep on polling
* until it gets a result from the server
* @return A {@link PollerFlux} object with the release entity
*/
public PollerFlux<PhoneNumberRelease, PhoneNumberRelease>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs the service method declaration.

beginReleasePhoneNumbers(List<PhoneNumber> phoneNumbers, Duration pollInterval) {
Objects.requireNonNull(phoneNumbers, "'phoneNumbers' cannot be null.");
Objects.requireNonNull(pollInterval, "'pollInterval' cannot be null.");
return new PollerFlux<PhoneNumberRelease, PhoneNumberRelease>(pollInterval,
releaseNumbersActivationOperation(phoneNumbers),
releaseNumbersPollOperation(),
(activationResponse, pollingContext) ->
monoError(logger, new RuntimeException("Cancellation is not supported")),
releaseNumbersFetchResultOperation());
}

private Function<PollingContext<PhoneNumberRelease>, Mono<PhoneNumberRelease>>
releaseNumbersActivationOperation(List<PhoneNumber> phoneNumbers) {
return (pollingContext) -> {
Mono<PhoneNumberRelease> response = releasePhoneNumbers(phoneNumbers)
.flatMap(releaseNumberResponse -> {
String releaseId = releaseNumberResponse.getReleaseId();
Mono<PhoneNumberRelease> phoneNumberRelease = getReleaseById(releaseId);
return phoneNumberRelease;
});
return response;
};
}

private Function<PollingContext<PhoneNumberRelease>,
Mono<PollResponse<PhoneNumberRelease>>>
releaseNumbersPollOperation() {
return pollingContext ->
getReleaseById(pollingContext.getLatestResponse().getValue().getReleaseId())
.flatMap(getReleaseResponse -> {
ReleaseStatus status = getReleaseResponse.getStatus();
if (status.equals(ReleaseStatus.COMPLETE)
|| status.equals(ReleaseStatus.EXPIRED)) {
return Mono.just(new PollResponse<>(
LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, getReleaseResponse));
}
if (status.equals(ReleaseStatus.FAILED)) {
return Mono.just(new PollResponse<>(
LongRunningOperationStatus.FAILED, getReleaseResponse));
}
return Mono.just(new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS, getReleaseResponse));
});
}

private Function<PollingContext<PhoneNumberRelease>,
Mono<PhoneNumberRelease>> releaseNumbersFetchResultOperation() {
return pollingContext -> {
return Mono.just(pollingContext.getLatestResponse().getValue());
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,19 @@ public SyncPoller<PhoneNumberSearch, PhoneNumberSearch> beginCreateSearch(
CreateSearchOptions options, Duration pollInterval) {
return phoneNumberAsyncClient.beginCreateSearch(options, pollInterval).getSyncPoller();
}

/**
* Creates a release for the given phone numbers.
* This function returns a Long Running Operation poller.
*
* @param phoneNumbers A list of {@link PhoneNumber} with the desired numbers to release
* @param pollInterval The time our long running operation will keep on polling
* until it gets a result from the server
* @return A {@link SyncPoller} object with the release entity
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type is a poller, shouldn't it be single.. I am not sure why it should be a COLLECTION

public SyncPoller<PhoneNumberRelease, PhoneNumberRelease> beginReleasePhoneNumbers(
List<PhoneNumber> phoneNumbers, Duration pollInterval) {
return phoneNumberAsyncClient.beginReleasePhoneNumbers(phoneNumbers, pollInterval).getSyncPoller();
}
}