Skip to content

Commit

Permalink
Onboard Rooms to Sync Stack (#35900)
Browse files Browse the repository at this point in the history
  • Loading branch information
minnieliu authored Jul 18, 2023
1 parent 1b15ab3 commit 7d1658d
Show file tree
Hide file tree
Showing 9 changed files with 470 additions and 51 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public RoomsAsyncClient buildAsyncClient() {
* @return RoomsClient instance
*/
public RoomsClient buildClient() {
return new RoomsClient(buildAsyncClient());
return new RoomsClient(createServiceImpl());
}

private AzureCommunicationRoomServiceImpl createServiceImpl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/** A builder for creating a new instance of the AzureCommunicationRoomService type. */
@ServiceClientBuilder(serviceClients = {AzureCommunicationRoomServiceImpl.class})
Expand Down Expand Up @@ -261,21 +260,19 @@ private HttpPipeline createHttpPipeline() {
if (headers.getSize() > 0) {
policies.add(new AddHeadersPolicy(headers));
}
policies.addAll(
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
.collect(Collectors.toList()));
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL)
.forEach(p -> policies.add(p));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy()));
policies.add(new AddDatePolicy());
policies.add(new CookiePolicy());
if (azureKeyCredential != null) {
policies.add(new AzureKeyCredentialPolicy("Authorization", azureKeyCredential));
}
policies.addAll(
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
.collect(Collectors.toList()));
this.pipelinePolicies.stream()
.filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY)
.forEach(p -> policies.add(p));
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
HttpPipeline httpPipeline =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ Mono<Response<ParticipantsCollection>> list(
@HeaderParam("Accept") String accept,
Context context);

@Get("/rooms/{roomId}/participants")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Response<ParticipantsCollection> listSync(
@HostParam("endpoint") String endpoint,
@PathParam("roomId") String roomId,
@QueryParam("api-version") String apiVersion,
@HeaderParam("Accept") String accept,
Context context);

@Patch("/rooms/{roomId}/participants")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Expand All @@ -77,6 +87,17 @@ Mono<Response<Object>> update(
@HeaderParam("Accept") String accept,
Context context);

@Patch("/rooms/{roomId}/participants")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Response<Object> updateSync(
@HostParam("endpoint") String endpoint,
@PathParam("roomId") String roomId,
@QueryParam("api-version") String apiVersion,
@BodyParam("application/merge-patch+json") String updateParticipantsRequest,
@HeaderParam("Accept") String accept,
Context context);

@Get("{nextLink}")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Expand All @@ -85,6 +106,15 @@ Mono<Response<ParticipantsCollection>> listNext(
@HostParam("endpoint") String endpoint,
@HeaderParam("Accept") String accept,
Context context);

@Get("{nextLink}")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(CommunicationErrorResponseException.class)
Response<ParticipantsCollection> listNextSync(
@PathParam(value = "nextLink", encoded = true) String nextLink,
@HostParam("endpoint") String endpoint,
@HeaderParam("Accept") String accept,
Context context);
}

/**
Expand Down Expand Up @@ -184,7 +214,16 @@ public PagedFlux<RoomParticipant> listAsync(String roomId, Context context) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PagedResponse<RoomParticipant> listSinglePage(String roomId) {
return listSinglePageAsync(roomId).block();
final String accept = "application/json";
Response<ParticipantsCollection> res =
service.listSync(this.client.getEndpoint(), roomId, this.client.getApiVersion(), accept, Context.NONE);
return new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().getValue(),
res.getValue().getNextLink(),
null);
}

/**
Expand All @@ -199,7 +238,16 @@ public PagedResponse<RoomParticipant> listSinglePage(String roomId) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PagedResponse<RoomParticipant> listSinglePage(String roomId, Context context) {
return listSinglePageAsync(roomId, context).block();
final String accept = "application/json";
Response<ParticipantsCollection> res =
service.listSync(this.client.getEndpoint(), roomId, this.client.getApiVersion(), accept, context);
return new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().getValue(),
res.getValue().getNextLink(),
null);
}

/**
Expand All @@ -213,7 +261,8 @@ public PagedResponse<RoomParticipant> listSinglePage(String roomId, Context cont
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<RoomParticipant> list(String roomId) {
return new PagedIterable<>(listAsync(roomId));
return new PagedIterable<>(
() -> listSinglePage(roomId, Context.NONE), nextLink -> listNextSinglePage(nextLink));
}

/**
Expand All @@ -228,7 +277,8 @@ public PagedIterable<RoomParticipant> list(String roomId) {
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PagedIterable<RoomParticipant> list(String roomId, Context context) {
return new PagedIterable<>(listAsync(roomId, context));
return new PagedIterable<>(
() -> listSinglePage(roomId, context), nextLink -> listNextSinglePage(nextLink, context));
}

/**
Expand Down Expand Up @@ -325,7 +375,14 @@ public Mono<Object> updateAsync(String roomId, String updateParticipantsRequest,
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<Object> updateWithResponse(String roomId, String updateParticipantsRequest, Context context) {
return updateWithResponseAsync(roomId, updateParticipantsRequest, context).block();
final String accept = "application/json";
return service.updateSync(
this.client.getEndpoint(),
roomId,
this.client.getApiVersion(),
updateParticipantsRequest,
accept,
context);
}

/**
Expand Down Expand Up @@ -408,7 +465,16 @@ public Mono<PagedResponse<RoomParticipant>> listNextSinglePageAsync(String nextL
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PagedResponse<RoomParticipant> listNextSinglePage(String nextLink) {
return listNextSinglePageAsync(nextLink).block();
final String accept = "application/json";
Response<ParticipantsCollection> res =
service.listNextSync(nextLink, this.client.getEndpoint(), accept, Context.NONE);
return new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().getValue(),
res.getValue().getNextLink(),
null);
}

/**
Expand All @@ -424,6 +490,15 @@ public PagedResponse<RoomParticipant> listNextSinglePage(String nextLink) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public PagedResponse<RoomParticipant> listNextSinglePage(String nextLink, Context context) {
return listNextSinglePageAsync(nextLink, context).block();
final String accept = "application/json";
Response<ParticipantsCollection> res =
service.listNextSync(nextLink, this.client.getEndpoint(), accept, context);
return new PagedResponseBase<>(
res.getRequest(),
res.getStatusCode(),
res.getHeaders(),
res.getValue().getValue(),
res.getValue().getNextLink(),
null);
}
}
Loading

0 comments on commit 7d1658d

Please sign in to comment.