From ea65d1e81ccf712c0d33780b87a5ed8abd9cb01c Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 27 Oct 2021 09:11:00 +0200 Subject: [PATCH 1/2] code analysis --- .../sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java | 1 + .../servicelayer/session/impl/ExamSessionServiceImpl.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java index a258846e..f10e325c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java @@ -637,6 +637,7 @@ public class ExamDAOImpl implements ExamDAO { @Override @Transactional(readOnly = true) public Result upToDate(final Long examId, final String updateId) { + // TODO make this with count on examId and updateId equals --> if count is 1 then it is up to date otherwise not return this.recordById(examId) .map(rec -> { if (updateId == null) { 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 67a62448..8c29fe3c 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 @@ -361,11 +361,13 @@ public class ExamSessionServiceImpl implements ExamSessionService { @Override public Result updateExamCache(final Long examId) { + // Get from cache (or load to cache if not already present) final Exam exam = this.examSessionCacheService.getRunningExam(examId); if (exam == null) { return Result.ofEmpty(); } + // Check if the exam from cache is up to date by checking the last_update on persistent storage final Boolean isUpToDate = this.examDAO.upToDate(examId, exam.lastUpdate) .onError(t -> log.error("Failed to verify if cached exam is up to date: {}", exam, t)) .getOr(false); From 9ce538484bd74573b83677770a94716b5a6bc152 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 28 Oct 2021 13:45:34 +0200 Subject: [PATCH 2/2] fixed single moodle course bug --- .../lms/impl/moodle/MoodleCourseDataAsyncLoader.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleCourseDataAsyncLoader.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleCourseDataAsyncLoader.java index 4d3a9730..290afbc2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleCourseDataAsyncLoader.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleCourseDataAsyncLoader.java @@ -14,6 +14,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Function; @@ -215,9 +216,14 @@ public class MoodleCourseDataAsyncLoader { // then get all quizzes of courses and filter final LinkedMultiValueMap attributes = new LinkedMultiValueMap<>(); + final List courseIds = new ArrayList<>(courseData.keySet()); + if (courseIds.size() == 1) { + // NOTE: This is a workaround because the Moodle API do not support lists with only one element. + courseIds.add("0"); + } attributes.put( MoodleCourseAccess.MOODLE_COURSE_API_COURSE_IDS, - new ArrayList<>(courseData.keySet())); + courseIds); final String quizzesJSON = callMoodleRestAPI( restTemplate,