1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
4
- package com .azure .communication .phonenumbers ;
4
+ package com .azure .communication .phonenumbers . siprouting ;
5
5
6
6
import com .azure .communication .phonenumbers .siprouting .implementation .SipRoutingAdminClientImpl ;
7
- import com .azure .communication .phonenumbers .siprouting .implementation .converters .SipRoutingErrorConverter ;
8
7
import com .azure .communication .phonenumbers .siprouting .implementation .models .CommunicationErrorResponseException ;
9
8
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 ;
12
9
import com .azure .communication .phonenumbers .siprouting .models .SipTrunk ;
13
10
import com .azure .communication .phonenumbers .siprouting .models .SipTrunkRoute ;
14
11
import com .azure .core .annotation .ReturnType ;
15
12
import com .azure .core .annotation .ServiceClient ;
16
13
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 ;
17
18
import com .azure .core .http .rest .Response ;
18
19
import com .azure .core .http .rest .SimpleResponse ;
19
20
import reactor .core .publisher .Mono ;
@@ -112,38 +113,28 @@ public Mono<Response<SipTrunk>> getTrunkWithResponse(String fqdn) {
112
113
* <!-- src_embed com.azure.communication.phonenumbers.siprouting.asyncclient.listTrunks -->
113
114
* <pre>
114
115
* sipRoutingAsyncClient.listTrunks()
115
- * .subscribe(trunks -> trunks.forEach( trunk ->
116
- * System.out.println("Trunk " + trunk.getFqdn() + ":" + trunk.getSipSignalingPort()))) ;
116
+ * .subscribe(trunk ->
117
+ * System.out.println("Trunk " + trunk.getFqdn() + ":" + trunk.getSipSignalingPort()));
117
118
* </pre>
118
119
* <!-- end com.azure.communication.phonenumbers.siprouting.asyncclient.listTrunks -->
119
120
*
120
121
* @return SIP Trunks.
121
122
*/
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 ( ));
125
126
}
126
127
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()
135
- * .subscribe(response -> response.getValue().forEach(trunk ->
136
- * System.out.println("Trunk " + trunk.getFqdn() + ":" + trunk.getSipSignalingPort())));
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 ));
147
138
}
148
139
149
140
/**
@@ -153,47 +144,32 @@ public Mono<Response<List<SipTrunk>>> listTrunksWithResponse() {
153
144
*
154
145
* <!-- src_embed com.azure.communication.phonenumbers.siprouting.asyncclient.listRoutes -->
155
146
* <pre>
156
- * sipRoutingAsyncClient.listRoutes().subscribe(routes -> routes.forEach( route -> {
147
+ * sipRoutingAsyncClient.listRoutes().subscribe(route -> {
157
148
* System.out.println("Route name: " + route.getName());
158
149
* System.out.println("Route description: " + route.getDescription());
159
150
* System.out.println("Route number pattern: " + route.getNumberPattern());
160
151
* System.out.println("Route trunks: " + String.join(",", route.getTrunks()));
161
- * })) ;
152
+ * });
162
153
* </pre>
163
154
* <!-- end com.azure.communication.phonenumbers.siprouting.asyncclient.listRoutes -->
164
155
*
165
156
* @return SIP Trunk Routes.
166
157
*/
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 ());
170
161
}
171
162
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()
180
- * .subscribe(response -> response.getValue().forEach(route -> {
181
- * System.out.println("Route name: " + route.getName());
182
- * System.out.println("Route description: " + route.getDescription());
183
- * System.out.println("Route number pattern: " + route.getNumberPattern());
184
- * System.out.println("Route trunks: " + String.join(",", route.getTrunks()));
185
- * }));
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 ));
197
173
}
198
174
199
175
/**
@@ -238,7 +214,7 @@ public Mono<Void> setTrunk(SipTrunk trunk) {
238
214
@ ServiceMethod (returns = ReturnType .SINGLE )
239
215
public Mono <Void > setTrunks (List <SipTrunk > trunks ) {
240
216
SipConfiguration update = new SipConfiguration ().setTrunks (convertToApi (trunks ));
241
- List <SipTrunk > currentTrunks = listTrunks ().block ();
217
+ List <SipTrunk > currentTrunks = getTrunksInternal ().block ();
242
218
if (currentTrunks != null ) {
243
219
List <String > storedFqdns = currentTrunks .stream ().map (SipTrunk ::getFqdn ).collect (Collectors .toList ());
244
220
Set <String > updatedFqdns = trunks .stream ().map (SipTrunk ::getFqdn ).collect (Collectors .toSet ());
@@ -278,7 +254,7 @@ public Mono<Void> setTrunks(List<SipTrunk> trunks) {
278
254
@ ServiceMethod (returns = ReturnType .SINGLE )
279
255
public Mono <Response <Void >> setTrunksWithResponse (List <SipTrunk > trunks ) {
280
256
SipConfiguration update = new SipConfiguration ().setTrunks (convertToApi (trunks ));
281
- List <SipTrunk > currentTrunks = listTrunks ().block ();
257
+ List <SipTrunk > currentTrunks = getTrunksInternal ().block ();
282
258
if (currentTrunks != null ) {
283
259
List <String > storedFqdns = currentTrunks .stream ().map (SipTrunk ::getFqdn ).collect (Collectors .toList ());
284
260
Set <String > updatedFqdns = trunks .stream ().map (SipTrunk ::getFqdn ).collect (Collectors .toSet ());
@@ -360,7 +336,7 @@ public Mono<Response<Void>> setRoutesWithResponse(List<SipTrunkRoute> routes) {
360
336
*/
361
337
@ ServiceMethod (returns = ReturnType .SINGLE )
362
338
public Mono <Void > deleteTrunk (String fqdn ) {
363
- List <SipTrunk > trunks = listTrunks ().block ();
339
+ List <SipTrunk > trunks = getTrunksInternal ().block ();
364
340
if (trunks == null || trunks .isEmpty ()) {
365
341
return Mono .empty ();
366
342
}
@@ -395,7 +371,7 @@ public Mono<Void> deleteTrunk(String fqdn) {
395
371
*/
396
372
@ ServiceMethod (returns = ReturnType .SINGLE )
397
373
public Mono <Response <Void >> deleteTrunkWithResponse (String fqdn ) {
398
- List <SipTrunk > trunks = listTrunks ().block ();
374
+ List <SipTrunk > trunks = getTrunksInternal ().block ();
399
375
if (trunks == null || trunks .isEmpty ()) {
400
376
return Mono .just (new SimpleResponse <>(null , 200 , null , null ));
401
377
}
@@ -434,11 +410,11 @@ private Mono<Response<SipConfiguration>> setSipConfigurationWithResponse(SipConf
434
410
.onErrorMap (CommunicationErrorResponseException .class , this ::translateException );
435
411
}
436
412
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 ()) );
443
419
}
444
420
}
0 commit comments