Skip to content

Commit cbf8c0d

Browse files
call source code refactor (Azure#32578)
1 parent f5e7381 commit cbf8c0d

21 files changed

+113
-99
lines changed

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallAutomationAsyncClient.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.azure.communication.callautomation.implementation.ServerCallsImpl;
1111
import com.azure.communication.callautomation.implementation.accesshelpers.CallConnectionPropertiesConstructorProxy;
1212
import com.azure.communication.callautomation.implementation.accesshelpers.ErrorConstructorProxy;
13+
import com.azure.communication.callautomation.implementation.converters.CallSourceConverter;
1314
import com.azure.communication.callautomation.implementation.converters.CommunicationIdentifierConverter;
1415
import com.azure.communication.callautomation.implementation.models.CallSourceInternal;
1516
import com.azure.communication.callautomation.implementation.models.MediaStreamingAudioChannelTypeInternal;
@@ -18,14 +19,14 @@
1819
import com.azure.communication.callautomation.implementation.models.MediaStreamingTransportTypeInternal;
1920
import com.azure.communication.callautomation.models.AnswerCallOptions;
2021
import com.azure.communication.callautomation.models.AnswerCallResult;
22+
import com.azure.communication.callautomation.models.CallSource;
2123
import com.azure.communication.callautomation.models.CallingServerErrorException;
2224
import com.azure.communication.callautomation.implementation.models.CommunicationIdentifierModel;
2325
import com.azure.communication.callautomation.implementation.models.CreateCallRequestInternal;
2426
import com.azure.communication.callautomation.implementation.models.AnswerCallRequestInternal;
2527
import com.azure.communication.callautomation.implementation.models.RedirectCallRequestInternal;
2628
import com.azure.communication.callautomation.implementation.models.RejectCallRequestInternal;
2729
import com.azure.communication.callautomation.implementation.models.CallRejectReasonInternal;
28-
import com.azure.communication.callautomation.implementation.models.PhoneNumberIdentifierModel;
2930
import com.azure.communication.callautomation.models.CreateCallOptions;
3031
import com.azure.communication.callautomation.models.CreateCallResult;
3132
import com.azure.communication.callautomation.models.MediaStreamingOptions;
@@ -82,10 +83,10 @@ public final class CallAutomationAsyncClient {
8283
this.contentsInternal = callServiceClient.getContents();
8384
this.logger = new ClientLogger(CallAutomationAsyncClient.class);
8485
this.contentDownloader = new ContentDownloader(
85-
callServiceClient.getEndpoint(),
86+
callServiceClient.getEndpoint().toString(),
8687
callServiceClient.getHttpPipeline());
8788
this.httpPipelineInternal = callServiceClient.getHttpPipeline();
88-
this.resourceEndpoint = callServiceClient.getEndpoint();
89+
this.resourceEndpoint = callServiceClient.getEndpoint().toString();
8990
}
9091

9192
//region Pre-call Actions
@@ -100,7 +101,7 @@ public final class CallAutomationAsyncClient {
100101
* @return Response for a successful CreateCallConnection request.
101102
*/
102103
@ServiceMethod(returns = ReturnType.SINGLE)
103-
public Mono<CreateCallResult> createCall(CommunicationIdentifier source,
104+
public Mono<CreateCallResult> createCall(CallSource source,
104105
List<CommunicationIdentifier> targets,
105106
String callbackUrl) {
106107
CreateCallOptions createCallOptions = new CreateCallOptions(source, targets, callbackUrl);
@@ -153,12 +154,7 @@ private CreateCallRequestInternal getCreateCallRequestInternal(CreateCallOptions
153154
List<CommunicationIdentifierModel> targetsModel = createCallOptions.getTargets()
154155
.stream().map(CommunicationIdentifierConverter::convert).collect(Collectors.toList());
155156

156-
CallSourceInternal callSourceDto = new CallSourceInternal().setIdentifier(
157-
CommunicationIdentifierConverter.convert(createCallOptions.getSource()));
158-
if (createCallOptions.getSourceCallerId() != null) {
159-
callSourceDto.setCallerId(new PhoneNumberIdentifierModel().setValue(createCallOptions.getSourceCallerId()));
160-
}
161-
157+
CallSourceInternal callSourceDto = CallSourceConverter.convert(createCallOptions.getSource());
162158
CreateCallRequestInternal request = new CreateCallRequestInternal()
163159
.setSource(callSourceDto)
164160
.setTargets(targetsModel)

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallAutomationClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.azure.communication.callautomation.models.AnswerCallOptions;
88
import com.azure.communication.callautomation.models.AnswerCallResult;
9+
import com.azure.communication.callautomation.models.CallSource;
910
import com.azure.communication.callautomation.models.CallingServerErrorException;
1011
import com.azure.communication.callautomation.models.CreateCallOptions;
1112
import com.azure.communication.callautomation.models.CreateCallResult;
@@ -49,7 +50,7 @@ public final class CallAutomationClient {
4950
* @return A CallConnectionDelete object.
5051
*/
5152
@ServiceMethod(returns = ReturnType.SINGLE)
52-
public CreateCallResult createCall(CommunicationIdentifier source,
53+
public CreateCallResult createCall(CallSource source,
5354
List<CommunicationIdentifier> targets,
5455
String callbackUrl) {
5556
return callAutomationAsyncClient.createCall(source, targets, callbackUrl).block();

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/CallAutomationClientBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ private AzureCommunicationCallAutomationServiceImpl createServiceImpl() {
377377

378378
AzureCommunicationCallAutomationServiceImplBuilder clientBuilder = new AzureCommunicationCallAutomationServiceImplBuilder();
379379
try {
380-
clientBuilder.endpoint(endpoint).pipeline(builderPipeline);
381-
} catch (RuntimeException e) {
380+
clientBuilder.endpoint(new URL(endpoint)).pipeline(builderPipeline);
381+
} catch (MalformedURLException e) {
382382
throw logger.logExceptionAsError(new RuntimeException(e.getMessage()));
383383
}
384384

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/implementation/AzureCommunicationCallAutomationServiceImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
import com.azure.core.http.policy.UserAgentPolicy;
1212
import com.azure.core.util.serializer.JacksonAdapter;
1313
import com.azure.core.util.serializer.SerializerAdapter;
14+
import java.net.URL;
1415

1516
/** Initializes a new instance of the AzureCommunicationCallAutomationService type. */
1617
public final class AzureCommunicationCallAutomationServiceImpl {
1718
/** The endpoint of the Azure Communication resource. */
18-
private final String endpoint;
19+
private final URL endpoint;
1920

2021
/**
2122
* Gets The endpoint of the Azure Communication resource.
2223
*
2324
* @return the endpoint value.
2425
*/
25-
public String getEndpoint() {
26+
public URL getEndpoint() {
2627
return this.endpoint;
2728
}
2829

@@ -116,7 +117,7 @@ public ServerCallsImpl getServerCalls() {
116117
* @param endpoint The endpoint of the Azure Communication resource.
117118
* @param apiVersion Api Version.
118119
*/
119-
AzureCommunicationCallAutomationServiceImpl(String endpoint, String apiVersion) {
120+
AzureCommunicationCallAutomationServiceImpl(URL endpoint, String apiVersion) {
120121
this(
121122
new HttpPipelineBuilder()
122123
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
@@ -133,7 +134,7 @@ public ServerCallsImpl getServerCalls() {
133134
* @param endpoint The endpoint of the Azure Communication resource.
134135
* @param apiVersion Api Version.
135136
*/
136-
AzureCommunicationCallAutomationServiceImpl(HttpPipeline httpPipeline, String endpoint, String apiVersion) {
137+
AzureCommunicationCallAutomationServiceImpl(HttpPipeline httpPipeline, URL endpoint, String apiVersion) {
137138
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, apiVersion);
138139
}
139140

@@ -146,7 +147,7 @@ public ServerCallsImpl getServerCalls() {
146147
* @param apiVersion Api Version.
147148
*/
148149
AzureCommunicationCallAutomationServiceImpl(
149-
HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, String apiVersion) {
150+
HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, URL endpoint, String apiVersion) {
150151
this.httpPipeline = httpPipeline;
151152
this.serializerAdapter = serializerAdapter;
152153
this.endpoint = endpoint;

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/implementation/AzureCommunicationCallAutomationServiceImplBuilder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.azure.core.util.Configuration;
1919
import com.azure.core.util.serializer.JacksonAdapter;
2020
import com.azure.core.util.serializer.SerializerAdapter;
21+
import java.net.URL;
2122
import java.util.ArrayList;
2223
import java.util.HashMap;
2324
import java.util.List;
@@ -40,15 +41,15 @@ public AzureCommunicationCallAutomationServiceImplBuilder() {
4041
/*
4142
* The endpoint of the Azure Communication resource.
4243
*/
43-
private String endpoint;
44+
private URL endpoint;
4445

4546
/**
4647
* Sets The endpoint of the Azure Communication resource.
4748
*
4849
* @param endpoint the endpoint value.
4950
* @return the AzureCommunicationCallAutomationServiceImplBuilder.
5051
*/
51-
public AzureCommunicationCallAutomationServiceImplBuilder endpoint(String endpoint) {
52+
public AzureCommunicationCallAutomationServiceImplBuilder endpoint(URL endpoint) {
5253
this.endpoint = endpoint;
5354
return this;
5455
}

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/implementation/CallConnectionsImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.azure.core.http.rest.RestProxy;
3333
import com.azure.core.util.Context;
3434
import com.azure.core.util.FluxUtil;
35+
import java.net.URL;
3536
import java.util.UUID;
3637
import reactor.core.publisher.Mono;
3738

@@ -65,7 +66,7 @@ public interface CallConnectionsService {
6566
@ExpectedResponses({200})
6667
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
6768
Mono<Response<CallConnectionPropertiesInternal>> getCall(
68-
@HostParam("endpoint") String endpoint,
69+
@HostParam("endpoint") URL endpoint,
6970
@PathParam("callConnectionId") String callConnectionId,
7071
@QueryParam("api-version") String apiVersion,
7172
@HeaderParam("Accept") String accept,
@@ -75,7 +76,7 @@ Mono<Response<CallConnectionPropertiesInternal>> getCall(
7576
@ExpectedResponses({204})
7677
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
7778
Mono<Response<Void>> hangupCall(
78-
@HostParam("endpoint") String endpoint,
79+
@HostParam("endpoint") URL endpoint,
7980
@PathParam("callConnectionId") String callConnectionId,
8081
@QueryParam("api-version") String apiVersion,
8182
@HeaderParam("Accept") String accept,
@@ -85,7 +86,7 @@ Mono<Response<Void>> hangupCall(
8586
@ExpectedResponses({204})
8687
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
8788
Mono<Response<Void>> terminateCall(
88-
@HostParam("endpoint") String endpoint,
89+
@HostParam("endpoint") URL endpoint,
8990
@PathParam("callConnectionId") String callConnectionId,
9091
@QueryParam("api-version") String apiVersion,
9192
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
@@ -97,7 +98,7 @@ Mono<Response<Void>> terminateCall(
9798
@ExpectedResponses({202})
9899
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
99100
Mono<Response<TransferCallResponseInternal>> transferToParticipant(
100-
@HostParam("endpoint") String endpoint,
101+
@HostParam("endpoint") URL endpoint,
101102
@PathParam("callConnectionId") String callConnectionId,
102103
@QueryParam("api-version") String apiVersion,
103104
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
@@ -110,7 +111,7 @@ Mono<Response<TransferCallResponseInternal>> transferToParticipant(
110111
@ExpectedResponses({200})
111112
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
112113
Mono<Response<GetParticipantsResponseInternal>> getParticipants(
113-
@HostParam("endpoint") String endpoint,
114+
@HostParam("endpoint") URL endpoint,
114115
@PathParam("callConnectionId") String callConnectionId,
115116
@QueryParam("api-version") String apiVersion,
116117
@HeaderParam("Accept") String accept,
@@ -120,7 +121,7 @@ Mono<Response<GetParticipantsResponseInternal>> getParticipants(
120121
@ExpectedResponses({202})
121122
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
122123
Mono<Response<AddParticipantsResponseInternal>> addParticipant(
123-
@HostParam("endpoint") String endpoint,
124+
@HostParam("endpoint") URL endpoint,
124125
@PathParam("callConnectionId") String callConnectionId,
125126
@QueryParam("api-version") String apiVersion,
126127
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
@@ -133,7 +134,7 @@ Mono<Response<AddParticipantsResponseInternal>> addParticipant(
133134
@ExpectedResponses({202})
134135
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
135136
Mono<Response<RemoveParticipantsResponseInternal>> removeParticipants(
136-
@HostParam("endpoint") String endpoint,
137+
@HostParam("endpoint") URL endpoint,
137138
@PathParam("callConnectionId") String callConnectionId,
138139
@QueryParam("api-version") String apiVersion,
139140
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
@@ -146,7 +147,7 @@ Mono<Response<RemoveParticipantsResponseInternal>> removeParticipants(
146147
@ExpectedResponses({200})
147148
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
148149
Mono<Response<AcsCallParticipantInternal>> getParticipant(
149-
@HostParam("endpoint") String endpoint,
150+
@HostParam("endpoint") URL endpoint,
150151
@PathParam("callConnectionId") String callConnectionId,
151152
@PathParam("participantMri") String participantMri,
152153
@QueryParam("api-version") String apiVersion,

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/implementation/ContentsImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.azure.core.http.rest.RestProxy;
2626
import com.azure.core.util.Context;
2727
import com.azure.core.util.FluxUtil;
28+
import java.net.URL;
2829
import java.util.UUID;
2930
import reactor.core.publisher.Mono;
3031

@@ -57,7 +58,7 @@ public interface ContentsService {
5758
@ExpectedResponses({202})
5859
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
5960
Mono<Response<Void>> play(
60-
@HostParam("endpoint") String endpoint,
61+
@HostParam("endpoint") URL endpoint,
6162
@PathParam("callConnectionId") String callConnectionId,
6263
@QueryParam("api-version") String apiVersion,
6364
@BodyParam("application/json") PlayRequest playRequest,
@@ -68,7 +69,7 @@ Mono<Response<Void>> play(
6869
@ExpectedResponses({202})
6970
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
7071
Mono<Response<Void>> cancelAllMediaOperations(
71-
@HostParam("endpoint") String endpoint,
72+
@HostParam("endpoint") URL endpoint,
7273
@PathParam("callConnectionId") String callConnectionId,
7374
@QueryParam("api-version") String apiVersion,
7475
@HeaderParam("Accept") String accept,
@@ -78,7 +79,7 @@ Mono<Response<Void>> cancelAllMediaOperations(
7879
@ExpectedResponses({202})
7980
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
8081
Mono<Response<Void>> recognize(
81-
@HostParam("endpoint") String endpoint,
82+
@HostParam("endpoint") URL endpoint,
8283
@PathParam("callConnectionId") String callConnectionId,
8384
@QueryParam("api-version") String apiVersion,
8485
@BodyParam("application/json") RecognizeRequest recognizeRequest,
@@ -89,7 +90,7 @@ Mono<Response<Void>> recognize(
8990
@ExpectedResponses({200})
9091
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
9192
Mono<Response<RecordingStateResponseInternal>> recording(
92-
@HostParam("endpoint") String endpoint,
93+
@HostParam("endpoint") URL endpoint,
9394
@QueryParam("api-version") String apiVersion,
9495
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
9596
@HeaderParam("Repeatability-First-Sent") String repeatabilityFirstSent,

sdk/communication/azure-communication-callautomation/src/main/java/com/azure/communication/callautomation/implementation/ServerCallingsImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.azure.core.http.rest.RestProxy;
2626
import com.azure.core.util.Context;
2727
import com.azure.core.util.FluxUtil;
28+
import java.net.URL;
2829
import java.util.UUID;
2930
import reactor.core.publisher.Mono;
3031

@@ -58,7 +59,7 @@ public interface ServerCallingsService {
5859
@ExpectedResponses({201})
5960
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
6061
Mono<Response<CallConnectionPropertiesInternal>> createCall(
61-
@HostParam("endpoint") String endpoint,
62+
@HostParam("endpoint") URL endpoint,
6263
@QueryParam("api-version") String apiVersion,
6364
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
6465
@HeaderParam("Repeatability-First-Sent") String repeatabilityFirstSent,
@@ -70,7 +71,7 @@ Mono<Response<CallConnectionPropertiesInternal>> createCall(
7071
@ExpectedResponses({200})
7172
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
7273
Mono<Response<CallConnectionPropertiesInternal>> answerCall(
73-
@HostParam("endpoint") String endpoint,
74+
@HostParam("endpoint") URL endpoint,
7475
@QueryParam("api-version") String apiVersion,
7576
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
7677
@HeaderParam("Repeatability-First-Sent") String repeatabilityFirstSent,
@@ -82,7 +83,7 @@ Mono<Response<CallConnectionPropertiesInternal>> answerCall(
8283
@ExpectedResponses({204})
8384
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
8485
Mono<Response<Void>> redirectCall(
85-
@HostParam("endpoint") String endpoint,
86+
@HostParam("endpoint") URL endpoint,
8687
@QueryParam("api-version") String apiVersion,
8788
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
8889
@HeaderParam("Repeatability-First-Sent") String repeatabilityFirstSent,
@@ -94,7 +95,7 @@ Mono<Response<Void>> redirectCall(
9495
@ExpectedResponses({204})
9596
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
9697
Mono<Response<Void>> rejectCall(
97-
@HostParam("endpoint") String endpoint,
98+
@HostParam("endpoint") URL endpoint,
9899
@QueryParam("api-version") String apiVersion,
99100
@HeaderParam("Repeatability-Request-ID") UUID repeatabilityRequestID,
100101
@HeaderParam("Repeatability-First-Sent") String repeatabilityFirstSent,

0 commit comments

Comments
 (0)