From e3c42fa44a4be5e95ab25645330208aa3d0240c8 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 30 Jun 2022 15:20:25 +0200 Subject: [PATCH] SEBSERV-334 fixed --- .../session/ExamSessionService.java | 14 +++++-- .../session/impl/ExamSessionServiceImpl.java | 6 +++ .../api/ExamAdministrationController.java | 1 - .../integration/UseCasesIntegrationTest.java | 37 ++++--------------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java index 27d98a7a..38679835 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java @@ -77,7 +77,7 @@ public interface ExamSessionService { /** Use this to check if a specified Exam has currently active SEB Client connections. * * Active SEB Client connections are established connections that are not yet closed and - * connection attempts that are older the a defined time interval. + * open connection attempts. * * @param examId The Exam identifier * @return true if the given Exam has currently no active client connection, false otherwise. */ @@ -86,7 +86,7 @@ public interface ExamSessionService { return false; } - return !this.getActiveConnectionTokens(examId) + return !this.getAllActiveConnectionTokens(examId) .getOrThrow() .isEmpty(); } @@ -184,13 +184,21 @@ public interface ExamSessionService { final Long examId, final Predicate filter); - /** Gets all connection tokens of active client connection that are related to a specified exam + /** Gets all connection tokens of client connection that are in ACTIVE state and related to a specified exam * from persistence storage without caching involved. * * @param examId the exam identifier * @return Result refer to the collection of connection tokens or to an error when happened. */ Result> getActiveConnectionTokens(Long examId); + /** Gets all connection tokens of client connections that are in an active state. See ClientConnection + * And that are related to a specified exam. + * There is no caching involved here, gets actual data from persistent storage + * + * @param examId the exam identifier + * @return Result refer to the collection of connection tokens or to an error when happened. */ + Result> getAllActiveConnectionTokens(Long examId); + /** Use this to check if the current cached running exam is up to date * and if not to flush the cache. * diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java index b413c5c9..9144daeb 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java @@ -430,6 +430,12 @@ public class ExamSessionServiceImpl implements ExamSessionService { .getActiveConnectionTokens(examId); } + @Override + public Result> getAllActiveConnectionTokens(final Long examId) { + return this.clientConnectionDAO + .getAllActiveConnectionTokens(examId); + } + @EventListener public void notifyExamFinished(final ExamFinishedEvent event) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java index b910eb7c..32bdfac6 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java @@ -568,7 +568,6 @@ public class ExamAdministrationController extends EntityController { .of("Exam currently has active SEB Client connections.")); } - // TODO double check before setSEBRestriction return this.checkNoActiveSEBClientConnections(exam) .flatMap(this.sebRestrictionService::applySEBClientRestriction) .flatMap(e -> this.examDAO.setSEBRestriction(exam.id, restrict)) diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java index fa66a89c..e77559a6 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java @@ -254,35 +254,6 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { // Nothing } -// @Test -// @Order(0) -// public void testUsecase00_cleanupAllExams() { -// final RestServiceImpl restService = createRestServiceForUser( -// "admin", -// "admin", -// new GetExamNames(), -// new DeleteExam()); -// -// final Result> call = restService -// .getBuilder(GetExamNames.class) -// .call(); -// -// if (!call.hasError()) { -// call.get().stream().forEach(key -> { -// final Result deleted = restService -// .getBuilder(DeleteExam.class) -// .withURIVariable(API.PARAM_MODEL_ID, key.modelId) -// .call(); -// -// if (deleted.hasError()) { -// System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%% deletion failed: " + key); -// } else { -// System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%% deleted: " + key); -// } -// }); -// } -// } - @Test @Order(1) // ************************************* @@ -815,6 +786,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { // - Check if there are some quizzes from previous LMS Setup // - Import a quiz as Exam // - get exam page and check the exam is there + // - get exam page with none native sort attribute to test this // - edit exam property and save again public void testUsecase07_ImportExam() { final RestServiceImpl restService = createRestServiceForUser( @@ -922,6 +894,13 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .filter(exam -> exam.name.equals(newExam.name)) .findFirst().isPresent()); + final Result> examsSorted = restService + .getBuilder(GetExamPage.class) + .withQueryParam(Page.ATTR_SORT, LmsSetup.FILTER_ATTR_LMS_SETUP) + .call(); + + assertNotNull(examsSorted); + assertFalse(examsSorted.hasError()); } @Test