SEBSERV-148 test and fixes

This commit is contained in:
anhefti 2021-04-08 15:44:05 +02:00
parent 7fae3f4baf
commit 449f7d5824
5 changed files with 57 additions and 9 deletions

View file

@ -40,6 +40,8 @@ public final class Constants {
public static final long HOUR_IN_MILLIS = 60 * MINUTE_IN_MILLIS; 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 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 CARRIAGE_RETURN = '\n';
public static final Character CURLY_BRACE_OPEN = '{'; public static final Character CURLY_BRACE_OPEN = '{';
public static final Character CURLY_BRACE_CLOSE = '}'; public static final Character CURLY_BRACE_CLOSE = '}';

View file

@ -387,11 +387,6 @@ public class ExamProctoringRoomServiceImpl implements ExamProctoringRoomService
remoteProctoringRoom.breakOutConnections, remoteProctoringRoom.breakOutConnections,
examProctoringService.getDefaultInstructionAttributes()); examProctoringService.getDefaultInstructionAttributes());
// Delete room on persistent
this.remoteProctoringRoomDAO
.deleteRoom(remoteProctoringRoom.id)
.getOrThrow();
// Dispose the proctoring room on service side // Dispose the proctoring room on service side
examProctoringService examProctoringService
.disposeBreakOutRoom(proctoringSettings, remoteProctoringRoom.name) .disposeBreakOutRoom(proctoringSettings, remoteProctoringRoom.name)
@ -402,6 +397,11 @@ public class ExamProctoringRoomServiceImpl implements ExamProctoringRoomService
proctoringSettings, proctoringSettings,
remoteProctoringRoom.breakOutConnections, remoteProctoringRoom.breakOutConnections,
examProctoringService); examProctoringService);
// Delete room on persistent
this.remoteProctoringRoomDAO
.deleteRoom(remoteProctoringRoom.id)
.getOrThrow();
} }
@Override @Override

View file

@ -23,6 +23,9 @@ import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter; import javax.xml.bind.DatatypeConverter;
import org.apache.commons.lang3.StringUtils; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -355,6 +358,7 @@ public class ZoomProctoringService implements ExamProctoringService {
return createAdHocMeeting( return createAdHocMeeting(
UUID.randomUUID().toString(), UUID.randomUUID().toString(),
"Proctoring Room " + (roomNumber + 1), "Proctoring Room " + (roomNumber + 1),
getMeetingDuration(proctoringSettings.examId),
proctoringSettings); proctoringSettings);
} }
@ -366,9 +370,25 @@ public class ZoomProctoringService implements ExamProctoringService {
return createAdHocMeeting( return createAdHocMeeting(
UUID.randomUUID().toString(), UUID.randomUUID().toString(),
subject, subject,
getMeetingDuration(proctoringSettings.examId),
proctoringSettings); 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 @Override
public Result<Void> disposeBreakOutRoom( public Result<Void> disposeBreakOutRoom(
final ProctoringServiceSettings proctoringSettings, final ProctoringServiceSettings proctoringSettings,
@ -397,7 +417,9 @@ public class ZoomProctoringService implements ExamProctoringService {
.getOrThrow(); .getOrThrow();
} catch (final Exception e) { } 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<NewRoom> createAdHocMeeting( private Result<NewRoom> createAdHocMeeting(
final String roomName, final String roomName,
final String subject, final String subject,
final int duration,
final ProctoringServiceSettings proctoringSettings) { final ProctoringServiceSettings proctoringSettings) {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
@ -443,6 +466,7 @@ public class ZoomProctoringService implements ExamProctoringService {
credentials, credentials,
userResponse.id, userResponse.id,
subject, subject,
duration,
meetingPwd); meetingPwd);
final MeetingResponse meetingResponse = this.jsonMapper.readValue( final MeetingResponse meetingResponse = this.jsonMapper.readValue(
createMeeting.getBody(), createMeeting.getBody(),
@ -668,6 +692,7 @@ public class ZoomProctoringService implements ExamProctoringService {
final ClientCredentials credentials, final ClientCredentials credentials,
final String userId, final String userId,
final String topic, final String topic,
final int duration,
final CharSequence password) { final CharSequence password) {
try { try {
@ -678,7 +703,10 @@ public class ZoomProctoringService implements ExamProctoringService {
.buildAndExpand(userId) .buildAndExpand(userId)
.toUriString(); .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 String body = this.zoomProctoringService.jsonMapper.writeValueAsString(createRoomRequest);
final HttpHeaders headers = getHeaders(credentials); final HttpHeaders headers = getHeaders(credentials);

View file

@ -116,13 +116,18 @@ public interface ZoomRoomRequestResponse {
@JsonProperty final int type; @JsonProperty final int type;
@JsonProperty final String start_time; @JsonProperty final String start_time;
@JsonProperty final String timezone; @JsonProperty final String timezone;
@JsonProperty final int duration = 60; @JsonProperty final int duration;
@JsonProperty final CharSequence password; @JsonProperty final CharSequence password;
@JsonProperty final Settings settings; @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.type = 2; // Scheduled Meeting
this.start_time = DateTime.now(DateTimeZone.UTC).toString("yyyy-MM-dd'T'HH:mm:ss"); this.start_time = DateTime.now(DateTimeZone.UTC).toString("yyyy-MM-dd'T'HH:mm:ss");
this.duration = duration;
this.timezone = DateTimeZone.UTC.getID(); this.timezone = DateTimeZone.UTC.getID();
this.topic = topic; this.topic = topic;
this.password = password; this.password = password;

View file

@ -29,4 +29,17 @@ public class ReplTest {
// assertEquals("", DateTimeZone.UTC.getID()); // 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);
// }
} }