From 6a81b3f7176f93777f219b23f9a956021f4d6002 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 12 Jun 2024 08:43:58 +0200 Subject: [PATCH] SEBSERV-417 try fix corrupt Moodle data --- .../plugin/MoodlePluginCourseRestriction.java | 1 - .../api/ExamAdministrationController.java | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseRestriction.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseRestriction.java index 4f71f7f8..bcc65b23 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseRestriction.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/plugin/MoodlePluginCourseRestriction.java @@ -174,7 +174,6 @@ public class MoodlePluginCourseRestriction implements SEBRestrictionAPI { addQuery.add(ATTRIBUTE_QUIZ_ID, quizId); final LinkedMultiValueMap queryAttributes = new LinkedMultiValueMap<>(); - queryAttributes.add(ATTRIBUTE_CONFIG_KEYS, StringUtils.EMPTY); queryAttributes.add(ATTRIBUTE_BROWSER_EXAM_KEYS, StringUtils.EMPTY); 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 8ac4e9cb..cb022f07 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 @@ -17,6 +17,7 @@ import javax.validation.Valid; import ch.ethz.seb.sebserver.gbl.util.Cryptor; import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamImportService; import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamUtils; +import ch.ethz.seb.sebserver.webservice.servicelayer.lms.FullLmsIntegrationService; import ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.NoSEBRestrictionException; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; @@ -92,6 +93,7 @@ public class ExamAdministrationController extends EntityController { private final SEBRestrictionService sebRestrictionService; private final SecurityKeyService securityKeyService; private final Cryptor cryptor; + private final FullLmsIntegrationService fullLmsIntegrationService; public ExamAdministrationController( final AuthorizationService authorization, @@ -108,7 +110,8 @@ public class ExamAdministrationController extends EntityController { final ExamSessionService examSessionService, final SEBRestrictionService sebRestrictionService, final SecurityKeyService securityKeyService, - final Cryptor cryptor) { + final Cryptor cryptor, + final FullLmsIntegrationService fullLmsIntegrationService) { super(authorization, bulkActionService, @@ -127,6 +130,7 @@ public class ExamAdministrationController extends EntityController { this.sebRestrictionService = sebRestrictionService; this.securityKeyService = securityKeyService; this.cryptor = cryptor; + this.fullLmsIntegrationService = fullLmsIntegrationService; } @Override @@ -726,14 +730,17 @@ public class ExamAdministrationController extends EntityController { .of("The LMS for this Exam has no SEB restriction feature")); } - if (this.examSessionService.hasActiveSEBClientConnections(exam.id)) { - throw new APIMessageException( - APIMessage.ErrorMessage.INTEGRITY_VALIDATION - .of("Exam currently has active SEB Client connections.")); - } - return this.checkNoActiveSEBClientConnections(exam) .flatMap(this.sebRestrictionService::applySEBClientRestriction) + // TODO temporary try to fix corrupted data on Moodle site + .onErrorDo(error -> { + if (error.getMessage().contains("error/SEB Server")) { + log.info("**** try to reset exam_data on Moodle 2.0 with temporary hack... "); + fullLmsIntegrationService.applyExamDataToLMS(exam) + .onError(e -> log.error("Failed to apply exam data: ", error)); + } + return this.sebRestrictionService.applySEBClientRestriction(exam).getOrThrow(); + }) .flatMap(e -> this.examDAO.setSEBRestriction(exam.id, restrict)) .getOrThrow(); } else {