patch fixes monitoring sorting and zoom token refresh

This commit is contained in:
anhefti 2023-05-09 14:13:09 +02:00
parent 56ad74dc25
commit a896737f5b
3 changed files with 58 additions and 25 deletions

View file

@ -15,6 +15,7 @@ import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
@ -69,8 +70,6 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
private static final Logger log = LoggerFactory.getLogger(ClientConnectionTable.class); private static final Logger log = LoggerFactory.getLogger(ClientConnectionTable.class);
private static final int BOTTOM_PADDING = 20; private static final int BOTTOM_PADDING = 20;
//private static final int[] TABLE_PROPORTIONS = new int[] { 3, 3, 2, 1 };
//private static final int NUMBER_OF_NONE_INDICATOR_COLUMNS = 3;
private static final String INDICATOR_NAME_TEXT_KEY_PREFIX = private static final String INDICATOR_NAME_TEXT_KEY_PREFIX =
"sebserver.exam.indicator.type.description."; "sebserver.exam.indicator.type.description.";
@ -101,12 +100,13 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
private final Map<Long, ClientGroup> clientGroupMapping; private final Map<Long, ClientGroup> clientGroupMapping;
private final Table table; private final Table table;
private final ColorData colorData; private final ColorData colorData;
private final List<UpdatableTableItem> sortList = new ArrayList<>();
private final Function<MonitoringEntry, String> localizedClientConnectionStatusNameFunction; private final Function<MonitoringEntry, String> localizedClientConnectionStatusNameFunction;
private Consumer<ClientConnectionTable> selectionListener; private Consumer<ClientConnectionTable> selectionListener;
private int tableWidth; private int tableWidth;
private boolean needsSort = false; private boolean needsSort = false;
private LinkedHashMap<Long, UpdatableTableItem> tableMapping; private final LinkedHashMap<Long, UpdatableTableItem> tableMapping;
private final Set<Long> toDelete = new HashSet<>(); private final Set<Long> toDelete = new HashSet<>();
private final Set<Long> toUpdateStatic = new HashSet<>(); private final Set<Long> toUpdateStatic = new HashSet<>();
private final Set<Long> duplicates = new HashSet<>(); private final Set<Long> duplicates = new HashSet<>();
@ -432,13 +432,15 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
} }
private void sortTable() { private void sortTable() {
this.tableMapping = this.tableMapping.entrySet() this.sortList.clear();
.stream() this.sortList.addAll(this.tableMapping.values());
.sorted(Entry.comparingByValue()) Collections.sort(this.sortList);
.collect(Collectors.toMap( this.tableMapping.clear();
Entry::getKey, final Iterator<UpdatableTableItem> iterator = this.sortList.iterator();
Entry::getValue, while (iterator.hasNext()) {
(e1, e2) -> e1, LinkedHashMap::new)); final UpdatableTableItem item = iterator.next();
this.tableMapping.put(item.connectionId, item);
}
} }
private void notifySelectionChange() { private void notifySelectionChange() {
@ -494,7 +496,7 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
@Override @Override
public boolean sebVersionDenied() { public boolean sebVersionDenied() {
return this.monitoringData.sebVersionDenied; return (this.monitoringData == null) ? false : this.monitoringData.sebVersionDenied;
} }
@Override @Override
@ -559,7 +561,7 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
} }
private void updateNotifications(final TableItem tableItem) { private void updateNotifications(final TableItem tableItem) {
if (BooleanUtils.isTrue(this.monitoringData.pendingNotification)) { if (this.monitoringData != null && BooleanUtils.isTrue(this.monitoringData.pendingNotification)) {
tableItem.setImage(0, tableItem.setImage(0,
WidgetFactory.ImageIcon.NOTIFICATION.getImage(ClientConnectionTable.this.table.getDisplay())); WidgetFactory.ImageIcon.NOTIFICATION.getImage(ClientConnectionTable.this.table.getDisplay()));
tableItem.setBackground(0, ClientConnectionTable.this.colorData.color2); tableItem.setBackground(0, ClientConnectionTable.this.colorData.color2);
@ -595,7 +597,7 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
final Long id = entry.getKey(); final Long id = entry.getKey();
final String displayValue = entry.getValue(); final String displayValue = entry.getValue();
final IndicatorData indicatorData = ClientConnectionTable.this.indicatorMapping.get(id); final IndicatorData indicatorData = ClientConnectionTable.this.indicatorMapping.get(id);
if (indicatorData == null) { if (indicatorData == null || this.monitoringData == null) {
return; return;
} }
@ -654,6 +656,9 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
} }
int notificationWeight() { int notificationWeight() {
if (this.monitoringData == null) {
return 0;
}
return BooleanUtils.isTrue(this.monitoringData.pendingNotification) || return BooleanUtils.isTrue(this.monitoringData.pendingNotification) ||
(this.monitoringData.status.establishedStatus && this.marked) ? -1 : 0; (this.monitoringData.status.establishedStatus && this.marked) ? -1 : 0;
} }
@ -663,6 +668,9 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
} }
int thresholdsWeight() { int thresholdsWeight() {
if (this.monitoringData != null && !this.monitoringData.status.clientActiveStatus) {
return 0;
}
return -this.thresholdsWeight; return -this.thresholdsWeight;
} }
@ -690,6 +698,7 @@ public final class ClientConnectionTable implements FullPageMonitoringGUIUpdate
} }
String getConnectionIdentifier() { String getConnectionIdentifier() {
if (this.staticData != null && this.staticData.userSessionId != null) { if (this.staticData != null && this.staticData.userSessionId != null) {
return this.staticData.userSessionId; return this.staticData.userSessionId;
} }

View file

@ -69,20 +69,13 @@ public class ColorData {
switch (entry.getStatus()) { switch (entry.getStatus()) {
case CONNECTION_REQUESTED: case CONNECTION_REQUESTED:
case AUTHENTICATED: { case AUTHENTICATED: {
if (entry.incidentFlag() > 0) { return 0;
return -1;
}
return 1;
} }
case ACTIVE: { case ACTIVE: {
final int incidentFlag = entry.incidentFlag();
if (incidentFlag > 0) {
return -incidentFlag;
}
return 2; return 2;
} }
case CLOSED: case CLOSED:
return 4; return 3;
default: default:
return 5; return 5;
} }

View file

@ -1016,6 +1016,37 @@ public class ZoomProctoringService implements ExamProctoringService {
} }
} }
@Override
boolean isValid(final ProctoringServiceSettings proctoringSettings) {
final boolean valid = super.isValid(proctoringSettings);
if (!valid) {
return false;
}
try {
final OAuth2RestTemplate oAuth2RestTemplate = (OAuth2RestTemplate) super.restTemplate;
final OAuth2AccessToken accessToken = oAuth2RestTemplate.getAccessToken();
if (accessToken == null) {
return false;
}
final boolean expired = accessToken.isExpired();
if (expired) {
return false;
}
final int expiresIn = accessToken.getExpiresIn();
if (expiresIn < 60) {
return false;
}
return true;
} catch (final Exception e) {
log.error("Failed to verify Zoom OAuth2RestTemplate status", e);
return false;
}
}
@Override @Override
public HttpHeaders getHeaders() { public HttpHeaders getHeaders() {
final HttpHeaders httpHeaders = new HttpHeaders(); final HttpHeaders httpHeaders = new HttpHeaders();
@ -1123,14 +1154,15 @@ public class ZoomProctoringService implements ExamProctoringService {
@Override @Override
public boolean supportsRefresh(final OAuth2ProtectedResourceDetails resource) { public boolean supportsRefresh(final OAuth2ProtectedResourceDetails resource) {
return false; return true;
} }
@Override @Override
public OAuth2AccessToken refreshAccessToken(final OAuth2ProtectedResourceDetails resource, public OAuth2AccessToken refreshAccessToken(final OAuth2ProtectedResourceDetails resource,
final OAuth2RefreshToken refreshToken, final AccessTokenRequest request) final OAuth2RefreshToken refreshToken, final AccessTokenRequest request)
throws UserRedirectRequiredException { throws UserRedirectRequiredException {
return null;
return this.obtainAccessToken(resource, request);
} }
@Override @Override
@ -1140,7 +1172,6 @@ public class ZoomProctoringService implements ExamProctoringService {
final ClientCredentialsResourceDetails resource = (ClientCredentialsResourceDetails) details; final ClientCredentialsResourceDetails resource = (ClientCredentialsResourceDetails) details;
return retrieveToken(request, resource, getParametersForTokenRequest(resource), new HttpHeaders()); return retrieveToken(request, resource, getParametersForTokenRequest(resource), new HttpHeaders());
} }
private MultiValueMap<String, String> getParametersForTokenRequest( private MultiValueMap<String, String> getParametersForTokenRequest(