Skip to content

Commit

Permalink
Refactor code (#22053)
Browse files Browse the repository at this point in the history
  • Loading branch information
arifsaikat-microsoft authored Jun 3, 2021
1 parent 32dd081 commit dace1b7
Show file tree
Hide file tree
Showing 32 changed files with 110 additions and 441 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
import com.azure.communication.callingserver.implementation.models.CallModality;
import com.azure.communication.callingserver.implementation.models.CancelAllMediaOperationsRequest;
import com.azure.communication.callingserver.implementation.models.CreateCallRequestInternal;
import com.azure.communication.callingserver.implementation.models.CreateCallResponse;
import com.azure.communication.callingserver.implementation.models.EventSubscriptionType;
import com.azure.communication.callingserver.implementation.models.InviteParticipantsRequest;
import com.azure.communication.callingserver.implementation.models.PhoneNumberIdentifierModel;
import com.azure.communication.callingserver.implementation.models.PlayAudioRequest;
import com.azure.communication.callingserver.models.CancelAllMediaOperationsResponse;
import com.azure.communication.callingserver.models.CreateCallOptions;
import com.azure.communication.callingserver.models.CreateCallResult;
import com.azure.communication.callingserver.models.CreateCallResponse;
import com.azure.communication.callingserver.models.PlayAudioResponse;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.ReturnType;
Expand Down Expand Up @@ -59,7 +58,7 @@ public final class CallAsyncClient {
* @return response for a successful CreateCall request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<CreateCallResult> createCall(CommunicationIdentifier source, Iterable<CommunicationIdentifier> targets,
public Mono<CreateCallResponse> createCall(CommunicationIdentifier source, Iterable<CommunicationIdentifier> targets,
CreateCallOptions createCallOptions) {
try {
Objects.requireNonNull(source, "'source' cannot be null.");
Expand All @@ -68,8 +67,7 @@ public Mono<CreateCallResult> createCall(CommunicationIdentifier source, Iterabl

CreateCallRequestInternal request = createCreateCallRequest(source, targets, createCallOptions);
return this.callClient.createCallAsync(request).flatMap((CreateCallResponse response) -> {
CreateCallResult createCallResult = convertCreateCallWithResponse(response);
return Mono.just(createCallResult);
return Mono.just(response);
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -85,12 +83,12 @@ public Mono<CreateCallResult> createCall(CommunicationIdentifier source, Iterabl
* @return response for a successful CreateCall request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<CreateCallResult>> createCallWithResponse(CommunicationIdentifier source,
public Mono<Response<CreateCallResponse>> createCallWithResponse(CommunicationIdentifier source,
Iterable<CommunicationIdentifier> targets, CreateCallOptions createCallOptions) {
return createCallWithResponse(source, targets, createCallOptions, null);
}

Mono<Response<CreateCallResult>> createCallWithResponse(CommunicationIdentifier source,
Mono<Response<CreateCallResponse>> createCallWithResponse(CommunicationIdentifier source,
Iterable<CommunicationIdentifier> targets, CreateCallOptions createCallOptions, Context context) {
try {
Objects.requireNonNull(source, "'source' cannot be null.");
Expand All @@ -105,8 +103,7 @@ Mono<Response<CreateCallResult>> createCallWithResponse(CommunicationIdentifier
}
return this.callClient.createCallWithResponseAsync(request)
.flatMap((Response<CreateCallResponse> response) -> {
CreateCallResult createCallResult = convertCreateCallWithResponse(response.getValue());
return Mono.just(new SimpleResponse<>(response, createCallResult));
return Mono.just(new SimpleResponse<>(response, response.getValue()));
});
});
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -138,7 +135,7 @@ public Mono<PlayAudioResponse> playAudio(String callId, String audioFileUri, boo
}
}

public Mono<PlayAudioResponse> playAudio(String callId, PlayAudioRequest request) {
Mono<PlayAudioResponse> playAudio(String callId, PlayAudioRequest request) {
try {
Objects.requireNonNull(callId, "'callId' cannot be null.");
Objects.requireNonNull(request, "'request' cannot be null.");
Expand Down Expand Up @@ -376,7 +373,7 @@ Mono<Response<Void>> addParticipantWithResponse(
if (context != null) {
contextValue = context;
}
return this.callClient.inviteParticipantsWithResponseAsync(callId,request);
return this.callClient.inviteParticipantsWithResponseAsync(callId, request);
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand Down Expand Up @@ -459,8 +456,4 @@ private CreateCallRequestInternal createCreateCallRequest(CommunicationIdentifie

return request;
}

private CreateCallResult convertCreateCallWithResponse(CreateCallResponse response) {
return new CreateCallResult().setCallLegId(response.getCallLegId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.azure.communication.callingserver.implementation.models.PlayAudioRequest;
import com.azure.communication.callingserver.models.CancelAllMediaOperationsResponse;
import com.azure.communication.callingserver.models.CreateCallOptions;
import com.azure.communication.callingserver.models.CreateCallResult;
import com.azure.communication.callingserver.models.CreateCallResponse;
import com.azure.communication.callingserver.models.PlayAudioResponse;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.ReturnType;
Expand Down Expand Up @@ -34,7 +34,7 @@ public final class CallClient {
* @return response for a successful CreateCall request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public CreateCallResult createCall(CommunicationIdentifier source, Iterable<CommunicationIdentifier> targets, CreateCallOptions createCallOptions) {
public CreateCallResponse createCall(CommunicationIdentifier source, Iterable<CommunicationIdentifier> targets, CreateCallOptions createCallOptions) {
return callAsyncClient.createCall(source, targets, createCallOptions).block();
}

Expand All @@ -48,7 +48,7 @@ public CreateCallResult createCall(CommunicationIdentifier source, Iterable<Comm
* @return response for a successful CreateCall request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<CreateCallResult> createCallWithResponse(CommunicationIdentifier source, Iterable<CommunicationIdentifier> targets, CreateCallOptions createCallOptions, Context context) {
public Response<CreateCallResponse> createCallWithResponse(CommunicationIdentifier source, Iterable<CommunicationIdentifier> targets, CreateCallOptions createCallOptions, Context context) {
return callAsyncClient.createCallWithResponse(source, targets, createCallOptions, context).block();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

import com.azure.communication.callingserver.implementation.AzureCommunicationCallingServerServiceImpl;
import com.azure.communication.callingserver.implementation.ConversationsImpl;
import com.azure.communication.callingserver.implementation.models.GetCallRecordingStateResponse;
import com.azure.communication.callingserver.implementation.models.StartCallRecordingResponse;
import com.azure.communication.callingserver.models.GetCallRecordingStateResult;
import com.azure.communication.callingserver.models.PlayAudioResponse;
import com.azure.communication.callingserver.implementation.converters.InviteParticipantsRequestConverter;
import com.azure.communication.callingserver.implementation.converters.JoinCallRequestConverter;
import com.azure.communication.callingserver.implementation.models.InviteParticipantsRequest;
import com.azure.communication.callingserver.implementation.models.PlayAudioRequest;
import com.azure.communication.callingserver.implementation.models.StartCallRecordingRequest;
import com.azure.communication.callingserver.models.GetCallRecordingStateResponse;
import com.azure.communication.callingserver.models.JoinCallOptions;
import com.azure.communication.callingserver.models.JoinCallResponse;
import com.azure.communication.callingserver.models.StartCallRecordingResult;
import com.azure.communication.callingserver.models.StartCallRecordingResponse;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
Expand Down Expand Up @@ -220,20 +218,18 @@ Mono<Response<Void>> removeParticipantWithResponse(String conversationId, String
* @return response for a successful startRecording request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<StartCallRecordingResult> startRecording(String conversationId, URI recordingStateCallbackUri) {
public Mono<StartCallRecordingResponse> startRecording(String conversationId, URI recordingStateCallbackUri) {
try {
Objects.requireNonNull(conversationId, "'conversationId' cannot be null.");
Objects.requireNonNull(recordingStateCallbackUri, "'recordingStateCallbackUri' cannot be null.");
if (!Boolean.TRUE.equals(recordingStateCallbackUri.isAbsolute())) {
throw logger.logExceptionAsError(new InvalidParameterException("'recordingStateCallbackUri' cannot be non absolute Uri"));
}

StartCallRecordingRequest request = createStartCallRecordingRequest(recordingStateCallbackUri);
StartCallRecordingRequest request = new StartCallRecordingRequest().setRecordingStateCallbackUri(recordingStateCallbackUri.toString());
return this.conversationsClient.startRecordingAsync(conversationId, request)
.flatMap((StartCallRecordingResponse response) -> {
StartCallRecordingResult startCallRecordingResult = convertGetCallRecordingStateResponse(
response);
return Mono.just(startCallRecordingResult);
return Mono.just(response);
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -249,12 +245,12 @@ public Mono<StartCallRecordingResult> startRecording(String conversationId, URI
* @return response for a successful startRecording request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<StartCallRecordingResult>> startRecordingWithResponse(String conversationId,
public Mono<Response<StartCallRecordingResponse>> startRecordingWithResponse(String conversationId,
URI recordingStateCallbackUri) {
return startRecordingWithResponse(conversationId, recordingStateCallbackUri, null);
}

Mono<Response<StartCallRecordingResult>> startRecordingWithResponse(String conversationId,
Mono<Response<StartCallRecordingResponse>> startRecordingWithResponse(String conversationId,
URI recordingStateCallbackUri, Context context) {
try {
Objects.requireNonNull(conversationId, "'conversationId' cannot be null.");
Expand All @@ -266,12 +262,10 @@ Mono<Response<StartCallRecordingResult>> startRecordingWithResponse(String conve
if (context != null) {
contextValue = context;
}
StartCallRecordingRequest request = createStartCallRecordingRequest(recordingStateCallbackUri);
StartCallRecordingRequest request = new StartCallRecordingRequest().setRecordingStateCallbackUri(recordingStateCallbackUri.toString());
return this.conversationsClient.startRecordingWithResponseAsync(conversationId, request)
.flatMap((Response<StartCallRecordingResponse> response) -> {
StartCallRecordingResult startCallRecordingResult = convertGetCallRecordingStateResponse(
response.getValue());
return Mono.just(new SimpleResponse<>(response, startCallRecordingResult));
return Mono.just(new SimpleResponse<>(response, response.getValue()));
});
});
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -422,15 +416,13 @@ Mono<Response<Void>> resumeRecordingWithResponse(String conversationId, String r
* @return response for a successful getRecordingState request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<GetCallRecordingStateResult> getRecordingState(String conversationId, String recordingId) {
public Mono<GetCallRecordingStateResponse> getRecordingState(String conversationId, String recordingId) {
try {
Objects.requireNonNull(conversationId, "'conversationId' cannot be null.");
Objects.requireNonNull(recordingId, "'recordingId' cannot be null.");
return this.conversationsClient.recordingStateAsync(conversationId, recordingId)
.flatMap((GetCallRecordingStateResponse response) -> {
GetCallRecordingStateResult getRecordingStateResult = convertGetCallRecordingStateResponse(
response);
return Mono.just(getRecordingStateResult);
return Mono.just(response);
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -445,12 +437,12 @@ public Mono<GetCallRecordingStateResult> getRecordingState(String conversationId
* @return response for a successful getRecordingState request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Response<GetCallRecordingStateResult>> getRecordingStateWithResponse(String conversationId,
public Mono<Response<GetCallRecordingStateResponse>> getRecordingStateWithResponse(String conversationId,
String recordingId) {
return getRecordingStateWithResponse(conversationId, recordingId, null);
}

Mono<Response<GetCallRecordingStateResult>> getRecordingStateWithResponse(String conversationId,
Mono<Response<GetCallRecordingStateResponse>> getRecordingStateWithResponse(String conversationId,
String recordingId, Context context) {
try {
Objects.requireNonNull(conversationId, "'conversationId' cannot be null.");
Expand All @@ -461,9 +453,7 @@ Mono<Response<GetCallRecordingStateResult>> getRecordingStateWithResponse(String
}
return this.conversationsClient.recordingStateWithResponseAsync(conversationId, recordingId)
.flatMap((Response<GetCallRecordingStateResponse> response) -> {
GetCallRecordingStateResult getRecordingStateResult = convertGetCallRecordingStateResponse(
response.getValue());
return Mono.just(new SimpleResponse<>(response, getRecordingStateResult));
return Mono.just(new SimpleResponse<>(response, response.getValue()));
});
});
} catch (RuntimeException ex) {
Expand Down Expand Up @@ -497,7 +487,7 @@ public Mono<PlayAudioResponse> playAudio(String conversationId, String audioFile
}
}

public Mono<PlayAudioResponse> playAudio(String conversationId, PlayAudioRequest request) {
Mono<PlayAudioResponse> playAudio(String conversationId, PlayAudioRequest request) {
try {
Objects.requireNonNull(conversationId, "'conversationId' cannot be null.");
Objects.requireNonNull(request, "'request' cannot be null.");
Expand Down Expand Up @@ -546,21 +536,4 @@ Mono<Response<PlayAudioResponse>> playAudioWithResponse(String conversationId, P
return monoError(logger, ex);
}
}

private StartCallRecordingRequest createStartCallRecordingRequest(URI recordingStateCallbackUri) {
StartCallRecordingRequest request = new StartCallRecordingRequest();
request.setRecordingStateCallbackUri(recordingStateCallbackUri.toString());
return request;
}

private GetCallRecordingStateResult convertGetCallRecordingStateResponse(
com.azure.communication.callingserver.implementation.models.GetCallRecordingStateResponse response) {
return new GetCallRecordingStateResult()
.setRecordingState(com.azure.communication.callingserver.models.CallRecordingState
.fromString(response.getRecordingState().toString()));
}

private StartCallRecordingResult convertGetCallRecordingStateResponse(StartCallRecordingResponse response) {
return new StartCallRecordingResult().setRecordingId(response.getRecordingId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
package com.azure.communication.callingserver;

import com.azure.communication.callingserver.implementation.models.PlayAudioRequest;
import com.azure.communication.callingserver.models.GetCallRecordingStateResult;
import com.azure.communication.callingserver.models.GetCallRecordingStateResponse;
import com.azure.communication.callingserver.models.JoinCallOptions;
import com.azure.communication.callingserver.models.JoinCallResponse;
import com.azure.communication.callingserver.models.PlayAudioResponse;
import com.azure.communication.callingserver.models.StartCallRecordingResult;
import com.azure.communication.callingserver.models.StartCallRecordingResponse;
import com.azure.communication.common.CommunicationIdentifier;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
Expand Down Expand Up @@ -120,7 +120,7 @@ public Response<Void> removeParticipantWithResponse(String conversationId, Strin
* @return response for a successful startRecording request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public StartCallRecordingResult startRecording(String conversationId, URI recordingStateCallbackUri) {
public StartCallRecordingResponse startRecording(String conversationId, URI recordingStateCallbackUri) {
return conversationAsyncClient.startRecording(conversationId, recordingStateCallbackUri).block();
}

Expand All @@ -133,7 +133,7 @@ public StartCallRecordingResult startRecording(String conversationId, URI record
* @return response for a successful startRecording request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<StartCallRecordingResult> startRecordingWithResponse(String conversationId,
public Response<StartCallRecordingResponse> startRecordingWithResponse(String conversationId,
URI recordingStateCallbackUri, Context context) {
return conversationAsyncClient.startRecordingWithResponse(conversationId, recordingStateCallbackUri, context).block();
}
Expand Down Expand Up @@ -221,7 +221,7 @@ public Response<Void> resumeRecordingWithResponse(String conversationId, String
* @return response for a successful getRecordingState request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public GetCallRecordingStateResult getRecordingState(String conversationId, String recordingId) {
public GetCallRecordingStateResponse getRecordingState(String conversationId, String recordingId) {
return conversationAsyncClient.getRecordingState(conversationId, recordingId).block();
}

Expand All @@ -234,7 +234,7 @@ public GetCallRecordingStateResult getRecordingState(String conversationId, Stri
* @return response for a successful getRecordingState request.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<GetCallRecordingStateResult> getRecordingStateWithResponse(String conversationId,
public Response<GetCallRecordingStateResponse> getRecordingStateWithResponse(String conversationId,
String recordingId, Context context) {
return conversationAsyncClient.getRecordingStateWithResponse(conversationId, recordingId, context).block();
}
Expand Down
Loading

0 comments on commit dace1b7

Please sign in to comment.