From b9962a26098d54c48ae5f3fe6b22c59b46e12af7 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 21 Dec 2022 16:52:45 +0100 Subject: [PATCH] SEBSERV-366 --- .../sebserver/gui/content/exam/ExamForm.java | 75 ++++++++++++------- .../lms/impl/LmsAPITemplateAdapter.java | 9 +-- .../lms/impl/SEBRestrictionServiceImpl.java | 1 + .../impl/mockup/MockSEBRestrictionAPI.java | 12 ++- src/main/resources/messages.properties | 3 +- 5 files changed, 64 insertions(+), 36 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java index 3dc911ac..d92e5c21 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java @@ -136,6 +136,8 @@ public class ExamForm implements TemplateComposer { new LocTextKey("sebserver.exam.consistency.no-lms-connection"); private final static LocTextKey CONSISTENCY_MESSAGEINVALID_ID_REFERENCE = new LocTextKey("sebserver.exam.consistency.invalid-lms-id"); + private final static LocTextKey CONSISTENCY_MESSAGE_SEB_RESTRICTION_MISMATCH = + new LocTextKey("sebserver.exam.consistencyseb-restriction-mismatch"); private final static LocTextKey AUTO_GEN_CONFIG_ERROR_TITLE = new LocTextKey("sebserver.exam.autogen.error.config.title"); @@ -220,30 +222,6 @@ public class ExamForm implements TemplateComposer { // new PageContext with actual EntityKey final PageContext formContext = pageContext.withEntityKey(exam.getEntityKey()); - // check exam consistency and inform the user if needed - Collection warnings = null; - if (readonly) { - warnings = this.restService.getBuilder(CheckExamConsistency.class) - .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) - .call() - .getOr(Collections.emptyList()); - if (warnings != null && !warnings.isEmpty()) { - showConsistencyChecks(warnings, formContext.getParent()); - } - } - - // the default page layout with title - final LocTextKey titleKey = importFromQuizData - ? EXAM_FORM_TITLE_IMPORT_KEY - : EXAM_FORM_TITLE_KEY; - final Composite content = this.widgetFactory.defaultPageLayout( - formContext.getParent(), - titleKey); - if (warnings != null && !warnings.isEmpty()) { - final GridData gridData = (GridData) content.getLayoutData(); - gridData.verticalIndent = 10; - } - final BooleanSupplier isNew = () -> importFromQuizData; final BooleanSupplier isNotNew = () -> !isNew.getAsBoolean(); final EntityGrantCheck entityGrantCheck = currentUser.entityGrantCheck(exam); @@ -262,6 +240,32 @@ public class ExamForm implements TemplateComposer { .call() .onError(e -> log.error("Unexpected error while trying to verify seb restriction settings: ", e)) .getOr(false); + final boolean sebRestrictionMismatch = isRestricted != exam.sebRestriction; + + // check exam consistency and inform the user if needed + Collection warnings = null; + if (readonly) { + warnings = this.restService.getBuilder(CheckExamConsistency.class) + .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) + .call() + .getOr(Collections.emptyList()); + if (sebRestrictionMismatch || (warnings != null && !warnings.isEmpty())) { + showConsistencyChecks(warnings, sebRestrictionMismatch, formContext.getParent()); + + } + } + + // the default page layout with title + final LocTextKey titleKey = importFromQuizData + ? EXAM_FORM_TITLE_IMPORT_KEY + : EXAM_FORM_TITLE_KEY; + final Composite content = this.widgetFactory.defaultPageLayout( + formContext.getParent(), + titleKey); + if ((warnings != null && !warnings.isEmpty()) || sebRestrictionMismatch) { + final GridData gridData = (GridData) content.getLayoutData(); + gridData.verticalIndent = 10; + } // The Exam form final FormHandle formHandle = this.pageService.formBuilder( @@ -637,10 +641,10 @@ public class ExamForm implements TemplateComposer { return !lmsSetupTestResult.hasError(ErrorType.QUIZ_RESTRICTION_API_REQUEST); } - private void showConsistencyChecks(final Collection result, final Composite parent) { - if (result == null || result.isEmpty()) { - return; - } + private void showConsistencyChecks( + final Collection result, + final boolean sebRestrictionMismatch, + final Composite parent) { final Composite warningPanel = this.widgetFactory.createWarningPanel(parent); this.widgetFactory.labelLocalized( @@ -656,6 +660,21 @@ public class ExamForm implements TemplateComposer { warningPanel, CustomVariant.MESSAGE, message)); + + if (sebRestrictionMismatch) { + this.widgetFactory.labelLocalized( + warningPanel, + CustomVariant.MESSAGE, + CONSISTENCY_MESSAGE_SEB_RESTRICTION_MISMATCH); + } + } + + private void showSEBRestrictionMismatchMessage(final Composite parent) { + final Composite warningPanel = this.widgetFactory.createWarningPanel(parent); + this.widgetFactory.labelLocalized( + warningPanel, + CustomVariant.MESSAGE, + CONSISTENCY_MESSAGE_SEB_RESTRICTION_MISMATCH); } private Result getExistingExam(final PageContext pageContext) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPITemplateAdapter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPITemplateAdapter.java index 0ec53df8..34e82cd6 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPITemplateAdapter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPITemplateAdapter.java @@ -372,14 +372,11 @@ public class LmsAPITemplateAdapter implements LmsAPITemplate { log.debug("Get course restriction: {} for LMSSetup: {}", exam.externalId, lmsSetup()); } + System.out.println("******************* getSEBClientRestriction"); + return this.restrictionRequest.protectedRun(() -> this.sebRestrictionAPI .getSEBClientRestriction(exam) - .onError(error -> { - if (error instanceof NoSEBRestrictionException) { - return; - } - log.error("Failed to get SEB restrictions: {}", error.getMessage()); - }) + .onError(error -> log.error("Failed to get SEB restrictions: {}", error.getMessage())) .getOrThrow()); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java index 0ebb96ac..f629d9e1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java @@ -244,6 +244,7 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService { exam, sebRestrictionData)) .map(data -> exam) + .onError(error -> this.examDAO.setSEBRestriction(exam.id, false)) .getOrThrow(); }) .getOrThrow(); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockSEBRestrictionAPI.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockSEBRestrictionAPI.java index 34fd34ee..00b267bd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockSEBRestrictionAPI.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/mockup/MockSEBRestrictionAPI.java @@ -30,7 +30,16 @@ public class MockSEBRestrictionAPI implements SEBRestrictionAPI { @Override public Result getSEBClientRestriction(final Exam exam) { - log.info("Apply SEB Client restriction for Exam: {}", exam); + log.info("Get SEB Client restriction for Exam: {}", exam); +// if (BooleanUtils.toBoolean(exam.sebRestriction)) { +// return Result.of(new SEBRestriction( +// exam.id, +// Stream.of("configKey").collect(Collectors.toList()), +// Collections.emptyList(), +// Collections.emptyMap())); +// } else { +// return Result.ofError(new NoSEBRestrictionException()); +// } return Result.ofError(new NoSEBRestrictionException()); } @@ -40,6 +49,7 @@ public class MockSEBRestrictionAPI implements SEBRestrictionAPI { final SEBRestriction sebRestrictionData) { log.info("Apply SEB Client restriction: {}", sebRestrictionData); + //return Result.ofError(new NoSEBRestrictionException()); return Result.of(sebRestrictionData); } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index b4ad9cd9..80c2e107 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -509,9 +509,10 @@ sebserver.exam.consistency.title=Note: This exam is already running but has some sebserver.exam.consistency.missing-supporter= - There are no Exam Supporter defined for this exam. Use 'Edit Exam' on the right to add an Exam Supporter. sebserver.exam.consistency.missing-indicator= - There is no indicator defined for this exam. Use 'Add Indicator" on the right to add an indicator. sebserver.exam.consistency.missing-config= - There is no configuration defined for this exam. Use 'Add Configuration' to attach one. -sebserver.exam.consistency.missing-seb-restriction= - There is currently no SEB restriction applied on the LMS side. Use 'Enable SEB Restriction' on the right to activate auto-restriction.
Or if this is not possible consider doing it manually on the LMS. +sebserver.exam.consistency.missing-seb-restriction= - There is currently no SEB restriction applied on the LMS side. Use 'Apply SEB Lock' on the right to activate auto-restriction.
Or if this is not possible consider doing it manually on the LMS. sebserver.exam.consistency.no-lms-connection= - Failed to connect to the LMS Setup of this exam yet.
Please check the LMS connection within the LMS Setup. sebserver.exam.consistency.invalid-lms-id= - The referencing course identifier seems to be invalid.
Please check if the course for this exam still exists on the LMS and the course identifier has not changed. +sebserver.exam.consistencyseb-restriction-mismatch= - There seems to be a mismatch in the SEB restriction for this exam. SEB Server has different state then the one of the LMS.
    The cause of this might lie in a connection errors with the LMS.
    However SEB Server is not able to verify the exact status of the SEB restriction on the LMS for this exam. sebserver.exam.confirm.remove-config=This exam is current running. The remove of the attached configuration will led to an invalid state
where connecting SEB clients cannot download the configuration for the exam.

Are you sure to remove the configuration? sebserver.exam.autogen.error.config.title=Exam Import Setup Failure sebserver.exam.autogen.error.config.text=There was an unexpected error while setting up the imported exam.
Please note that the exam has successfully been imported and can be modified but one or more additional auto-setup(s) failed:
{0}