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 72b8687b..c67dd542 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 @@ -820,7 +820,8 @@ public class ExamDAOImpl implements ExamDAO { // short name. If one quiz has been found that matches all criteria, we adapt the internal id // mapping to this quiz. try { - final LmsSetup lmsSetup = this.lmsAPIService.getLmsSetup(record.getLmsSetupId()) + final LmsSetup lmsSetup = this.lmsAPIService + .getLmsSetup(record.getLmsSetupId()) .getOrThrow(); if (lmsSetup.lmsType == LmsType.MOODLE) { @@ -851,21 +852,23 @@ public class ExamDAOImpl implements ExamDAO { final String shortname = MoodleCourseAccess.getShortname(externalId); if (StringUtils.isNotBlank(shortname)) { - log.debug("using shortame: {} for recovering", shortname); + log.debug("Using short-name: {} for recovering", shortname); - final QuizData recoveredQuizData = quizzes.entrySet() - .stream() - .filter(quizEntry -> { - final String qShortName = MoodleCourseAccess.getShortname(quizEntry.getKey()); - return qShortName != null && qShortName.equals(shortname); - }) - .map(quizEntry -> quizEntry.getValue()) - .filter(quiz -> additionalAttribute.getValue().equals(quiz.name)) - .findAny() - .orElse(null); + final QuizData recoveredQuizData = this.lmsAPIService.getLmsAPITemplate(lmsSetup.id) + .map(template -> template.getQuizzes(new FilterMap()) + .getOrThrow() + .stream() + .filter(quiz -> { + final String qShortName = MoodleCourseAccess.getShortname(quiz.id); + return qShortName != null && qShortName.equals(shortname); + }) + .filter(quiz -> additionalAttribute.getValue().equals(quiz.name)) + .findAny() + .get()) + .getOrThrow(); if (recoveredQuizData != null) { - log.debug("found quiz data for recovering: {}", recoveredQuizData); + log.debug("Found quiz data for recovering: {}", recoveredQuizData); // save exam with new external id this.examRecordMapper.updateByPrimaryKeySelective(new ExamRecord( @@ -873,6 +876,9 @@ public class ExamDAOImpl implements ExamDAO { null, null, recoveredQuizData.id, null, null, null, null, null, null, null, null, null, null)); + + log.debug("Successfully recovered exam quiz data to new externalId {}", + recoveredQuizData.id); } return recoveredQuizData; } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsAPIService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsAPIService.java index 851289d7..68811b89 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsAPIService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsAPIService.java @@ -100,6 +100,9 @@ public interface LmsAPIService { * @param filterMap the FilterMap containing the filter criteria * @return true if the given QuizzData passes the filter */ static Predicate quizFilterPredicate(final FilterMap filterMap) { + if (filterMap == null) { + return q -> true; + } final String name = filterMap.getQuizName(); final DateTime from = filterMap.getQuizFromTime(); return q -> { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleCourseAccess.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleCourseAccess.java index 27f47eec..aea9d157 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleCourseAccess.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/moodle/MoodleCourseAccess.java @@ -329,7 +329,7 @@ public class MoodleCourseAccess extends CourseAccess { return null; } - final String[] ids = internalQuizId.split(internalQuizId, Constants.COLON); + final String[] ids = StringUtils.split(internalQuizId, Constants.COLON); return ids[ids.length - 1]; } @@ -338,9 +338,11 @@ public class MoodleCourseAccess extends CourseAccess { return null; } - final String[] ids = internalQuizId.split(internalQuizId, Constants.COLON); - if (ids.length > 1) { - return ids[ids.length - 2]; + final String[] ids = StringUtils.split(internalQuizId, Constants.COLON); + if (ids.length == 3) { + return ids[1]; + } else if (ids.length == 2) { + return ids[0]; } else { return null; } @@ -351,7 +353,7 @@ public class MoodleCourseAccess extends CourseAccess { return null; } - final String[] ids = internalQuizId.split(internalQuizId, Constants.COLON); + final String[] ids = StringUtils.split(internalQuizId, Constants.COLON); if (ids.length == 3) { return ids[0]; } else { diff --git a/src/main/resources/config/application-dev.properties b/src/main/resources/config/application-dev.properties index a0ee0b69..0012fdde 100644 --- a/src/main/resources/config/application-dev.properties +++ b/src/main/resources/config/application-dev.properties @@ -5,5 +5,5 @@ server.port=8080 server.servlet.context-path=/ server.tomcat.uri-encoding=UTF-8 -logging.level.ch=ERROR +logging.level.ch=INFO