From fc398d3ff928652f2e4c8f8468ca941044a243cd Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 17 Jan 2022 11:07:01 +0100 Subject: [PATCH] SEBSERV-188 added new Active connection filter --- .../gui/content/action/ActionDefinition.java | 12 + .../monitoring/MonitoringRunningExam.java | 221 ++++++++++++------ .../session/ClientConnectionTable.java | 4 - .../impl/ClientConnectionDataInternal.java | 2 +- .../api/ExamMonitoringController.java | 34 ++- src/main/resources/messages.properties | 2 + 6 files changed, 201 insertions(+), 74 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java index 5c53a543..28d18784 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java @@ -757,6 +757,18 @@ public enum ActionDefinition { ImageIcon.TOGGLE_ON, PageStateDefinitionImpl.MONITORING_RUNNING_EXAM, ActionCategory.FILTER), + + MONITOR_EXAM_HIDE_ACTIVE_CONNECTION( + new LocTextKey("sebserver.monitoring.exam.connection.action.hide.active"), + ImageIcon.TOGGLE_OFF, + PageStateDefinitionImpl.MONITORING_RUNNING_EXAM, + ActionCategory.FILTER), + MONITOR_EXAM_SHOW_ACTIVE_CONNECTION( + new LocTextKey("sebserver.monitoring.exam.connection.action.show.active"), + ImageIcon.TOGGLE_ON, + PageStateDefinitionImpl.MONITORING_RUNNING_EXAM, + ActionCategory.FILTER), + MONITOR_EXAM_HIDE_CLOSED_CONNECTION( new LocTextKey("sebserver.monitoring.exam.connection.action.hide.closed"), ImageIcon.TOGGLE_OFF, diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/MonitoringRunningExam.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/MonitoringRunningExam.java index 8ac8a2e5..033a33f6 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/MonitoringRunningExam.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/MonitoringRunningExam.java @@ -338,93 +338,180 @@ public class MonitoringRunningExam implements TemplateComposer { final ClientConnectionTable clientTable, final BooleanSupplier isExamSupporter) { - addClosedFilterAction(actionBuilder, clientTable); - addRequestedFilterAction(actionBuilder, clientTable); - addDisabledFilterAction(actionBuilder, clientTable); + addFilterAction( + actionBuilder, + clientTable, + ConnectionStatus.CONNECTION_REQUESTED, + ActionDefinition.MONITOR_EXAM_SHOW_REQUESTED_CONNECTION, + ActionDefinition.MONITOR_EXAM_HIDE_REQUESTED_CONNECTION); + addFilterAction( + actionBuilder, + clientTable, + ConnectionStatus.ACTIVE, + ActionDefinition.MONITOR_EXAM_SHOW_ACTIVE_CONNECTION, + ActionDefinition.MONITOR_EXAM_HIDE_ACTIVE_CONNECTION); + addFilterAction( + actionBuilder, + clientTable, + ConnectionStatus.CLOSED, + ActionDefinition.MONITOR_EXAM_SHOW_CLOSED_CONNECTION, + ActionDefinition.MONITOR_EXAM_HIDE_CLOSED_CONNECTION); + addFilterAction( + actionBuilder, + clientTable, + ConnectionStatus.DISABLED, + ActionDefinition.MONITOR_EXAM_SHOW_DISABLED_CONNECTION, + ActionDefinition.MONITOR_EXAM_HIDE_DISABLED_CONNECTION); + +// addRequestedFilterAction(actionBuilder, clientTable); +// addActiveFilterAction(actionBuilder, clientTable); +// addClosedFilterAction(actionBuilder, clientTable); +// addDisabledFilterAction(actionBuilder, clientTable); } - private void addDisabledFilterAction( +// private void addRequestedFilterAction( +// final PageActionBuilder actionBuilder, +// final ClientConnectionTable clientTable) { +// +// if (clientTable.isStatusHidden(ConnectionStatus.CONNECTION_REQUESTED)) { +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_REQUESTED_CONNECTION) +// .withExec(showStateViewAction(clientTable, ConnectionStatus.CONNECTION_REQUESTED)) +// .noEventPropagation() +// .withSwitchAction( +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_REQUESTED_CONNECTION) +// .withExec( +// hideStateViewAction(clientTable, ConnectionStatus.CONNECTION_REQUESTED)) +// .noEventPropagation() +// .create()) +// .publish(); +// } else { +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_REQUESTED_CONNECTION) +// .withExec(hideStateViewAction(clientTable, ConnectionStatus.CONNECTION_REQUESTED)) +// .noEventPropagation() +// .withSwitchAction( +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_REQUESTED_CONNECTION) +// .withExec( +// showStateViewAction(clientTable, ConnectionStatus.CONNECTION_REQUESTED)) +// .noEventPropagation() +// .create()) +// .publish(); +// } +// } + + private void addFilterAction( final PageActionBuilder actionBuilder, - final ClientConnectionTable clientTable) { + final ClientConnectionTable clientTable, + final ConnectionStatus status, + final ActionDefinition showAction, + final ActionDefinition hideAction) { - if (clientTable.isStatusHidden(ConnectionStatus.DISABLED)) { - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_DISABLED_CONNECTION) - .withExec(showStateViewAction(clientTable, ConnectionStatus.DISABLED)) + if (clientTable.isStatusHidden(status)) { + actionBuilder.newAction(showAction) + .withExec(showStateViewAction(clientTable, status)) .noEventPropagation() .withSwitchAction( - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_DISABLED_CONNECTION) - .withExec(hideStateViewAction(clientTable, ConnectionStatus.DISABLED)) - .noEventPropagation() - .create()) - .publish(); - } else { - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_DISABLED_CONNECTION) - .withExec(hideStateViewAction(clientTable, ConnectionStatus.DISABLED)) - .noEventPropagation() - .withSwitchAction( - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_DISABLED_CONNECTION) - .withExec(showStateViewAction(clientTable, ConnectionStatus.DISABLED)) - .noEventPropagation() - .create()) - .publish(); - } - } - - private void addRequestedFilterAction( - final PageActionBuilder actionBuilder, - final ClientConnectionTable clientTable) { - - if (clientTable.isStatusHidden(ConnectionStatus.CONNECTION_REQUESTED)) { - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_REQUESTED_CONNECTION) - .withExec(showStateViewAction(clientTable, ConnectionStatus.CONNECTION_REQUESTED)) - .noEventPropagation() - .withSwitchAction( - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_REQUESTED_CONNECTION) + actionBuilder.newAction(hideAction) .withExec( - hideStateViewAction(clientTable, ConnectionStatus.CONNECTION_REQUESTED)) + hideStateViewAction(clientTable, status)) .noEventPropagation() .create()) .publish(); } else { - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_REQUESTED_CONNECTION) - .withExec(hideStateViewAction(clientTable, ConnectionStatus.CONNECTION_REQUESTED)) + actionBuilder.newAction(hideAction) + .withExec(hideStateViewAction(clientTable, status)) .noEventPropagation() .withSwitchAction( - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_REQUESTED_CONNECTION) + actionBuilder.newAction(showAction) .withExec( - showStateViewAction(clientTable, ConnectionStatus.CONNECTION_REQUESTED)) + showStateViewAction(clientTable, status)) .noEventPropagation() .create()) .publish(); } } - private void addClosedFilterAction( - final PageActionBuilder actionBuilder, - final ClientConnectionTable clientTable) { - - if (clientTable.isStatusHidden(ConnectionStatus.CLOSED)) { - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_CLOSED_CONNECTION) - .withExec(showStateViewAction(clientTable, ConnectionStatus.CLOSED)) - .noEventPropagation() - .withSwitchAction( - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_CLOSED_CONNECTION) - .withExec(hideStateViewAction(clientTable, ConnectionStatus.CLOSED)) - .noEventPropagation() - .create()) - .publish(); - } else { - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_CLOSED_CONNECTION) - .withExec(hideStateViewAction(clientTable, ConnectionStatus.CLOSED)) - .noEventPropagation() - .withSwitchAction( - actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_CLOSED_CONNECTION) - .withExec(showStateViewAction(clientTable, ConnectionStatus.CLOSED)) - .noEventPropagation() - .create()) - .publish(); - } - } +// private void addActiveFilterAction( +// final PageActionBuilder actionBuilder, +// final ClientConnectionTable clientTable) { +// +// if (clientTable.isStatusHidden(ConnectionStatus.ACTIVE)) { +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_ACTIVE_CONNECTION) +// .withExec(showStateViewAction(clientTable, ConnectionStatus.ACTIVE)) +// .noEventPropagation() +// .withSwitchAction( +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_ACTIVE_CONNECTION) +// .withExec( +// hideStateViewAction(clientTable, ConnectionStatus.ACTIVE)) +// .noEventPropagation() +// .create()) +// .publish(); +// } else { +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_ACTIVE_CONNECTION) +// .withExec(hideStateViewAction(clientTable, ConnectionStatus.ACTIVE)) +// .noEventPropagation() +// .withSwitchAction( +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_ACTIVE_CONNECTION) +// .withExec( +// showStateViewAction(clientTable, ConnectionStatus.ACTIVE)) +// .noEventPropagation() +// .create()) +// .publish(); +// } +// } +// +// private void addDisabledFilterAction( +// final PageActionBuilder actionBuilder, +// final ClientConnectionTable clientTable) { +// +// if (clientTable.isStatusHidden(ConnectionStatus.DISABLED)) { +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_DISABLED_CONNECTION) +// .withExec(showStateViewAction(clientTable, ConnectionStatus.DISABLED)) +// .noEventPropagation() +// .withSwitchAction( +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_DISABLED_CONNECTION) +// .withExec(hideStateViewAction(clientTable, ConnectionStatus.DISABLED)) +// .noEventPropagation() +// .create()) +// .publish(); +// } else { +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_DISABLED_CONNECTION) +// .withExec(hideStateViewAction(clientTable, ConnectionStatus.DISABLED)) +// .noEventPropagation() +// .withSwitchAction( +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_DISABLED_CONNECTION) +// .withExec(showStateViewAction(clientTable, ConnectionStatus.DISABLED)) +// .noEventPropagation() +// .create()) +// .publish(); +// } +// } +// +// private void addClosedFilterAction( +// final PageActionBuilder actionBuilder, +// final ClientConnectionTable clientTable) { +// +// if (clientTable.isStatusHidden(ConnectionStatus.CLOSED)) { +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_CLOSED_CONNECTION) +// .withExec(showStateViewAction(clientTable, ConnectionStatus.CLOSED)) +// .noEventPropagation() +// .withSwitchAction( +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_CLOSED_CONNECTION) +// .withExec(hideStateViewAction(clientTable, ConnectionStatus.CLOSED)) +// .noEventPropagation() +// .create()) +// .publish(); +// } else { +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_HIDE_CLOSED_CONNECTION) +// .withExec(hideStateViewAction(clientTable, ConnectionStatus.CLOSED)) +// .noEventPropagation() +// .withSwitchAction( +// actionBuilder.newAction(ActionDefinition.MONITOR_EXAM_SHOW_CLOSED_CONNECTION) +// .withExec(showStateViewAction(clientTable, ConnectionStatus.CLOSED)) +// .noEventPropagation() +// .create()) +// .publish(); +// } +// } private PageAction openSearchPopup(final PageAction action) { this.monitoringExamSearchPopup.show(action.pageContext()); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java index b8d80f38..5ea3c348 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java @@ -524,10 +524,6 @@ public final class ClientConnectionTable { } private void update(final TableItem tableItem) { - if (ClientConnectionTable.this.statusFilter.contains(this.connectionData.clientConnection.status)) { - tableItem.dispose(); - return; - } updateData(tableItem); if (this.connectionData != null) { updateConnectionStatusColor(tableItem); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ClientConnectionDataInternal.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ClientConnectionDataInternal.java index ab1b42d2..2d239ee8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ClientConnectionDataInternal.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ClientConnectionDataInternal.java @@ -88,7 +88,7 @@ public class ClientConnectionDataInternal extends ClientConnectionData { @Override @JsonIgnore public final boolean hasAnyIncident() { - return pendingNotification() || hasIncident(); + return getMissingPing() || pendingNotification() || hasIncident(); } private boolean hasIncident() { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamMonitoringController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamMonitoringController.java index bfd32c94..3f92d2fa 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamMonitoringController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamMonitoringController.java @@ -12,6 +12,7 @@ import java.util.Collection; import java.util.EnumSet; import java.util.Objects; import java.util.concurrent.Executor; +import java.util.function.Predicate; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; @@ -180,19 +181,48 @@ public class ExamMonitoringController { if (StringUtils.isNoneBlank(hiddenStates)) { final String[] split = StringUtils.split(hiddenStates, Constants.LIST_SEPARATOR); for (int i = 0; i < split.length; i++) { - filterStates.add(ConnectionStatus.valueOf(split[0])); + filterStates.add(ConnectionStatus.valueOf(split[i])); } } + final boolean active = filterStates.contains(ConnectionStatus.ACTIVE); + if (active) { + filterStates.remove(ConnectionStatus.ACTIVE); + } + return this.examSessionService .getConnectionData( examId, filterStates.isEmpty() ? Objects::nonNull - : conn -> conn != null && !filterStates.contains(conn.clientConnection.status)) + : active + ? withActiveFilter(filterStates) + : noneActiveFilter(filterStates)) .getOrThrow(); } + private Predicate noneActiveFilter(final EnumSet filterStates) { + return conn -> conn != null && !filterStates.contains(conn.clientConnection.status); + } + + /** If we have a filter criteria for ACTIVE connection, we shall filter only the active connections + * that has no incident. */ + private Predicate withActiveFilter(final EnumSet filterStates) { + return conn -> { + if (conn == null) { + return false; + } else if (conn.clientConnection.status == ConnectionStatus.ACTIVE) { + return conn.hasAnyIncident(); + } else { + return !filterStates.contains(conn.clientConnection.status); + } + }; +// return conn -> conn != null +// && ((conn.clientConnection.status == ConnectionStatus.ACTIVE && !conn.hasAnyIncident()) || +// (conn.clientConnection.status != ConnectionStatus.ACTIVE +// && !filterStates.contains(conn.clientConnection.status))); + } + @RequestMapping( path = API.PARENT_MODEL_ID_VAR_PATH_SEGMENT + API.EXAM_MONITORING_SEB_CONNECTION_TOKEN_PATH_SEGMENT, diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 8e36a803..21272aa9 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -1799,6 +1799,8 @@ sebserver.monitoring.exam.connection.action.instruction.disable.all.confirm=Are sebserver.monitoring.exam.connection.action.disable=Mark As Canceled sebserver.monitoring.exam.connection.action.hide.requested=Hide Requested sebserver.monitoring.exam.connection.action.show.requested=Show Requested +sebserver.monitoring.exam.connection.action.hide.active=Hide Active +sebserver.monitoring.exam.connection.action.show.active=Show Active sebserver.monitoring.exam.connection.action.hide.closed=Hide Closed sebserver.monitoring.exam.connection.action.show.closed=Show Closed sebserver.monitoring.exam.connection.action.hide.disabled=Hide Canceled