Skip to content

Commit

Permalink
Merge pull request #1 from wangrui-msft/rtung/IdempotencyJavaSDK
Browse files Browse the repository at this point in the history
Idempotency Java SDK
  • Loading branch information
wangrui-msft committed Apr 30, 2022
2 parents 34c2be3 + 8b33ee9 commit fa6d615
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.azure.communication.rooms.implementation.models.RoomParticipantInternal;
import com.azure.communication.rooms.implementation.models.UpdateRoomRequest;
import com.azure.communication.rooms.implementation.models.CreateRoomRequest;
import com.azure.communication.rooms.implementation.models.CreateRoomResponse;
import com.azure.communication.rooms.implementation.models.UpdateRoomResponse;
import com.azure.communication.rooms.models.CommunicationRoom;
import com.azure.communication.rooms.models.RoomParticipant;
import com.azure.core.annotation.ReturnType;
Expand Down Expand Up @@ -61,8 +59,8 @@ Mono<CommunicationRoom> createRoom(OffsetDateTime validFrom, OffsetDateTime vali
try {
return this.roomsClient
.createRoomWithResponseAsync(toCreateRoomRequest(validFrom, validUntil, participants), context)
.flatMap((Response<CreateRoomResponse> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants()));
.flatMap((Response<RoomModel> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue()));
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -87,8 +85,8 @@ Mono<Response<CommunicationRoom>> createRoomWithResponse(OffsetDateTime validFro
try {
return this.roomsClient
.createRoomWithResponseAsync(toCreateRoomRequest(validFrom, validUntil, participants), context)
.flatMap((Response<CreateRoomResponse> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants());
.flatMap((Response<RoomModel> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue());
return Mono.just(new SimpleResponse<CommunicationRoom>(response, communicationRoom));
});
} catch (RuntimeException ex) {
Expand All @@ -114,8 +112,8 @@ Mono<CommunicationRoom> updateRoom(String roomId, OffsetDateTime validFrom, Offs
try {
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(validFrom, validUntil, null, false), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants()));
.flatMap((Response<RoomModel> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue()));
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -141,8 +139,8 @@ Mono<Response<CommunicationRoom>> updateRoomWithResponse(String roomId, OffsetDa
try {
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(validFrom, validUntil, null, false), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants());
.flatMap((Response<RoomModel> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue());
return Mono.just(new SimpleResponse<CommunicationRoom>(response, communicationRoom));
});
} catch (RuntimeException ex) {
Expand All @@ -169,7 +167,7 @@ Mono<CommunicationRoom> getRoom(String roomId, Context context) {
.getRoomWithResponseAsync(roomId, context)
.flatMap(
(Response<RoomModel> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue(), null));
return Mono.just(getCommunicationRoomFromResponse(response.getValue()));
}
);
} catch (RuntimeException ex) {
Expand All @@ -196,7 +194,7 @@ Mono<Response<CommunicationRoom>> getRoomWithResponse(String roomId, Context con
.getRoomWithResponseAsync(roomId, context)
.flatMap(
(Response<RoomModel> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue(), null);
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue());
return Mono.just(new SimpleResponse<CommunicationRoom>(response, communicationRoom));
}
);
Expand Down Expand Up @@ -247,8 +245,8 @@ Mono<CommunicationRoom> addParticipants(String roomId, List<RoomParticipant> par
try {
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(null, null, participants, false), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants()));
.flatMap((Response<RoomModel> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue()));
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -273,8 +271,8 @@ Mono<Response<CommunicationRoom>> addParticipantsWithResponse(String roomId, Lis
try {
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(null, null, participants, false), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants());
.flatMap((Response<RoomModel> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue());
return Mono.just(new SimpleResponse<CommunicationRoom>(response, communicationRoom));
});
} catch (RuntimeException ex) {
Expand All @@ -299,8 +297,8 @@ Mono<CommunicationRoom> updateParticipants(String roomId, List<RoomParticipant>
try {
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(null, null, participants, false), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants()));
.flatMap((Response<RoomModel> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue()));
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -325,8 +323,8 @@ Mono<Response<CommunicationRoom>> updateParticipantsWithResponse(String roomId,
try {
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(null, null, participants, false), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants());
.flatMap((Response<RoomModel> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue());
return Mono.just(new SimpleResponse<CommunicationRoom>(response, communicationRoom));
});
} catch (RuntimeException ex) {
Expand All @@ -351,8 +349,8 @@ Mono<CommunicationRoom> removeParticipants(String roomId, List<RoomParticipant>
try {
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(null, null, participants, true), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants()));
.flatMap((Response<RoomModel> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue()));
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -377,8 +375,8 @@ Mono<Response<CommunicationRoom>> removeParticipantsWithResponse(String roomId,
try {
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(null, null, participants, true), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants());
.flatMap((Response<RoomModel> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue());
return Mono.just(new SimpleResponse<CommunicationRoom>(response, communicationRoom));
});
} catch (RuntimeException ex) {
Expand All @@ -403,8 +401,8 @@ Mono<CommunicationRoom> removeAllParticipants(String roomId, Context context) {
Map<String, RoomParticipantInternal> participants = new HashMap<>();
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(null, null, participants), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants()));
.flatMap((Response<RoomModel> response) -> {
return Mono.just(getCommunicationRoomFromResponse(response.getValue()));
});
} catch (RuntimeException ex) {
return monoError(logger, ex);
Expand All @@ -429,8 +427,8 @@ Mono<Response<CommunicationRoom>> removeAllParticipantsWithResponse(String roomI
Map<String, RoomParticipantInternal> participants = new HashMap<>();
return this.roomsClient
.updateRoomWithResponseAsync(roomId, toUpdateRoomRequest(null, null, participants), context)
.flatMap((Response<UpdateRoomResponse> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue().getRoom(), response.getValue().getInvalidParticipants());
.flatMap((Response<RoomModel> response) -> {
CommunicationRoom communicationRoom = getCommunicationRoomFromResponse(response.getValue());
return Mono.just(new SimpleResponse<CommunicationRoom>(response, communicationRoom));
});
} catch (RuntimeException ex) {
Expand All @@ -447,7 +445,7 @@ private Map<String, RoomParticipantInternal> createParticipantMapFromCollection(
return participantMap;
}

private CommunicationRoom getCommunicationRoomFromResponse(RoomModel room, Map<String, RoomParticipantInternal> invalidParticipant) {
private CommunicationRoom getCommunicationRoomFromResponse(RoomModel room) {
List<RoomParticipant> participants = new ArrayList<>();
if (room.getParticipants() != null) {
participants = room.getParticipants().entrySet().stream()
Expand All @@ -458,8 +456,7 @@ private CommunicationRoom getCommunicationRoomFromResponse(RoomModel room, Map<S
room.getValidFrom(),
room.getValidUntil(),
room.getCreatedDateTime(),
participants,
invalidParticipant);
participants);
}

/**
Expand Down

0 comments on commit fa6d615

Please sign in to comment.