Skip to content

Commit

Permalink
Merge branch 'Onlineberatung:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow authored Sep 22, 2023
2 parents c71ad46 + 453d9c9 commit 145afb9
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 43 deletions.
13 changes: 11 additions & 2 deletions services/statisticsservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ paths:
operationId: getConsultantStatistics
responses:
200:
description: OK - successfull operation
description: OK - successful operation
400:
description: BAD REQUEST - invalid/incomplete request or body object
403:
Expand All @@ -29,7 +29,7 @@ paths:
operationId: getConsultantStatisticsCsv
responses:
200:
description: OK - successfull operation
description: OK - successful operation
400:
description: BAD REQUEST - invalid/incomplete request or body object
403:
Expand Down Expand Up @@ -124,10 +124,19 @@ components:
format: int64
description: The id of the session
example: 12345
adviceSeekerId:
type: string
description: The id of the adviceseeker
example: 12345
videoCallUuid:
type: string
description: The uuid of the video call
example: 123e4567-e89b-12d3-a456-556642440000
tenantId:
type: integer
format: int64
description: The id of the tenant
example: 12345

StopVideoCallStatisticsEventMessage:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import de.caritas.cob.videoservice.api.model.VideoCallResponseDTO;
import de.caritas.cob.videoservice.api.service.RejectVideoCallService;
import de.caritas.cob.videoservice.api.service.video.VideoCallUrlGeneratorService;
import de.caritas.cob.videoservice.api.tenant.TenantContext;
import de.caritas.cob.videoservice.generated.api.controller.VideocallsApi;
import io.swagger.annotations.Api;
import java.util.UUID;
import javax.validation.Valid;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -28,6 +30,9 @@ public class VideoController implements VideocallsApi {
private final @NonNull RejectVideoCallService rejectVideoCallService;
private final @NonNull VideoCallUrlGeneratorService videoCallUrlGeneratorService;

@Value("${multitenancy.enabled}")
private boolean multitenancy;

/**
* Starts a new video call.
*
Expand Down Expand Up @@ -58,6 +63,11 @@ public ResponseEntity<Void> stopVideoCall(UUID roomId) {

@Override
public ResponseEntity<Void> handleVideoCallStoppedEvent(String roomId) {
if (multitenancy) {
// prosody events are tenant-unaware, therefore set the tenant to 0 to be able to send
// messages
TenantContext.setCurrentTenant(0L);
}
videoCallFacade.handleVideoCallStoppedEvent(roomId);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import de.caritas.cob.videoservice.api.service.statistics.event.StopVideoCallStatisticsEvent;
import de.caritas.cob.videoservice.api.service.video.VideoCallUrlGeneratorService;
import de.caritas.cob.videoservice.api.service.video.VideoRoomService;
import de.caritas.cob.videoservice.api.tenant.TenantContext;
import de.caritas.cob.videoservice.liveservice.generated.web.model.EventType;
import de.caritas.cob.videoservice.liveservice.generated.web.model.LiveEventMessage;
import de.caritas.cob.videoservice.liveservice.generated.web.model.VideoCallRequestDTO;
Expand Down Expand Up @@ -85,15 +86,17 @@ private VideoCallResponseDTO startOneToOneVideoCall(
singletonList(consultantSessionDto.getAskerId()));

this.videoRoomService.createOneToOneVideoRoom(
consultantSessionDto.getId(),
consultantSessionDto.getGroupId(),
videoCallUuid,
videoCallUrls.getModeratorVideoUrl());
consultantSessionDto.getId(), consultantSessionDto.getGroupId(), videoCallUuid);
var createVideoCallResponseDto =
new VideoCallResponseDTO().moderatorVideoCallUrl(videoCallUrls.getModeratorVideoUrl());
statisticsService.fireEvent(
new StartVideoCallStatisticsEvent(
authenticatedUser.getUserId(), UserRole.CONSULTANT, sessionId, videoCallUuid));
authenticatedUser.getUserId(),
UserRole.CONSULTANT,
sessionId,
videoCallUuid,
consultantSessionDto.getAskerId(),
TenantContext.getCurrentTenant()));

log.info("Started one to one video call for sessionId {}", sessionId);
return createVideoCallResponseDto;
Expand Down Expand Up @@ -124,15 +127,13 @@ private VideoCallResponseDTO startGroupVideoCall(

var groupVideoRoom =
this.videoRoomService.createGroupVideoRoom(
createVideoCallRequest.getGroupChatId(),
chatById.getGroupId(),
videoCallUuid,
videoCallUrls.getUserVideoUrl());
createVideoCallRequest.getGroupChatId(), chatById.getGroupId(), videoCallUuid);

messageService.createAndSendVideoCallStartedMessage(
chatById.getGroupId(),
authenticatedUser.getUsername(),
groupVideoRoom,
videoCallUrls.getUserVideoUrl(),
createVideoCallRequest.getInitiatorDisplayName(),
initiatorRcUserId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public class VideoRoomEntity {
@Column(name = "group_chat_id", updatable = false)
private Long groupChatId;

@Column(name = "guest_video_link", nullable = false)
private String guestVideoLink;

@Column(name = "create_date", nullable = false)
private LocalDateTime createDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public void createAndSendVideoCallStartedMessage(
String groupId,
String username,
VideoRoomEntity videoRoomEntity,
String guestVideoUrl,
String initiatorDisplayName,
String initiatorRcUserId) {
AliasMessageDTO message =
createVideoChatMessage(
username,
videoRoomEntity,
guestVideoUrl,
"Videochat has started. Initiating moderator has joined the call.",
EventTypeEnum.CALL_STARTED);
message.getVideoCallMessageDTO().setInitiatorRcUserId(initiatorRcUserId);
Expand All @@ -78,34 +80,44 @@ public void createAndSendVideoCallStartedMessage(
}

public void createAndSendVideoCallEndedMessage(
String groupId, String username, VideoRoomEntity videoRoomEntity) {
String groupId, String username, VideoRoomEntity videoRoomEntity, String guestVideoUrl) {
AliasMessageDTO message =
createVideoChatMessage(
username,
videoRoomEntity,
guestVideoUrl,
"Videochat has ended. All moderators have left the call.",
EventTypeEnum.CALL_ENDED);
message.getVideoCallMessageDTO().setInitiatorRcUserId("");
message.getVideoCallMessageDTO().setInitiatorUserName("");
sendMessage(groupId, message);
}

public void createAndSendVideoCallEndedMessage(
String groupId, String username, VideoRoomEntity videoRoomEntity) {
createAndSendVideoCallEndedMessage(groupId, username, videoRoomEntity, "");
}

private AliasMessageDTO createVideoChatMessage(
String username,
VideoRoomEntity videoRoomEntity,
String guestVideoUrl,
String messageTitle,
EventTypeEnum eventType) {
AliasMessageDTO message = new AliasMessageDTO();

message.setContent(
getMessageContent(username, videoRoomEntity, messageTitle, message, eventType).toString());
getMessageContent(
username, videoRoomEntity, guestVideoUrl, messageTitle, message, eventType)
.toString());
message.setVideoCallMessageDTO(new VideoCallMessageDTO().eventType(eventType));
return message;
}

JSONObject getMessageContent(
String username,
VideoRoomEntity videoRoomEntity,
String guestVideoUrl,
String messageTitle,
AliasMessageDTO message,
EventTypeEnum eventType) {
Expand All @@ -114,7 +126,7 @@ JSONObject getMessageContent(
message.setMessageType(MessageType.VIDEOCALL);
messageContent.put("date", videoRoomEntity.getCreateDate());
messageContent.put("moderator_user", username);
messageContent.put("note", videoRoomEntity.getGuestVideoLink());
messageContent.put("note", guestVideoUrl);
long calculateDurationInSecods = calculateDurationInSeconds(videoRoomEntity);
messageContent.put("durationSeconds", calculateDurationInSecods);
messageContent.put("eventType", eventType.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import de.caritas.cob.videoservice.statisticsservice.generated.web.model.StartVideoCallStatisticsEventMessage;
import de.caritas.cob.videoservice.statisticsservice.generated.web.model.UserRole;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@AllArgsConstructor
public class StartVideoCallStatisticsEvent implements StatisticsEvent {

private static final EventType EVENT_TYPE = EventType.START_VIDEO_CALL;
Expand All @@ -19,6 +21,9 @@ public class StartVideoCallStatisticsEvent implements StatisticsEvent {
private @NonNull UserRole userRole;
private @NonNull Long sessionId;
private @NonNull String videoCallUuid;
private @NonNull String adviceSeekerId;

private Long tenantId;

/** {@inheritDoc} */
@Override
Expand All @@ -40,6 +45,8 @@ private StartVideoCallStatisticsEventMessage createStartVideoCallStatisticsEvent
.userRole(userRole)
.sessionId(sessionId)
.videoCallUuid(videoCallUuid)
.adviceSeekerId(adviceSeekerId)
.tenantId(tenantId)
.timestamp(CustomOffsetDateTime.nowInUtc());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@ public class VideoRoomService {
private final @NonNull VideoRoomRepository videoRoomRepository;

public VideoRoomEntity createOneToOneVideoRoom(
Long sessionId, String rocketChatRoomId, String jitsiRoomId, String videoLink) {
Long sessionId, String rocketChatRoomId, String jitsiRoomId) {
var videoRoom = new VideoRoomEntity();
videoRoom.setSessionId(sessionId);
videoRoom.setRocketChatRoomId(rocketChatRoomId);
videoRoom.setJitsiRoomId(jitsiRoomId);
videoRoom.setGuestVideoLink(videoLink);
videoRoom.setCreateDate(LocalDateTime.now());
return videoRoomRepository.save(videoRoom);
}

public VideoRoomEntity createGroupVideoRoom(
Long groupChatId, String rocketChatRoomId, String jitsiRoomId, String guestVideoLink) {
Long groupChatId, String rocketChatRoomId, String jitsiRoomId) {
var videoRoom = new VideoRoomEntity();
videoRoom.setGroupChatId(groupChatId);
videoRoom.setJitsiRoomId(jitsiRoomId);
videoRoom.setRocketChatRoomId(rocketChatRoomId);

videoRoom.setGuestVideoLink(guestVideoLink);
videoRoom.setCreateDate(LocalDateTime.now());
videoRoom.setCloseDate(null);
return videoRoomRepository.save(videoRoom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
public class HttpTenantFilter extends OncePerRequestFilter {

private static final String[] TENANCY_FILTER_WHITELIST =
new String[] {"/actuator/health", "/actuator/health/**", "/swagger-ui.html", "/favicon.ico"};
new String[] {
"/actuator/health",
"/actuator/health/**",
"/swagger-ui.html",
"/favicon.ico",
"/videocalls/event/stop/"
};
private final TenantResolverService tenantResolverService;
private final DefaultRequiresTenantFilterMatcher requiresTenantFilterMatcher =
new DefaultRequiresTenantFilterMatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CREATE TABLE videoservice.`videoroom` (
`group_chat_id` bigint(21) NULL,
`jitsi_room_id` varchar(40) NOT NULL,
`rocketchat_room_id` varchar(40) NULL,
`guest_video_link` varchar(1024) COLLATE utf8_unicode_ci NOT NULL,
`create_date` datetime NOT NULL DEFAULT (UTC_TIMESTAMP),
`close_date` datetime NULL,
PRIMARY KEY (`id`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ public void startVideoCall_Should_ReturnCorrectVideoCallUrl_When_UrlWasGenerated
// then
assertThat(result.getModeratorVideoCallUrl()).isEqualTo(videoCallUrls.getModeratorVideoUrl());
verify(videoRoomService)
.createGroupVideoRoom(
Mockito.eq(GROUP_CHAT_ID),
Mockito.eq(ROCKETCHAT_ROOM_ID),
Mockito.eq(VIDEO_CALL_UUID),
Mockito.anyString());
.createGroupVideoRoom(GROUP_CHAT_ID, ROCKETCHAT_ROOM_ID, VIDEO_CALL_UUID);

ArgumentCaptor<List<String>> captor = ArgumentCaptor.forClass(List.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void findById_Should_findRoomBySessionId() {
void create_Should_createVideoRoom() {
// given
VideoRoomEntity entity = new VideoRoomEntity();
entity.setGuestVideoLink("https://videolink." + UUID.randomUUID());
entity.setCreateDate(LocalDateTime.now());
entity.setJitsiRoomId(UUID.randomUUID().toString());
entity.setSessionId(1L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ void getMessageContent_Should_CalculateCallDuration() {
// when
JSONObject messageContent =
this.messageService.getMessageContent(
"user", videoRoomEntity, "title", new AliasMessageDTO(), EventTypeEnum.CALL_STARTED);
"user",
videoRoomEntity,
"guestVideoCallUrl",
"title",
new AliasMessageDTO(),
EventTypeEnum.CALL_STARTED);
// then
assertThat((Long) messageContent.get("durationSeconds")).isGreaterThanOrEqualTo(60L);
}
Expand All @@ -37,7 +42,12 @@ void getMessageContent_Should_CalculateCallDurationToZero_When_CreateDateIsNotSe
// when
JSONObject messageContent =
this.messageService.getMessageContent(
"user", videoRoomEntity, "title", new AliasMessageDTO(), EventTypeEnum.CALL_STARTED);
"user",
videoRoomEntity,
"guestVideoCallUrl",
"title",
new AliasMessageDTO(),
EventTypeEnum.CALL_STARTED);
// then
assertThat((Long) messageContent.get("durationSeconds")).isZero();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.caritas.cob.videoservice.api.service.statistics;

import static de.caritas.cob.videoservice.api.testhelper.TestConstants.ADVICESEEKER_ID;
import static de.caritas.cob.videoservice.api.testhelper.TestConstants.CONSULTANT_ID;
import static de.caritas.cob.videoservice.api.testhelper.TestConstants.SESSION_ID;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
Expand Down Expand Up @@ -43,7 +44,7 @@ public void fireEvent_Should_Send_ExpectedAssignSessionStatisticsEventMessageToQ
UUID uuid = UUID.randomUUID();
StartVideoCallStatisticsEvent startVideoCallStatisticsEvent =
new StartVideoCallStatisticsEvent(
CONSULTANT_ID, UserRole.CONSULTANT, SESSION_ID, uuid.toString());
CONSULTANT_ID, UserRole.CONSULTANT, SESSION_ID, uuid.toString(), ADVICESEEKER_ID);

statisticsService.fireEvent(startVideoCallStatisticsEvent);
Message message =
Expand All @@ -52,6 +53,9 @@ public void fireEvent_Should_Send_ExpectedAssignSessionStatisticsEventMessageToQ

String expectedJson =
"{"
+ " \"adviceSeekerId\":\""
+ ADVICESEEKER_ID
+ "\","
+ " \"userId\":\""
+ CONSULTANT_ID
+ "\","
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ public class StartVideoCallStatisticsEventTest {
private StartVideoCallStatisticsEvent startVideoCallStatisticsEvent;
private UUID uuid;

private UUID adviceSeekerUuid;

@Before
public void setup() {
uuid = UUID.randomUUID();
startVideoCallStatisticsEvent =
new StartVideoCallStatisticsEvent(
CONSULTANT_ID, UserRole.CONSULTANT, SESSION_ID, uuid.toString());
CONSULTANT_ID,
UserRole.CONSULTANT,
SESSION_ID,
uuid.toString(),
adviceSeekerUuid.toString());
}

@Test
Expand Down
Loading

0 comments on commit 145afb9

Please sign in to comment.