From 25ed224b3a03c1e3a91e45ef35076202d6029c9f Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 16 Aug 2022 10:47:35 +0200 Subject: [PATCH] fixed lms update if not available at all --- .../legacy/MoodleRestTemplateFactory.java | 2 +- .../session/impl/ExamUpdateHandler.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/legacy/MoodleRestTemplateFactory.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/legacy/MoodleRestTemplateFactory.java index 5de31e82..f3b803ae 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/legacy/MoodleRestTemplateFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/legacy/MoodleRestTemplateFactory.java @@ -137,7 +137,7 @@ public class MoodleRestTemplateFactory { log.warn("Failed to get access token for LMS: {}({})", lmsSetup.name, lmsSetup.id, - result.getError()); + result.getError().getMessage()); } return result; }) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java index a3dd4a3c..d911846c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java @@ -88,6 +88,31 @@ class ExamUpdateHandler { final Set failedOrMissing = new HashSet<>(exams.keySet()); final String updateId = this.createUpdateId(); + // test overall LMS access + try { + this.lmsAPIService + .getLmsAPITemplate(lmsSetupId) + .getOrThrow() + .checkCourseAPIAccess(); + } catch (final Exception e) { + log.warn("No LMS access, mark all exams of the LMS as not connected to LMS"); + if (!failedOrMissing.isEmpty()) { + failedOrMissing + .stream() + .forEach(quizId -> { + try { + final Exam exam = exams.get(quizId); + if (exam.lmsAvailable == null || exam.isLmsAvailable()) { + this.examDAO.markLMSAvailability(quizId, false, updateId); + } + } catch (final Exception ee) { + log.error("Failed to mark exam: {} as not connected to LMS", quizId, ee); + } + }); + } + return failedOrMissing; + } + this.lmsAPIService .getLmsAPITemplate(lmsSetupId) .map(template -> {