active client connection handling and find-bugs
This commit is contained in:
parent
dee1477472
commit
5551c7d7c2
6 changed files with 35 additions and 43 deletions
|
@ -12,9 +12,11 @@
|
|||
<Package name="ch.ethz.seb.sebserver.webservice.datalayer.batis.model"/>
|
||||
</Match>
|
||||
<Match>
|
||||
<Class name="ch.ethz.seb.sebserver.gui.widget.MultiSelectionCombo" />
|
||||
<Class name="ch.ethz.seb.sebserver.gui.widget.GridTable" />
|
||||
<Package name="ch.ethz.seb.sebserver.gui.widget" />
|
||||
<Bug pattern="SE_BAD_FIELD" />
|
||||
</Match>
|
||||
|
||||
|
||||
|
||||
|
||||
</FindBugsFilter>
|
|
@ -47,14 +47,21 @@ public interface ExamSessionService {
|
|||
void streamDefaultExamConfig(String connectionToken, OutputStream out);
|
||||
|
||||
/** Get current ClientConnectionData for a specified active SEB client connection.
|
||||
*
|
||||
*
|
||||
* active SEB client connections are connections that were initialized by a SEB client
|
||||
* on the particular server instance.
|
||||
*
|
||||
* @param connectionToken the connection token of the active SEB client connection
|
||||
* @return */
|
||||
Result<ClientConnectionData> getConnectionData(String connectionToken);
|
||||
|
||||
/** Get the collection of ClientConnectionData of all active SEB client connections
|
||||
* of a running exam.
|
||||
*
|
||||
*
|
||||
* active SEB client connections are connections that were initialized by a SEB client
|
||||
* on the particular server instance. This may not be the all connections of an exam but
|
||||
* a subset of them.
|
||||
*
|
||||
* @param examId The exam identifier
|
||||
* @return collection of ClientConnectionData of all active SEB client connections
|
||||
* of a running exam */
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
package ch.ethz.seb.sebserver.webservice.servicelayer.session;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection;
|
||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData;
|
||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientEvent;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||
|
||||
|
@ -100,12 +99,6 @@ public interface SebClientConnectionService {
|
|||
Long institutionId,
|
||||
String clientAddress);
|
||||
|
||||
/** Get ClientConnectionData for an active connection (connection on running exam)
|
||||
*
|
||||
* @param connectionToken The connection token of the connection to get the ClientConnectionData from
|
||||
* @return ClientConnectionData for an active connection (connection on running exam) */
|
||||
Result<ClientConnectionData> getActiveConnectionData(String connectionToken);
|
||||
|
||||
/** Notify a ping for a certain client connection.
|
||||
*
|
||||
* @param connectionToken the connection token
|
||||
|
|
|
@ -17,6 +17,8 @@ import java.util.stream.Collectors;
|
|||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -40,15 +42,18 @@ public class ExamSessionServiceImpl implements ExamSessionService {
|
|||
private final ClientConnectionDAO clientConnectionDAO;
|
||||
private final ExamSessionCacheService examSessionCacheService;
|
||||
private final ExamDAO examDAO;
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
protected ExamSessionServiceImpl(
|
||||
final ExamSessionCacheService examSessionCacheService,
|
||||
final ExamDAO examDAO,
|
||||
final ClientConnectionDAO clientConnectionDAO) {
|
||||
final ClientConnectionDAO clientConnectionDAO,
|
||||
final CacheManager cacheManager) {
|
||||
|
||||
this.examSessionCacheService = examSessionCacheService;
|
||||
this.examDAO = examDAO;
|
||||
this.clientConnectionDAO = clientConnectionDAO;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -147,25 +152,24 @@ public class ExamSessionServiceImpl implements ExamSessionService {
|
|||
|
||||
@Override
|
||||
public Result<ClientConnectionData> getConnectionData(final String connectionToken) {
|
||||
final ClientConnectionDataInternal activeClientConnection = this.examSessionCacheService
|
||||
.getActiveClientConnection(connectionToken);
|
||||
|
||||
if (activeClientConnection == null) {
|
||||
log.error("No active ClientConnection found for token: {}", connectionToken);
|
||||
return Result.ofError(new IllegalArgumentException("No active ClientConnection found for token"));
|
||||
} else {
|
||||
return Result.of(activeClientConnection);
|
||||
}
|
||||
return Result.tryCatch(() -> {
|
||||
final Cache cache = this.cacheManager.getCache(ExamSessionCacheService.CACHE_NAME_ACTIVE_CLIENT_CONNECTION);
|
||||
return cache.get(connectionToken, ClientConnectionData.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Collection<ClientConnectionData>> getConnectionData(final Long examId) {
|
||||
return this.clientConnectionDAO
|
||||
.getConnectionTokens(examId)
|
||||
.map(all -> all
|
||||
.stream()
|
||||
.map(this.examSessionCacheService::getActiveClientConnection)
|
||||
.collect(Collectors.toList()));
|
||||
return Result.tryCatch(() -> {
|
||||
final Cache cache = this.cacheManager.getCache(ExamSessionCacheService.CACHE_NAME_ACTIVE_CLIENT_CONNECTION);
|
||||
return this.clientConnectionDAO
|
||||
.getConnectionTokens(examId)
|
||||
.getOrThrow()
|
||||
.stream()
|
||||
.map(token -> cache.get(token, ClientConnectionData.class))
|
||||
.filter(data -> data != null)
|
||||
.collect(Collectors.toList());
|
||||
});
|
||||
}
|
||||
|
||||
private void flushCache(final Exam exam) {
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.springframework.stereotype.Service;
|
|||
import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamType;
|
||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection;
|
||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus;
|
||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData;
|
||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientEvent;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||
|
@ -339,19 +338,6 @@ public class SebClientConnectionServiceImpl implements SebClientConnectionServic
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<ClientConnectionData> getActiveConnectionData(final String connectionToken) {
|
||||
final ClientConnectionDataInternal activeClientConnection = this.examSessionCacheService
|
||||
.getActiveClientConnection(connectionToken);
|
||||
|
||||
if (activeClientConnection == null) {
|
||||
return Result
|
||||
.ofError(new IllegalArgumentException("No active client connection found for connectionToken"));
|
||||
} else {
|
||||
return Result.of(activeClientConnection);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyPing(
|
||||
final String connectionToken,
|
||||
|
|
|
@ -259,8 +259,8 @@ public class ExamAPI_V1_Controller {
|
|||
handshakeUpdate(connectionToken, Long.valueOf(examId), null, principal, request);
|
||||
}
|
||||
|
||||
final ClientConnectionData connection = this.sebClientConnectionService
|
||||
.getActiveConnectionData(connectionToken)
|
||||
final ClientConnectionData connection = this.examSessionService
|
||||
.getConnectionData(connectionToken)
|
||||
.getOrThrow();
|
||||
|
||||
// exam integrity check
|
||||
|
|
Loading…
Reference in a new issue