Skip to content

Commit 0f847c8

Browse files
Sofiar/cherrypicker (#45095)
* Generate new models for api-version 2025-04-01 * Create public facing methods fro cherry picker * Add cherry picker tests * Add DNR tests * Add missing params on doc comments * Add DNR tests for traditional search * Fix linting problems * Fix linting issues * Rename ReservationStatus to PhoneNUmberReservationStatus * Add custom PhoneNumbersReservation * Format clients * Fix warnings * Fix spacing on doc, and naming * Fix naming * Update recordings * Add countryCode to PhoneNumbersBrowseRequest * Split createOrUpdate reservation into two methods * Reuse PhoneNumberCost * Join create and update * Update tests to use new createOrUpdate reservation method * Update tests to use new createOrUpdate reservation method * Remove all unused imports * Add missing params on doc comments * Update readme to add remove-empty-child-schemas flag * Make browse return an AvailablePhoneNumber list * Remove browseresult model * Make browseresult model internal * Replace browseCapabilitiesRequest with regular request * Replace PhoneNumberCapabilitiesRequest to PhoneNumberCapabilities * Use createOrUpdateClientOptions * Add missing comments for CreateOrUpdateReservationOptions * Add missing comments for CreateOrUpdateReservationOptions * Remove unused models from public * Fix comments from CreateOrUpdateReservationOptions * Fix mappers * Replace UUID for string * Fix recordings * Fix linting issues * Replace Listo for PhoneNumbersBrowseResult * Add missing WithResponse methods * Add missing comment on deleteReservationWithResponse * Rename AvailablePhoneNumberStatus to PhoneNumberAvailabilityStatus * Rename BrowseRequest to BrowsePhoneNumbersOptions * Add fields as readonly * Add directive to replace PhoneNumberCapabilitiesRequest * Replace AvailablePhoneNumberError with ResponseError * Remove unused imports * Remove unused models * Make setPhoneNumbers private * Add accesshelper to PhoneNumbersReservation customization * Add required fields to constructor * Add custom PhoneNumberSearchResultError * Remove params from CreateOrUpdateReservationOptions constructor * Fix linting on AccssHelper * Make phoneNUmbers readonly on phoneNumbersBrowseResult * Exclude PhoneNumbersReservationAccessHelper * Remove unused setter on CreateOrUpdateReservationOptions * Update changelog and README * Add samples * Fix version on changelog * Remove unused imports from samples * Remove unecessary required com.azure.core * Rename params to match type * Replace UUID for string on missing function * Remove setter for country code and number type from BrowseOptions * Replace getId from UUID to String * Replace request with reservationOptions on missin method * Format createOrUpdateReservationWithResponse * Fix linting * Update sdk/communication/azure-communication-phonenumbers/README.md Co-authored-by: Daniel Ortega <[email protected]> * Solve PR comments for refactoring createOrUpdateReservation --------- Co-authored-by: Daniel Ortega <[email protected]>
1 parent 41f647d commit 0f847c8

40 files changed

+5019
-208
lines changed

sdk/communication/azure-communication-phonenumbers/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
### Features Added
66

7+
- Adds support for the Browse Available Phone Numbers and Reservations APIs
8+
- This adds an alternate way to search and purchase phone numbers that allows customers to select which phone numbers they want to reserve and purchase.
9+
- Adds support for automated purchases of phone numbers from countries requiring a Do Not Resell agreement.
10+
- For more information, refer to: https://learn.microsoft.com/azure/communication-services/concepts/numbers/sub-eligibility-number-capability
11+
- API version `2025-04-01` is the default.
12+
713
### Breaking Changes
814

915
### Bugs Fixed

sdk/communication/azure-communication-phonenumbers/README.md

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ Purchased phone numbers can come with many capabilities, depending on the countr
66

77
[Source code][source] | [Package (Maven)][package] | [API reference documentation][api_documentation]
88
| [Product documentation][product_docs]
9+
910
## Getting started
1011

1112
### Prerequisites
1213

13-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
14-
- [Java Development Kit (JDK)](https://learn.microsoft.com/java/azure/jdk/?view=azure-java-stable) version 8 or above.
15-
- [Apache Maven](https://maven.apache.org/download.cgi).
16-
- A deployed Communication Services resource. You can use the [Azure Portal](https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp) or the [Azure PowerShell](https://learn.microsoft.com/powershell/module/az.communication/new-azcommunicationservice) to set it up.
14+
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
15+
- [Java Development Kit (JDK)](https://learn.microsoft.com/java/azure/jdk/?view=azure-java-stable) version 8 or above.
16+
- [Apache Maven](https://maven.apache.org/download.cgi).
17+
- A deployed Communication Services resource. You can use the [Azure Portal](https://learn.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp) or the [Azure PowerShell](https://learn.microsoft.com/powershell/module/az.communication/new-azcommunicationservice) to set it up.
1718

1819
### Include the package
20+
1921
#### Include the BOM file
2022

2123
Please include the azure-sdk-bom to your project to take dependency on the General Availability (GA) version of the library. In the following snippet, replace the {bom_version_to_target} placeholder with the version number.
@@ -34,6 +36,7 @@ To learn more about the BOM, see the [AZURE SDK BOM README](https://github.com/A
3436
</dependencies>
3537
</dependencyManagement>
3638
```
39+
3740
and then include the direct dependency in the dependencies section without the version tag.
3841

3942
```xml
@@ -46,11 +49,12 @@ and then include the direct dependency in the dependencies section without the v
4649
```
4750

4851
#### Include direct dependency
52+
4953
If you want to take dependency on a particular version of the library that is not present in the BOM,
5054
add the direct dependency to your project as follows.
5155

56+
[//]: # "{x-version-update-start;com.azure:azure-communication-phonenumbers;current}"
5257

53-
[//]: # ({x-version-update-start;com.azure:azure-communication-phonenumbers;current})
5458
```xml
5559
<dependency>
5660
<groupId>com.azure</groupId>
@@ -70,6 +74,7 @@ The `direct routing` feature enables connecting your existing telephony infrastr
7074
The configuration is managed using the `SipRoutingClient`, which provides methods for setting up SIP trunks and voice routing rules, in order to properly handle calls for your telephony subnet.
7175

7276
### Initializing Client
77+
7378
Clients can be initialized using the Azure Active Directory Authentication.
7479

7580
```java readme-sample-createPhoneNumberClientWithAAD
@@ -131,6 +136,7 @@ SipRoutingClient sipRoutingClient = new SipRoutingClientBuilder()
131136
.httpClient(httpClient)
132137
.buildClient();
133138
```
139+
134140
Alternatively, you can provide the entire connection string using the connectionString() function of the client instead of providing the endpoint and access key.
135141

136142
### Phone numbers client
@@ -145,6 +151,14 @@ Phone numbers can be searched through the search creation API by providing an ar
145151

146152
Phone numbers can also be released using the release API.
147153

154+
#### Browsing and reserving phone numbers
155+
156+
The Browse and Reservations APIs provide an alternate way to acquire phone numbers via a shopping-cart-like experience. This is achieved by splitting the search operation, which finds and reserves numbers using a single LRO, into two separate synchronous steps, Browse and Reservation.
157+
158+
The browse operation retrieves a random sample of phone numbers that are available for purchase for a given country, with optional filtering criteria to narrow down results. The returned phone numbers are not reserved for any customer.
159+
160+
Reservations represent a collection of phone numbers that are locked by a specific customer and are awaiting purchase. They have an expiration time of 15 minutes after the last modification or 2 hours from creation time. A reservation can include numbers from different countries, in contrast with the Search operation. Customers can Create, Retrieve, Modify (by adding and removing numbers), Delete, and Purchase reservations. Purchasing a reservation is an LRO.
161+
148162
### SIP routing client
149163

150164
Direct routing feature allows connecting customer-provided telephony infrastructure to Azure Communication Resources. In order to setup routing configuration properly, customer needs to supply the SIP trunk configuration and SIP routing rules for calls. SIP routing client provides the necessary interface for setting this configuration.
@@ -157,6 +171,7 @@ Once a route is matched, the call is routed to the first trunk in the route's tr
157171
### PhoneNumbersClient
158172

159173
#### Get Purchased Phone Number
174+
160175
Gets the specified purchased phone number.
161176

162177
```java readme-sample-getPurchasedPhoneNumber
@@ -166,6 +181,7 @@ System.out.println("Phone Number Country Code: " + phoneNumber.getCountryCode())
166181
```
167182

168183
#### Get All Purchased Phone Numbers
184+
169185
Lists all the purchased phone numbers.
170186

171187
```java readme-sample-listPhoneNumbers
@@ -175,11 +191,36 @@ System.out.println("Phone Number Value: " + phoneNumber.getPhoneNumber());
175191
System.out.println("Phone Number Country Code: " + phoneNumber.getCountryCode());
176192
```
177193

194+
### Browse and reserve available phone numbers
195+
196+
Use the Browse and Reservations API to reserve a phone number
197+
198+
```java readme-sample-browseAndReservePhoneNumbers
199+
PhoneNumbersClient phoneNumberClient = createPhoneNumberClient();
200+
String reservationId = UUID.randomUUID().toString();
201+
202+
BrowsePhoneNumbersOptions browseRequest = new BrowsePhoneNumbersOptions("US", PhoneNumberType.TOLL_FREE)
203+
.setAssignmentType(PhoneNumberAssignmentType.APPLICATION)
204+
.setCapabilities(new PhoneNumberCapabilities().setCalling(PhoneNumberCapabilityType.INBOUND_OUTBOUND)
205+
.setSms(PhoneNumberCapabilityType.INBOUND_OUTBOUND));
206+
207+
PhoneNumbersBrowseResult result = phoneNumberClient.browseAvailableNumbers(browseRequest);
208+
209+
List<AvailablePhoneNumber> numbersToAdd = new ArrayList<>();
210+
211+
numbersToAdd.add(result.getPhoneNumbers().get(0));
212+
213+
PhoneNumbersReservation reservationResponse = phoneNumberClient.createOrUpdateReservation(
214+
new CreateOrUpdateReservationOptions(reservationId).setPhoneNumbersToAdd(numbersToAdd));
215+
System.out.println("Reservation ID: " + reservationResponse.getId());
216+
```
217+
178218
### Long Running Operations
179219

180220
The Phone Number Client supports a variety of long-running operations that allow indefinite polling time to the functions listed down below.
181221

182222
#### Search for Available Phone Numbers
223+
183224
Search for available phone numbers by providing the area code, assignment type, phone number capabilities, phone number type, and quantity. The result of the search can then be used to purchase the numbers. Note that for the toll-free phone number type, providing the area code is optional.
184225

185226
```java readme-sample-searchAvailablePhoneNumbers
@@ -204,6 +245,7 @@ if (LongRunningOperationStatus.SUCCESSFULLY_COMPLETED == response.getStatus()) {
204245
```
205246

206247
#### Purchase Phone Numbers
248+
207249
The result of searching for phone numbers is a `PhoneNumberSearchResult`. This can be used to get the numbers' details and purchase numbers by passing in the `searchId` to the purchase number API.
208250

209251
```java readme-sample-purchasePhoneNumbers
@@ -212,7 +254,18 @@ PollResponse<PhoneNumberOperation> purchaseResponse =
212254
System.out.println("Purchase phone numbers is complete: " + purchaseResponse.getStatus());
213255
```
214256

257+
#### Purchase Phone Number Reservation
258+
259+
Begin the purchas of a reservation
260+
261+
```java readme-sample-purchaseReservation
262+
PollResponse<PhoneNumberOperation> purchaseResponse =
263+
phoneNumberClient.beginReservationPurchase(reservationId, Context.NONE).waitForCompletion();
264+
System.out.println("Purchase reservation is complete: " + purchaseResponse.getStatus());
265+
```
266+
215267
#### Release Phone Number
268+
216269
Releases a purchased phone number.
217270

218271
```java readme-sample-releasePhoneNumber
@@ -222,11 +275,13 @@ System.out.println("Release phone number is complete: " + releaseResponse.getSta
222275
```
223276

224277
#### Updating Phone Number Capabilities
278+
225279
Updates Phone Number Capabilities for Calling and SMS to one of:
226-
- `PhoneNumberCapabilityValue.NONE`
227-
- `PhoneNumberCapabilityValue.INBOUND`
228-
- `PhoneNumberCapabilityValue.OUTBOUND`
229-
- `PhoneNumberCapabilityValue.INBOUND_OUTBOUND`
280+
281+
- `PhoneNumberCapabilityValue.NONE`
282+
- `PhoneNumberCapabilityValue.INBOUND`
283+
- `PhoneNumberCapabilityValue.OUTBOUND`
284+
- `PhoneNumberCapabilityValue.INBOUND_OUTBOUND`
230285

231286
```java readme-sample-updatePhoneNumberCapabilities
232287
PhoneNumberCapabilities capabilities = new PhoneNumberCapabilities();
@@ -311,7 +366,6 @@ When you submit a pull request, a CLA-bot will automatically determine whether y
311366

312367
This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For more information see the [Code of Conduct FAQ][coc_faq] or contact [[email protected]][coc_contact] with any additional questions or comments.
313368

314-
315369
## Troubleshooting
316370

317371
In progress.
@@ -321,6 +375,7 @@ In progress.
321375
Check out other client libraries for Azure communication service
322376

323377
<!-- LINKS -->
378+
324379
[cla]: https://cla.microsoft.com
325380
[coc]: https://opensource.microsoft.com/codeofconduct/
326381
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
@@ -329,7 +384,3 @@ Check out other client libraries for Azure communication service
329384
[package]: https://central.sonatype.com/artifact/com.azure/azure-communication-phonenumbers
330385
[api_documentation]: https://aka.ms/java-docs
331386
[source]: https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/communication/azure-communication-phonenumbers/src
332-
333-
334-
335-

sdk/communication/azure-communication-phonenumbers/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "java",
44
"TagPrefix": "java/communication/azure-communication-phonenumbers",
5-
"Tag": "java/communication/azure-communication-phonenumbers_2dd73df054"
5+
"Tag": "java/communication/azure-communication-phonenumbers_ac7d2e0f8b"
66
}

sdk/communication/azure-communication-phonenumbers/spotbugs-exclude.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@
3737
<Class name="com.azure.communication.phonenumbers.siprouting.models.SipTrunkRoute" />
3838
</Or>
3939
</Match>
40+
<Match>
41+
<Bug pattern="EI_EXPOSE_STATIC_REP2" />
42+
<Or>
43+
<Class name="com.azure.communication.phonenumbers.implementation.accesshelpers.PhoneNumbersReservationAccessHelper" />
44+
</Or>
45+
</Match>
4046
</FindBugsFilter>

0 commit comments

Comments
 (0)