From 7ddbb218e6928856f46495a2024545be3b8487c3 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 31 Jan 2024 09:35:08 +0100 Subject: [PATCH] SEBSERV-478 review and optimizations --- .../monitoring/MonitoringRunningExam.java | 17 +++++-- .../session/FullPageMonitoringUpdate.java | 7 ++- .../gui/service/session/MonitoringFilter.java | 2 + .../api/ExamMonitoringController.java | 46 ++++--------------- 4 files changed, 30 insertions(+), 42 deletions(-) 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 33f0e577..0b37f670 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 @@ -493,14 +493,21 @@ public class MonitoringRunningExam implements TemplateComposer { final ActionDefinition showActionDef, final ActionDefinition hideActionDef) { - final int numOfConnections = filter.getNumOfConnections(connectionIssueStatus); - final PageAction action = actionBuilder.newAction(hideActionDef) - .withExec(hideIssueViewAction(filter, clientTable, connectionIssueStatus)) + final PageAction action = actionBuilder.newAction(filter.isIssueHidden(connectionIssueStatus) + ? showActionDef + : hideActionDef) + .withExec(filter.isIssueHidden(connectionIssueStatus) + ? showIssueViewAction(filter, clientTable, connectionIssueStatus) + : hideIssueViewAction(filter, clientTable, connectionIssueStatus)) .noEventPropagation() .withSwitchAction( - actionBuilder.newAction(showActionDef) - .withExec(showIssueViewAction(filter, clientTable, connectionIssueStatus)) + actionBuilder.newAction(filter.isIssueHidden(connectionIssueStatus) + ? hideActionDef + : showActionDef) + .withExec(filter.isIssueHidden(connectionIssueStatus) + ? hideIssueViewAction(filter, clientTable, connectionIssueStatus) + : showIssueViewAction(filter, clientTable, connectionIssueStatus)) .noEventPropagation() .withNameAttributes(numOfConnections) .create()) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/FullPageMonitoringUpdate.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/FullPageMonitoringUpdate.java index 491d9801..e5833408 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/FullPageMonitoringUpdate.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/FullPageMonitoringUpdate.java @@ -206,6 +206,11 @@ public class FullPageMonitoringUpdate implements MonitoringFilter { saveFilter(); } + @Override + public boolean isIssueHidden(final ConnectionIssueStatus connectionIssueStatus) { + return this.issueFilter.contains(connectionIssueStatus); + } + @Override public void hideIssue(final ConnectionIssueStatus connectionIssueStatus) { this.issueFilter.add(connectionIssueStatus); @@ -359,7 +364,7 @@ public class FullPageMonitoringUpdate implements MonitoringFilter { } } catch (final Exception e) { - log.warn("Failed to load status filter to user session"); + log.warn("Failed to load issue filter to user session"); this.issueFilter.clear(); } finally { this.issueFilterParam = StringUtils.join(this.issueFilter, Constants.LIST_SEPARATOR); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/MonitoringFilter.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/MonitoringFilter.java index c36fd9f4..b908ba18 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/MonitoringFilter.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/MonitoringFilter.java @@ -53,6 +53,8 @@ public interface MonitoringFilter { void showClientGroup(Long clientGroupId); + boolean isIssueHidden(ConnectionIssueStatus connectionIssueStatus); + void hideIssue(ConnectionIssueStatus connectionIssueStatus); void showIssue(ConnectionIssueStatus connectionIssueStatus); 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 a839a8a5..496dc141 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 @@ -547,17 +547,11 @@ public class ExamMonitoringController { } private Predicate activeIssueFilterSebVersion(final EnumSet filterStates) { - if(!filterStates.contains(ConnectionIssueStatus.SEB_VERSION_GRANTED)){ - return null; - } - return conn -> conn != null && BooleanUtils.isFalse(conn.clientConnection.clientVersionGranted); + return conn -> BooleanUtils.isFalse(conn.clientConnection.clientVersionGranted); } private Predicate activeIssueFilterAsk(final EnumSet filterStates) { - if(!filterStates.contains(ConnectionIssueStatus.ASK_GRANTED)){ - return null; - } - return conn -> conn != null && BooleanUtils.isFalse(conn.clientConnection.securityCheckGranted); + return conn -> BooleanUtils.isFalse(conn.clientConnection.securityCheckGranted); } /** If we have a filter criteria for ACTIVE connection, we shall filter only the active connections @@ -592,7 +586,7 @@ public class ExamMonitoringController { filterStates.remove(ConnectionStatus.ACTIVE); } - final Predicate stateFilter = filterStates.isEmpty() + Predicate filter = filterStates.isEmpty() ? Objects::nonNull : active ? withActiveFilter(filterStates) @@ -606,16 +600,12 @@ public class ExamMonitoringController { } } - final Predicate issueFilterSebVersion = - filterIssues.isEmpty() - ? null - : activeIssueFilterSebVersion(filterIssues); - - final Predicate issueFilterAsk = - filterIssues.isEmpty() - ? null - : activeIssueFilterAsk(filterIssues); - + if (filterIssues.contains(ConnectionIssueStatus.SEB_VERSION_GRANTED)) { + filter = filter.and(activeIssueFilterSebVersion(filterIssues)); + } + if (filterIssues.contains(ConnectionIssueStatus.ASK_GRANTED)) { + filter = filter.and(activeIssueFilterAsk(filterIssues)); + } Set filterClientGroups = null; if (StringUtils.isNotBlank(hiddenClientGroups)) { @@ -627,23 +617,7 @@ public class ExamMonitoringController { } final Set _filterClientGroups = filterClientGroups; - return ccd -> { - if (ccd == null) { - return false; - } - - boolean result = stateFilter.test(ccd) && ccd.filter(_filterClientGroups); - - if (issueFilterSebVersion != null) { - result = result && issueFilterSebVersion.test(ccd); - } - - if (issueFilterAsk != null) { - result = result && issueFilterAsk.test(ccd); - } - - return result; - }; + return filter.and(ccd -> ccd.filter(_filterClientGroups)); } }