From 449f7d582462519ea1497ff58cca5465a6b194da Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 8 Apr 2021 15:44:05 +0200 Subject: [PATCH] SEBSERV-148 test and fixes --- .../ch/ethz/seb/sebserver/gbl/Constants.java | 2 ++ .../ExamProctoringRoomServiceImpl.java | 10 +++--- .../proctoring/ZoomProctoringService.java | 32 +++++++++++++++++-- .../proctoring/ZoomRoomRequestResponse.java | 9 ++++-- .../ethz/seb/sebserver/gbl/util/ReplTest.java | 13 ++++++++ 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java b/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java index 0af7d6fc..9e579b95 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java @@ -40,6 +40,8 @@ public final class Constants { public static final long HOUR_IN_MILLIS = 60 * MINUTE_IN_MILLIS; public static final long DAY_IN_MILLIS = 24 * HOUR_IN_MILLIS; + public static final int DAY_IN_MIN = 60 * 24; + public static final Character CARRIAGE_RETURN = '\n'; public static final Character CURLY_BRACE_OPEN = '{'; public static final Character CURLY_BRACE_CLOSE = '}'; diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ExamProctoringRoomServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ExamProctoringRoomServiceImpl.java index 18468e20..5431e3a5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ExamProctoringRoomServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ExamProctoringRoomServiceImpl.java @@ -387,11 +387,6 @@ public class ExamProctoringRoomServiceImpl implements ExamProctoringRoomService remoteProctoringRoom.breakOutConnections, examProctoringService.getDefaultInstructionAttributes()); - // Delete room on persistent - this.remoteProctoringRoomDAO - .deleteRoom(remoteProctoringRoom.id) - .getOrThrow(); - // Dispose the proctoring room on service side examProctoringService .disposeBreakOutRoom(proctoringSettings, remoteProctoringRoom.name) @@ -402,6 +397,11 @@ public class ExamProctoringRoomServiceImpl implements ExamProctoringRoomService proctoringSettings, remoteProctoringRoom.breakOutConnections, examProctoringService); + + // Delete room on persistent + this.remoteProctoringRoomDAO + .deleteRoom(remoteProctoringRoom.id) + .getOrThrow(); } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomProctoringService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomProctoringService.java index 333002ed..9e78afe1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomProctoringService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomProctoringService.java @@ -23,6 +23,9 @@ import javax.crypto.spec.SecretKeySpec; import javax.xml.bind.DatatypeConverter; import org.apache.commons.lang3.StringUtils; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.Interval; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Lazy; @@ -355,6 +358,7 @@ public class ZoomProctoringService implements ExamProctoringService { return createAdHocMeeting( UUID.randomUUID().toString(), "Proctoring Room " + (roomNumber + 1), + getMeetingDuration(proctoringSettings.examId), proctoringSettings); } @@ -366,9 +370,25 @@ public class ZoomProctoringService implements ExamProctoringService { return createAdHocMeeting( UUID.randomUUID().toString(), subject, + getMeetingDuration(proctoringSettings.examId), proctoringSettings); } + private int getMeetingDuration(final Long examId) { + try { + final DateTime endTime = this.examSessionService + .getRunningExam(examId) + .getOrThrow() + .getEndTime(); + final Long result = new Interval(DateTime.now(DateTimeZone.UTC), endTime) + .toDurationMillis() / Constants.MINUTE_IN_MILLIS; + return result.intValue(); + } catch (final Exception e) { + log.error("Failed to get duration for meeting from exam: {} cause: {}", examId, e.getMessage()); + return Constants.DAY_IN_MIN; + } + } + @Override public Result disposeBreakOutRoom( final ProctoringServiceSettings proctoringSettings, @@ -397,7 +417,9 @@ public class ZoomProctoringService implements ExamProctoringService { .getOrThrow(); } catch (final Exception e) { - throw new RuntimeException("Unexpected error while trying to dispose ad-hoc room for zoom proctoring"); + throw new RuntimeException( + "Unexpected error while trying to dispose ad-hoc room for zoom proctoring", + e); } }); @@ -420,6 +442,7 @@ public class ZoomProctoringService implements ExamProctoringService { private Result createAdHocMeeting( final String roomName, final String subject, + final int duration, final ProctoringServiceSettings proctoringSettings) { return Result.tryCatch(() -> { @@ -443,6 +466,7 @@ public class ZoomProctoringService implements ExamProctoringService { credentials, userResponse.id, subject, + duration, meetingPwd); final MeetingResponse meetingResponse = this.jsonMapper.readValue( createMeeting.getBody(), @@ -668,6 +692,7 @@ public class ZoomProctoringService implements ExamProctoringService { final ClientCredentials credentials, final String userId, final String topic, + final int duration, final CharSequence password) { try { @@ -678,7 +703,10 @@ public class ZoomProctoringService implements ExamProctoringService { .buildAndExpand(userId) .toUriString(); - final CreateMeetingRequest createRoomRequest = new CreateMeetingRequest(topic, password); + final CreateMeetingRequest createRoomRequest = new CreateMeetingRequest( + topic, + duration, + password); final String body = this.zoomProctoringService.jsonMapper.writeValueAsString(createRoomRequest); final HttpHeaders headers = getHeaders(credentials); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomRoomRequestResponse.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomRoomRequestResponse.java index d3cbd284..4560dbce 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomRoomRequestResponse.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ZoomRoomRequestResponse.java @@ -116,13 +116,18 @@ public interface ZoomRoomRequestResponse { @JsonProperty final int type; @JsonProperty final String start_time; @JsonProperty final String timezone; - @JsonProperty final int duration = 60; + @JsonProperty final int duration; @JsonProperty final CharSequence password; @JsonProperty final Settings settings; - public CreateMeetingRequest(final String topic, final CharSequence password) { + public CreateMeetingRequest( + final String topic, + final int duration, + final CharSequence password) { + this.type = 2; // Scheduled Meeting this.start_time = DateTime.now(DateTimeZone.UTC).toString("yyyy-MM-dd'T'HH:mm:ss"); + this.duration = duration; this.timezone = DateTimeZone.UTC.getID(); this.topic = topic; this.password = password; diff --git a/src/test/java/ch/ethz/seb/sebserver/gbl/util/ReplTest.java b/src/test/java/ch/ethz/seb/sebserver/gbl/util/ReplTest.java index c5918f0f..049c20d5 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gbl/util/ReplTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gbl/util/ReplTest.java @@ -29,4 +29,17 @@ public class ReplTest { // assertEquals("", DateTimeZone.UTC.getID()); // } +// @Test +// public void testPeriod() { +// final Period period = new Period( +// DateTime.now(DateTimeZone.UTC), +// DateTime.now(DateTimeZone.UTC).plusDays(1)); +// +// final Interval interv = new Interval( +// DateTime.now(DateTimeZone.UTC), +// DateTime.now(DateTimeZone.UTC).plusDays(1)); +// +// assertEquals(Constants.DAY_IN_MIN, interv.toDurationMillis() / Constants.MINUTE_IN_MILLIS); +// } + }