From 28960ddacc6c70a06ba59a29855474aa1077af2b Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 25 Mar 2024 16:26:47 +0100 Subject: [PATCH 1/2] SEBSERV-529 fixed --- .../servicelayer/lms/impl/SEBRestrictionServiceImpl.java | 9 ++++++--- .../moodle/plugin/MoodlePluginCourseRestriction.java | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) 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 758203b4..f9d42be0 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 @@ -148,9 +148,12 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService { // special Moodle plugin case for ADDITIONAL_ATTR_ALTERNATIVE_SEB_BEK this.lmsAPIService.getLmsSetup(exam.lmsSetupId).map(lms -> { if (lms.lmsType == LmsType.MOODLE_PLUGIN) { - additionalAttributes.put( - MoodleSEBRestriction.ATTR_ALT_BEK, - exam.getAdditionalAttribute(ADDITIONAL_ATTR_ALTERNATIVE_SEB_BEK)); + final AdditionalAttributeRecord attr = this.additionalAttributesDAO.getAdditionalAttribute( + EntityType.EXAM, + exam.id, + ADDITIONAL_ATTR_ALTERNATIVE_SEB_BEK) + .getOrThrow(); + additionalAttributes.put(MoodleSEBRestriction.ATTR_ALT_BEK, attr.getValue()); } return lms; }); 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 85cb6025..38dd7ade 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 @@ -137,8 +137,11 @@ public class MoodlePluginCourseRestriction implements SEBRestrictionAPI { final ArrayList configKeys = new ArrayList<>(sebRestrictionData.configKeys); final String quitLink = this.examConfigurationValueService.getQuitLink(exam.id); final String quitSecret = this.examConfigurationValueService.getQuitPassword(exam.id); - final String additionalBEK = exam.getAdditionalAttribute( - SEBRestrictionService.ADDITIONAL_ATTR_ALTERNATIVE_SEB_BEK); + String additionalBEK = sebRestrictionData.additionalProperties.get(SEBRestrictionService.ADDITIONAL_ATTR_ALTERNATIVE_SEB_BEK); + if (additionalBEK == null) { + additionalBEK = exam.getAdditionalAttribute( + SEBRestrictionService.ADDITIONAL_ATTR_ALTERNATIVE_SEB_BEK); + } if (additionalBEK != null && !beks.contains(additionalBEK)) { beks.add(additionalBEK); From a53b3b0947a0fa4e29d3167c6ae473fa1a97932e Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 26 Mar 2024 09:28:38 +0100 Subject: [PATCH 2/2] SEBSERV-529 fixed empty additional attributes --- .../lms/impl/moodle/MoodleUtils.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleUtils.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleUtils.java index c334d841..e2750f4b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleUtils.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleUtils.java @@ -202,18 +202,36 @@ public abstract class MoodleUtils { final boolean useQuizId) { final Map additionalAttrs = new HashMap<>(); - additionalAttrs.put(QuizData.ATTR_ADDITIONAL_CREATION_TIME, String.valueOf(courseData.time_created)); - additionalAttrs.put(QuizData.ATTR_ADDITIONAL_SHORT_NAME, courseData.short_name); - additionalAttrs.put(QuizData.ATTR_ADDITIONAL_ID_NUMBER, courseData.idnumber); - additionalAttrs.put(QuizData.ATTR_ADDITIONAL_FULL_NAME, courseData.full_name); - additionalAttrs.put(QuizData.ATTR_ADDITIONAL_DISPLAY_NAME, courseData.display_name); - additionalAttrs.put(QuizData.ATTR_ADDITIONAL_SUMMARY, courseData.summary); + if (courseData.time_created != null) { + additionalAttrs.put(QuizData.ATTR_ADDITIONAL_CREATION_TIME, String.valueOf(courseData.time_created)); + } + if (courseData.short_name != null) { + additionalAttrs.put(QuizData.ATTR_ADDITIONAL_SHORT_NAME, courseData.short_name); + } + if (courseData.idnumber != null) { + additionalAttrs.put(QuizData.ATTR_ADDITIONAL_ID_NUMBER, courseData.idnumber); + } + if (StringUtils.isNotBlank(courseData.full_name)) { + additionalAttrs.put(QuizData.ATTR_ADDITIONAL_FULL_NAME, courseData.full_name); + } + if (StringUtils.isNotBlank(courseData.display_name)) { + additionalAttrs.put(QuizData.ATTR_ADDITIONAL_DISPLAY_NAME, courseData.display_name); + } + if (StringUtils.isNotBlank(courseData.summary)) { + additionalAttrs.put(QuizData.ATTR_ADDITIONAL_SUMMARY, courseData.summary); + } final List courseAndQuiz = courseData.quizzes .stream() .map(courseQuizData -> { final String startURI = uriPrefix + courseQuizData.course_module; - additionalAttrs.put(QuizData.ATTR_ADDITIONAL_TIME_LIMIT, String.valueOf(courseQuizData.time_limit)); + + additionalAttrs.put( + QuizData.ATTR_ADDITIONAL_TIME_LIMIT, + (courseQuizData.time_limit == null) + ? StringUtils.EMPTY + : String.valueOf(courseQuizData.time_limit)); + return new QuizData( MoodleUtils.getInternalQuizId( (useQuizId) ? courseQuizData.id : courseQuizData.course_module,