fixed Moodle quiz recovery
This commit is contained in:
parent
a17da0923b
commit
286ba29e02
4 changed files with 30 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<QuizData> quizFilterPredicate(final FilterMap filterMap) {
|
||||
if (filterMap == null) {
|
||||
return q -> true;
|
||||
}
|
||||
final String name = filterMap.getQuizName();
|
||||
final DateTime from = filterMap.getQuizFromTime();
|
||||
return q -> {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue