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