Skip to content

Commit 005a6b8

Browse files
authored
Jiriburant/fixing ga release comments (Azure#34063)
* Fixed return types for listTrunks and listRoutes. Moved SIP routing client to siprouting subpackage. Updated Changelog. * Changing SipException type to generic HttpResponseException. * Removed iterator. * Adding forgotten Assert. * Fixing lint issues.
1 parent fbd4581 commit 005a6b8

File tree

18 files changed

+342
-733
lines changed

18 files changed

+342
-733
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
- Added environment variable `AZURE_TEST_DOMAIN` for SIP routing tests to support domain verification.
88

99
### Other Changes
10+
- Changed listTrunks and listRoutes methods to return PagedIterable for sync client and PagedFlux for async client.
11+
- Moved SIP routing clients to com.azure.communication.phonenumbers.siprouting subpackage.
1012
- Added `PhoneNumberAreaCode` public model.
1113
- Removed `PhoneNumberOfferings`, `PhoneNumberLocalities` and `PhoneNumberCountries` from the models package. Since no public method exposed them, this is not a breaking change.
1214

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ if (LongRunningOperationStatus.SUCCESSFULLY_COMPLETED == response.getStatus()) {
251251
Get the list of currently configured trunks or routes.
252252

253253
```java readme-sample-listTrunksAndRoutes
254-
List<SipTrunk> trunks = sipRoutingClient.listTrunks();
255-
List<SipTrunkRoute> routes = sipRoutingClient.listRoutes();
254+
PagedIterable<SipTrunk> trunks = sipRoutingClient.listTrunks();
255+
PagedIterable<SipTrunkRoute> routes = sipRoutingClient.listRoutes();
256256
for (SipTrunk trunk : trunks) {
257257
System.out.println("Trunk " + trunk.getFqdn() + ":" + trunk.getSipSignalingPort());
258258
}
Lines changed: 45 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
package com.azure.communication.phonenumbers;
4+
package com.azure.communication.phonenumbers.siprouting;
55

66
import com.azure.communication.phonenumbers.siprouting.implementation.SipRoutingAdminClientImpl;
7-
import com.azure.communication.phonenumbers.siprouting.implementation.converters.SipRoutingErrorConverter;
87
import com.azure.communication.phonenumbers.siprouting.implementation.models.CommunicationErrorResponseException;
98
import com.azure.communication.phonenumbers.siprouting.implementation.models.SipConfiguration;
10-
import com.azure.communication.phonenumbers.siprouting.models.SipRoutingError;
11-
import com.azure.communication.phonenumbers.siprouting.models.SipRoutingResponseException;
129
import com.azure.communication.phonenumbers.siprouting.models.SipTrunk;
1310
import com.azure.communication.phonenumbers.siprouting.models.SipTrunkRoute;
1411
import com.azure.core.annotation.ReturnType;
1512
import com.azure.core.annotation.ServiceClient;
1613
import com.azure.core.annotation.ServiceMethod;
14+
import com.azure.core.exception.HttpResponseException;
15+
import com.azure.core.http.rest.PagedFlux;
16+
import com.azure.core.http.rest.PagedResponse;
17+
import com.azure.core.http.rest.PagedResponseBase;
1718
import com.azure.core.http.rest.Response;
1819
import com.azure.core.http.rest.SimpleResponse;
1920
import reactor.core.publisher.Mono;
@@ -112,38 +113,28 @@ public Mono<Response<SipTrunk>> getTrunkWithResponse(String fqdn) {
112113
* <!-- src_embed com.azure.communication.phonenumbers.siprouting.asyncclient.listTrunks -->
113114
* <pre>
114115
* sipRoutingAsyncClient.listTrunks&#40;&#41;
115-
* .subscribe&#40;trunks -&gt; trunks.forEach&#40;trunk -&gt;
116-
* System.out.println&#40;&quot;Trunk &quot; + trunk.getFqdn&#40;&#41; + &quot;:&quot; + trunk.getSipSignalingPort&#40;&#41;&#41;&#41;&#41;;
116+
* .subscribe&#40;trunk -&gt;
117+
* System.out.println&#40;&quot;Trunk &quot; + trunk.getFqdn&#40;&#41; + &quot;:&quot; + trunk.getSipSignalingPort&#40;&#41;&#41;&#41;;
117118
* </pre>
118119
* <!-- end com.azure.communication.phonenumbers.siprouting.asyncclient.listTrunks -->
119120
*
120121
* @return SIP Trunks.
121122
*/
122-
@ServiceMethod(returns = ReturnType.SINGLE)
123-
public Mono<List<SipTrunk>> listTrunks() {
124-
return getSipConfiguration().map(config -> convertFromApi(config.getTrunks()));
123+
@ServiceMethod(returns = ReturnType.COLLECTION)
124+
public PagedFlux<SipTrunk> listTrunks() {
125+
return new PagedFlux<SipTrunk>(() -> getOnePageTrunks());
125126
}
126127

127-
/**
128-
* Lists SIP Trunks.
129-
*
130-
* <p><strong>Code Samples</strong></p>
131-
*
132-
* <!-- src_embed com.azure.communication.phonenumbers.siprouting.asyncclient.listTrunksWithResponse -->
133-
* <pre>
134-
* sipRoutingAsyncClient.listTrunksWithResponse&#40;&#41;
135-
* .subscribe&#40;response -&gt; response.getValue&#40;&#41;.forEach&#40;trunk -&gt;
136-
* System.out.println&#40;&quot;Trunk &quot; + trunk.getFqdn&#40;&#41; + &quot;:&quot; + trunk.getSipSignalingPort&#40;&#41;&#41;&#41;&#41;;
137-
* </pre>
138-
* <!-- end com.azure.communication.phonenumbers.siprouting.asyncclient.listTrunksWithResponse -->
139-
*
140-
* @return Response object with the SIP Trunks.
141-
*/
142-
@ServiceMethod(returns = ReturnType.SINGLE)
143-
public Mono<Response<List<SipTrunk>>> listTrunksWithResponse() {
144-
return getSipConfigurationWithResponse()
145-
.onErrorMap(CommunicationErrorResponseException.class, this::translateException)
146-
.map(result -> new SimpleResponse<>(result, convertFromApi(result.getValue().getTrunks())));
128+
private Mono<PagedResponse<SipTrunk>> getOnePageTrunks() {
129+
return client.getSipRoutings().getWithResponseAsync()
130+
.onErrorMap(CommunicationErrorResponseException.class, this::translateException)
131+
.map(result -> new PagedResponseBase<>(
132+
result.getRequest(),
133+
result.getStatusCode(),
134+
result.getHeaders(),
135+
convertFromApi(result.getValue().getTrunks()),
136+
null,
137+
null));
147138
}
148139

149140
/**
@@ -153,47 +144,32 @@ public Mono<Response<List<SipTrunk>>> listTrunksWithResponse() {
153144
*
154145
* <!-- src_embed com.azure.communication.phonenumbers.siprouting.asyncclient.listRoutes -->
155146
* <pre>
156-
* sipRoutingAsyncClient.listRoutes&#40;&#41;.subscribe&#40;routes -&gt; routes.forEach&#40;route -&gt; &#123;
147+
* sipRoutingAsyncClient.listRoutes&#40;&#41;.subscribe&#40;route -&gt; &#123;
157148
* System.out.println&#40;&quot;Route name: &quot; + route.getName&#40;&#41;&#41;;
158149
* System.out.println&#40;&quot;Route description: &quot; + route.getDescription&#40;&#41;&#41;;
159150
* System.out.println&#40;&quot;Route number pattern: &quot; + route.getNumberPattern&#40;&#41;&#41;;
160151
* System.out.println&#40;&quot;Route trunks: &quot; + String.join&#40;&quot;,&quot;, route.getTrunks&#40;&#41;&#41;&#41;;
161-
* &#125;&#41;&#41;;
152+
* &#125;&#41;;
162153
* </pre>
163154
* <!-- end com.azure.communication.phonenumbers.siprouting.asyncclient.listRoutes -->
164155
*
165156
* @return SIP Trunk Routes.
166157
*/
167-
@ServiceMethod(returns = ReturnType.SINGLE)
168-
public Mono<List<SipTrunkRoute>> listRoutes() {
169-
return getSipConfiguration().map(sipConfiguration -> convertFromApi(sipConfiguration.getRoutes()));
158+
@ServiceMethod(returns = ReturnType.COLLECTION)
159+
public PagedFlux<SipTrunkRoute> listRoutes() {
160+
return new PagedFlux<SipTrunkRoute>(() -> getOnePageRoutes());
170161
}
171162

172-
/**
173-
* Lists SIP Trunk Routes.
174-
*
175-
* <p><strong>Code Samples</strong></p>
176-
*
177-
* <!-- src_embed com.azure.communication.phonenumbers.siprouting.asyncclient.listRoutesWithResponse -->
178-
* <pre>
179-
* sipRoutingAsyncClient.listRoutesWithResponse&#40;&#41;
180-
* .subscribe&#40;response -&gt; response.getValue&#40;&#41;.forEach&#40;route -&gt; &#123;
181-
* System.out.println&#40;&quot;Route name: &quot; + route.getName&#40;&#41;&#41;;
182-
* System.out.println&#40;&quot;Route description: &quot; + route.getDescription&#40;&#41;&#41;;
183-
* System.out.println&#40;&quot;Route number pattern: &quot; + route.getNumberPattern&#40;&#41;&#41;;
184-
* System.out.println&#40;&quot;Route trunks: &quot; + String.join&#40;&quot;,&quot;, route.getTrunks&#40;&#41;&#41;&#41;;
185-
* &#125;&#41;&#41;;
186-
* </pre>
187-
* <!-- end com.azure.communication.phonenumbers.siprouting.asyncclient.listRoutesWithResponse -->
188-
*
189-
*
190-
* @return Response object with the SIP Trunk Routes.
191-
*/
192-
@ServiceMethod(returns = ReturnType.SINGLE)
193-
public Mono<Response<List<SipTrunkRoute>>> listRoutesWithResponse() {
194-
return getSipConfigurationWithResponse()
195-
.onErrorMap(CommunicationErrorResponseException.class, this::translateException)
196-
.map(result -> new SimpleResponse<>(result, convertFromApi(result.getValue().getRoutes())));
163+
private Mono<PagedResponse<SipTrunkRoute>> getOnePageRoutes() {
164+
return client.getSipRoutings().getWithResponseAsync()
165+
.onErrorMap(CommunicationErrorResponseException.class, this::translateException)
166+
.map(result -> new PagedResponseBase<>(
167+
result.getRequest(),
168+
result.getStatusCode(),
169+
result.getHeaders(),
170+
convertFromApi(result.getValue().getRoutes()),
171+
null,
172+
null));
197173
}
198174

199175
/**
@@ -238,7 +214,7 @@ public Mono<Void> setTrunk(SipTrunk trunk) {
238214
@ServiceMethod(returns = ReturnType.SINGLE)
239215
public Mono<Void> setTrunks(List<SipTrunk> trunks) {
240216
SipConfiguration update = new SipConfiguration().setTrunks(convertToApi(trunks));
241-
List<SipTrunk> currentTrunks = listTrunks().block();
217+
List<SipTrunk> currentTrunks = getTrunksInternal().block();
242218
if (currentTrunks != null) {
243219
List<String> storedFqdns = currentTrunks.stream().map(SipTrunk::getFqdn).collect(Collectors.toList());
244220
Set<String> updatedFqdns = trunks.stream().map(SipTrunk::getFqdn).collect(Collectors.toSet());
@@ -278,7 +254,7 @@ public Mono<Void> setTrunks(List<SipTrunk> trunks) {
278254
@ServiceMethod(returns = ReturnType.SINGLE)
279255
public Mono<Response<Void>> setTrunksWithResponse(List<SipTrunk> trunks) {
280256
SipConfiguration update = new SipConfiguration().setTrunks(convertToApi(trunks));
281-
List<SipTrunk> currentTrunks = listTrunks().block();
257+
List<SipTrunk> currentTrunks = getTrunksInternal().block();
282258
if (currentTrunks != null) {
283259
List<String> storedFqdns = currentTrunks.stream().map(SipTrunk::getFqdn).collect(Collectors.toList());
284260
Set<String> updatedFqdns = trunks.stream().map(SipTrunk::getFqdn).collect(Collectors.toSet());
@@ -360,7 +336,7 @@ public Mono<Response<Void>> setRoutesWithResponse(List<SipTrunkRoute> routes) {
360336
*/
361337
@ServiceMethod(returns = ReturnType.SINGLE)
362338
public Mono<Void> deleteTrunk(String fqdn) {
363-
List<SipTrunk> trunks = listTrunks().block();
339+
List<SipTrunk> trunks = getTrunksInternal().block();
364340
if (trunks == null || trunks.isEmpty()) {
365341
return Mono.empty();
366342
}
@@ -395,7 +371,7 @@ public Mono<Void> deleteTrunk(String fqdn) {
395371
*/
396372
@ServiceMethod(returns = ReturnType.SINGLE)
397373
public Mono<Response<Void>> deleteTrunkWithResponse(String fqdn) {
398-
List<SipTrunk> trunks = listTrunks().block();
374+
List<SipTrunk> trunks = getTrunksInternal().block();
399375
if (trunks == null || trunks.isEmpty()) {
400376
return Mono.just(new SimpleResponse<>(null, 200, null, null));
401377
}
@@ -434,11 +410,11 @@ private Mono<Response<SipConfiguration>> setSipConfigurationWithResponse(SipConf
434410
.onErrorMap(CommunicationErrorResponseException.class, this::translateException);
435411
}
436412

437-
private SipRoutingResponseException translateException(CommunicationErrorResponseException exception) {
438-
SipRoutingError error = null;
439-
if (exception.getValue() != null) {
440-
error = SipRoutingErrorConverter.convert(exception.getValue().getError());
441-
}
442-
return new SipRoutingResponseException(exception.getMessage(), exception.getResponse(), error);
413+
private HttpResponseException translateException(CommunicationErrorResponseException exception) {
414+
return new HttpResponseException(exception.getMessage(), exception.getResponse());
415+
}
416+
417+
private Mono<List<SipTrunk>> getTrunksInternal() {
418+
return getSipConfiguration().map(config -> convertFromApi(config.getTrunks()));
443419
}
444420
}

0 commit comments

Comments
 (0)