SEBSERV-478 review and optimizations

This commit is contained in:
anhefti 2024-01-31 09:35:08 +01:00
parent a43042ce2f
commit 7ddbb218e6
4 changed files with 30 additions and 42 deletions

View file

@ -493,14 +493,21 @@ public class MonitoringRunningExam implements TemplateComposer {
final ActionDefinition showActionDef, final ActionDefinition showActionDef,
final ActionDefinition hideActionDef) { final ActionDefinition hideActionDef) {
final int numOfConnections = filter.getNumOfConnections(connectionIssueStatus); final int numOfConnections = filter.getNumOfConnections(connectionIssueStatus);
final PageAction action = actionBuilder.newAction(hideActionDef) final PageAction action = actionBuilder.newAction(filter.isIssueHidden(connectionIssueStatus)
.withExec(hideIssueViewAction(filter, clientTable, connectionIssueStatus)) ? showActionDef
: hideActionDef)
.withExec(filter.isIssueHidden(connectionIssueStatus)
? showIssueViewAction(filter, clientTable, connectionIssueStatus)
: hideIssueViewAction(filter, clientTable, connectionIssueStatus))
.noEventPropagation() .noEventPropagation()
.withSwitchAction( .withSwitchAction(
actionBuilder.newAction(showActionDef) actionBuilder.newAction(filter.isIssueHidden(connectionIssueStatus)
.withExec(showIssueViewAction(filter, clientTable, connectionIssueStatus)) ? hideActionDef
: showActionDef)
.withExec(filter.isIssueHidden(connectionIssueStatus)
? hideIssueViewAction(filter, clientTable, connectionIssueStatus)
: showIssueViewAction(filter, clientTable, connectionIssueStatus))
.noEventPropagation() .noEventPropagation()
.withNameAttributes(numOfConnections) .withNameAttributes(numOfConnections)
.create()) .create())

View file

@ -206,6 +206,11 @@ public class FullPageMonitoringUpdate implements MonitoringFilter {
saveFilter(); saveFilter();
} }
@Override
public boolean isIssueHidden(final ConnectionIssueStatus connectionIssueStatus) {
return this.issueFilter.contains(connectionIssueStatus);
}
@Override @Override
public void hideIssue(final ConnectionIssueStatus connectionIssueStatus) { public void hideIssue(final ConnectionIssueStatus connectionIssueStatus) {
this.issueFilter.add(connectionIssueStatus); this.issueFilter.add(connectionIssueStatus);
@ -359,7 +364,7 @@ public class FullPageMonitoringUpdate implements MonitoringFilter {
} }
} catch (final Exception e) { } 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(); this.issueFilter.clear();
} finally { } finally {
this.issueFilterParam = StringUtils.join(this.issueFilter, Constants.LIST_SEPARATOR); this.issueFilterParam = StringUtils.join(this.issueFilter, Constants.LIST_SEPARATOR);

View file

@ -53,6 +53,8 @@ public interface MonitoringFilter {
void showClientGroup(Long clientGroupId); void showClientGroup(Long clientGroupId);
boolean isIssueHidden(ConnectionIssueStatus connectionIssueStatus);
void hideIssue(ConnectionIssueStatus connectionIssueStatus); void hideIssue(ConnectionIssueStatus connectionIssueStatus);
void showIssue(ConnectionIssueStatus connectionIssueStatus); void showIssue(ConnectionIssueStatus connectionIssueStatus);

View file

@ -547,17 +547,11 @@ public class ExamMonitoringController {
} }
private Predicate<ClientConnectionData> activeIssueFilterSebVersion(final EnumSet<ConnectionIssueStatus> filterStates) { private Predicate<ClientConnectionData> activeIssueFilterSebVersion(final EnumSet<ConnectionIssueStatus> filterStates) {
if(!filterStates.contains(ConnectionIssueStatus.SEB_VERSION_GRANTED)){ return conn -> BooleanUtils.isFalse(conn.clientConnection.clientVersionGranted);
return null;
}
return conn -> conn != null && BooleanUtils.isFalse(conn.clientConnection.clientVersionGranted);
} }
private Predicate<ClientConnectionData> activeIssueFilterAsk(final EnumSet<ConnectionIssueStatus> filterStates) { private Predicate<ClientConnectionData> activeIssueFilterAsk(final EnumSet<ConnectionIssueStatus> filterStates) {
if(!filterStates.contains(ConnectionIssueStatus.ASK_GRANTED)){ return conn -> BooleanUtils.isFalse(conn.clientConnection.securityCheckGranted);
return null;
}
return conn -> conn != null && BooleanUtils.isFalse(conn.clientConnection.securityCheckGranted);
} }
/** If we have a filter criteria for ACTIVE connection, we shall filter only the active connections /** 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); filterStates.remove(ConnectionStatus.ACTIVE);
} }
final Predicate<ClientConnectionData> stateFilter = filterStates.isEmpty() Predicate<ClientConnectionData> filter = filterStates.isEmpty()
? Objects::nonNull ? Objects::nonNull
: active : active
? withActiveFilter(filterStates) ? withActiveFilter(filterStates)
@ -606,16 +600,12 @@ public class ExamMonitoringController {
} }
} }
final Predicate<ClientConnectionData> issueFilterSebVersion = if (filterIssues.contains(ConnectionIssueStatus.SEB_VERSION_GRANTED)) {
filterIssues.isEmpty() filter = filter.and(activeIssueFilterSebVersion(filterIssues));
? null }
: activeIssueFilterSebVersion(filterIssues); if (filterIssues.contains(ConnectionIssueStatus.ASK_GRANTED)) {
filter = filter.and(activeIssueFilterAsk(filterIssues));
final Predicate<ClientConnectionData> issueFilterAsk = }
filterIssues.isEmpty()
? null
: activeIssueFilterAsk(filterIssues);
Set<Long> filterClientGroups = null; Set<Long> filterClientGroups = null;
if (StringUtils.isNotBlank(hiddenClientGroups)) { if (StringUtils.isNotBlank(hiddenClientGroups)) {
@ -627,23 +617,7 @@ public class ExamMonitoringController {
} }
final Set<Long> _filterClientGroups = filterClientGroups; final Set<Long> _filterClientGroups = filterClientGroups;
return ccd -> { return filter.and(ccd -> ccd.filter(_filterClientGroups));
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;
};
} }
} }