fixed some issues with proctoring rooms and error handling

This commit is contained in:
anhefti 2020-11-18 16:05:52 +01:00
parent 3b1641994a
commit 696a85a1fe
4 changed files with 99 additions and 50 deletions

View file

@ -47,6 +47,7 @@ import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.PageContext;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer;
import ch.ethz.seb.sebserver.gui.service.page.event.ActionActivationEvent;
import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction;
import ch.ethz.seb.sebserver.gui.service.push.ServerPushContext;
import ch.ethz.seb.sebserver.gui.service.push.ServerPushService;
@ -75,16 +76,16 @@ public class MonitoringClientConnection implements TemplateComposer {
private static final Logger log = LoggerFactory.getLogger(MonitoringClientConnection.class);
// @formatter:off
private static final String OPEN_SINGEL_ROOM_SCRIPT =
"var existingWin = window.open('', '%s', 'height=420,width=640,location=no,scrollbars=yes,status=no,menubar=yes,toolbar=yes,titlebar=yes,dialog=yes');\n" +
"if(existingWin.location.href === 'about:blank'){\n" +
" existingWin.location.href = '%s%s';\n" +
" existingWin.focus();\n" +
"} else {\n" +
" existingWin.focus();\n" +
"}";
// @formatter:on
// // @formatter:off
// private static final String OPEN_SINGEL_ROOM_SCRIPT =
// "var existingWin = window.open('', '%s', 'height=420,width=640,location=no,scrollbars=yes,status=no,menubar=yes,toolbar=yes,titlebar=yes,dialog=yes');\n" +
// "if(existingWin.location.href === 'about:blank'){\n" +
// " existingWin.location.href = '%s%s';\n" +
// " existingWin.focus();\n" +
// "} else {\n" +
// " existingWin.focus();\n" +
// "}";
// // @formatter:on
private static final LocTextKey PAGE_TITLE_KEY =
new LocTextKey("sebserver.monitoring.exam.connection.title");
@ -289,8 +290,7 @@ public class MonitoringClientConnection implements TemplateComposer {
.publishIf(() -> currentUser.get().hasRole(UserRole.EXAM_SUPPORTER) &&
connectionData.clientConnection.status == ConnectionStatus.ACTIVE);
// TODO if (connectionData.clientConnection.status == ConnectionStatus.ACTIVE) {
if (connectionData.clientConnection.status != ConnectionStatus.DISABLED) {
if (connectionData.clientConnection.status == ConnectionStatus.ACTIVE) {
final ProctoringSettings procotringSettings = restService
.getBuilder(GetProctoringSettings.class)
.withURIVariable(API.PARAM_MODEL_ID, parentEntityKey.modelId)
@ -311,6 +311,16 @@ public class MonitoringClientConnection implements TemplateComposer {
.withExec(action -> this.openExamCollectionProctorScreen(action, connectionData))
.noEventPropagation()
.publish();
clientConnectionDetails.setStatusChangeListener(ccd -> {
this.pageService.firePageEvent(
new ActionActivationEvent(
ccd.clientConnection.status == ConnectionStatus.ACTIVE,
ActionDefinition.MONITOR_EXAM_CLIENT_CONNECTION_QUIT,
ActionDefinition.MONITOR_EXAM_CLIENT_CONNECTION_PROCTORING,
ActionDefinition.MONITOR_EXAM_CLIENT_CONNECTION_EXAM_ROOM_PROCTORING),
pageContext);
});
}
}
}
@ -349,8 +359,10 @@ public class MonitoringClientConnection implements TemplateComposer {
ProctoringGUIService.setCurrentProctoringWindowData(examId, proctoringConnectionData);
final String script = String.format(
MonitoringRunningExam.OPEN_EXAM_COLLECTION_ROOM_SCRIPT,
MonitoringRunningExam.OPEN_ROOM_SCRIPT,
room.name,
800,
1200,
this.guiServiceInfo.getExternalServerURIBuilder().toUriString(),
this.remoteProctoringEndpoint);
@ -396,8 +408,10 @@ public class MonitoringClientConnection implements TemplateComposer {
final JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
final String script = String.format(
OPEN_SINGEL_ROOM_SCRIPT,
MonitoringRunningExam.OPEN_ROOM_SCRIPT,
roomName,
420,
640,
this.guiServiceInfo.getExternalServerURIBuilder().toUriString(),
this.remoteProctoringEndpoint);
javaScriptExecutor.execute(script);

View file

@ -91,13 +91,18 @@ public class MonitoringRunningExam implements TemplateComposer {
private static final Logger log = LoggerFactory.getLogger(MonitoringRunningExam.class);
// @formatter:off
static final String OPEN_EXAM_COLLECTION_ROOM_SCRIPT =
"var existingWin = window.open('', '%s', 'height=800,width=1200,location=no,scrollbars=yes,status=no,menubar=yes,toolbar=yes,titlebar=yes,dialog=yes');\n" +
static final String OPEN_ROOM_SCRIPT =
"try {\n" +
"var existingWin = window.open('', '%s', 'height=%s,width=%s,location=no,scrollbars=yes,status=no,menubar=0,toolbar=no,titlebar=no,dialog=no');\n" +
"if(existingWin.location.href === 'about:blank'){\n" +
" existingWin.location.href = '%s%s';\n" +
" existingWin.focus();\n" +
"} else {\n" +
" existingWin.focus();\n" +
"}" +
"}\n" +
"catch(err) {\n" +
" alert(\"Unexpected Javascript Error happened: \" + err);\n"+
"}";
// @formatter:on
@ -411,55 +416,71 @@ public class MonitoringRunningExam implements TemplateComposer {
}
private PageAction openTownhallRoom(final PageAction action) {
final EntityKey examId = action.getEntityKey();
try {
final EntityKey examId = action.getEntityKey();
final ProctoringGUIService proctoringGUIService = this.pageService
.getCurrentUser()
.getProctoringGUIService();
final ProctoringGUIService proctoringGUIService = this.pageService
.getCurrentUser()
.getProctoringGUIService();
String activeAllRoomName = proctoringGUIService.getTownhallRoom(examId.modelId);
String activeAllRoomName = proctoringGUIService.getTownhallRoom(examId.modelId);
if (activeAllRoomName == null) {
final SEBProctoringConnectionData proctoringConnectionData = proctoringGUIService
.registerTownhallRoom(
examId.modelId,
this.pageService.getI18nSupport().getText(EXAM_ROOM_NAME))
.onError(error -> log.error(
"Failed to open all collecting room for exam {} {}", examId.modelId, error.getMessage()))
.getOrThrow();
ProctoringGUIService.setCurrentProctoringWindowData(
examId.modelId,
proctoringConnectionData);
activeAllRoomName = proctoringConnectionData.roomName;
if (activeAllRoomName == null) {
final SEBProctoringConnectionData proctoringConnectionData = proctoringGUIService
.registerTownhallRoom(
examId.modelId,
this.pageService.getI18nSupport().getText(EXAM_ROOM_NAME))
.onError(error -> log.error(
"Failed to open all collecting room for exam {} {}", examId.modelId,
error.getMessage()))
.getOrThrow();
ProctoringGUIService.setCurrentProctoringWindowData(
examId.modelId,
proctoringConnectionData);
activeAllRoomName = proctoringConnectionData.roomName;
}
final JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
final String script = String.format(
OPEN_ROOM_SCRIPT,
activeAllRoomName,
800,
1200,
this.guiServiceInfo.getExternalServerURIBuilder().toUriString(),
this.remoteProctoringEndpoint);
javaScriptExecutor.execute(script);
proctoringGUIService.registerProctoringWindow(activeAllRoomName);
} catch (final Exception e) {
log.error("Failed to open popup for townhall room: ", e);
}
final JavaScriptExecutor javaScriptExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
final String script = String.format(
OPEN_EXAM_COLLECTION_ROOM_SCRIPT,
activeAllRoomName,
this.guiServiceInfo.getExternalServerURIBuilder().toUriString(),
this.remoteProctoringEndpoint);
javaScriptExecutor.execute(script);
proctoringGUIService.registerProctoringWindow(activeAllRoomName);
return action;
}
private PageAction closeTownhallRoom(final PageAction action) {
final String examId = action.getEntityKey().modelId;
final RemoteProctoringRoom townhall = this.pageService.getRestService()
.getBuilder(GetTownhallRoom.class)
.withURIVariable(API.PARAM_MODEL_ID, action.getEntityKey().modelId)
.withURIVariable(API.PARAM_MODEL_ID, examId)
.call()
.getOr(null);
if (townhall == null || townhall.id == null) {
log.warn(
"Close townhall action cannot get active townhall form webservice for exam: {}",
examId);
return action;
}
final ProctoringGUIService proctoringGUIService = this.pageService
.getCurrentUser()
.getProctoringGUIService();
try {
final ProctoringGUIService proctoringGUIService = this.pageService
.getCurrentUser()
.getProctoringGUIService();
proctoringGUIService.closeRoom(townhall.name);
proctoringGUIService.closeRoom(townhall.name);
} catch (final Exception e) {
log.error("Failed to close procotring townhall room for exam: {}", examId);
}
return action;
}
@ -616,8 +637,10 @@ public class MonitoringRunningExam implements TemplateComposer {
proctoringConnectionData);
final String script = String.format(
OPEN_EXAM_COLLECTION_ROOM_SCRIPT,
OPEN_ROOM_SCRIPT,
room.name,
800,
1200,
this.guiServiceInfo.getExternalServerURIBuilder().toUriString(),
this.remoteProctoringEndpoint);

View file

@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gui.service.session;
import java.util.Collection;
import java.util.EnumMap;
import java.util.function.Consumer;
import org.apache.commons.lang3.BooleanUtils;
import org.eclipse.swt.graphics.Color;
@ -58,6 +59,7 @@ public class ClientConnectionDetails {
private ClientConnectionData connectionData = null;
private boolean statusChanged = true;
private Consumer<ClientConnectionData> statusChangeListener = null;
public ClientConnectionDetails(
final PageService pageService,
@ -112,6 +114,10 @@ public class ClientConnectionDetails {
this.formHandle = formBuilder.build();
}
public void setStatusChangeListener(final Consumer<ClientConnectionData> statusChangeListener) {
this.statusChangeListener = statusChangeListener;
}
public void updateData() {
final ClientConnectionData connectionData = this.restCallBuilder
.call()
@ -123,8 +129,8 @@ public class ClientConnectionDetails {
if (this.connectionData != null && connectionData != null) {
this.statusChanged =
this.connectionData.clientConnection.status != connectionData.clientConnection.status ||
BooleanUtils.toBoolean(this.connectionData.missingPing) !=
BooleanUtils.toBoolean(connectionData.missingPing);
BooleanUtils.toBoolean(this.connectionData.missingPing) != BooleanUtils
.toBoolean(connectionData.missingPing);
}
this.connectionData = connectionData;
}
@ -152,6 +158,10 @@ public class ClientConnectionDetails {
final Color statusTextColor = this.colorData.getStatusTextColor(statusColor);
form.setFieldColor(Domain.CLIENT_CONNECTION.ATTR_STATUS, statusColor);
form.setFieldTextColor(Domain.CLIENT_CONNECTION.ATTR_STATUS, statusTextColor);
if (this.statusChangeListener != null) {
this.statusChangeListener.accept(this.connectionData);
}
}
// update indicators

View file

@ -228,6 +228,8 @@ public class ProctoringGUIService {
name,
error.getMessage()));
}
} else {
log.warn("No proctoring room with name: {} found for closing.", name);
}
}