SEBSERV-308 finished up refactoring of LMS connection handling

This commit is contained in:
anhefti 2022-05-18 09:11:57 +02:00
parent dad44d9b4d
commit adac7a044c
8 changed files with 37 additions and 15 deletions

View file

@ -276,8 +276,6 @@ public class ExamList implements TemplateComposer {
item.setData(RWT.CUSTOM_VARIANT, CustomVariant.WARNING.key); item.setData(RWT.CUSTOM_VARIANT, CustomVariant.WARNING.key);
} }
}); });
item.setGrayed(true);
} }
private static Function<Exam, String> examLmsSetupNameFunction(final ResourceService resourceService) { private static Function<Exam, String> examLmsSetupNameFunction(final ResourceService resourceService) {

View file

@ -198,11 +198,11 @@ public interface ExamDAO extends ActivatableEntityDAO<Exam, Exam>, BulkActionSup
key = "#examId") key = "#examId")
Result<QuizData> updateQuizData(Long examId, QuizData quizData, String updateId); Result<QuizData> updateQuizData(Long examId, QuizData quizData, String updateId);
/** This is used by the internal update process to mark exams for which the LMS related data is /** This is used by the internal update process to mark exams for which the LMS related data availability
* not currently available and the local data might be out-dated
* *
* @param externalQuizId The exams external UUID or quiz id of the exam to mark * @param externalQuizId The exams external UUID or quiz id of the exam to mark
* @param available The LMS availability flag to set
* @param updateId The update identifier given by the update task */ * @param updateId The update identifier given by the update task */
void markLMSNotAvailable(final String externalQuizId, final String updateId); void markLMSAvailability(final String externalQuizId, final boolean available, final String updateId);
} }

View file

@ -177,12 +177,16 @@ public class ExamDAOImpl implements ExamDAO {
} }
@Override @Override
public void markLMSNotAvailable(final String externalQuizId, final String updateId) { public void markLMSAvailability(final String externalQuizId, final boolean available, final String updateId) {
log.info("Mark exam quiz data not available form LMS: {}", externalQuizId); if (!available) {
log.info("Mark exam quiz data not available form LMS: {}", externalQuizId);
} else {
log.info("Mark exam quiz data back again form LMS: {}", externalQuizId);
}
this.examRecordDAO.idByExternalQuizId(externalQuizId) this.examRecordDAO.idByExternalQuizId(externalQuizId)
.map(examId -> this.examRecordDAO.updateLmsNotAvailable(examId, updateId)) .flatMap(examId -> this.examRecordDAO.updateLmsNotAvailable(examId, available, updateId))
.onError(error -> log.error("Failed to mark LMS not available: {}", externalQuizId, error)); .onError(error -> log.error("Failed to mark LMS not available: {}", externalQuizId, error));
} }

View file

@ -283,7 +283,7 @@ public class ExamRecordDAO {
} }
@Transactional @Transactional
public Result<ExamRecord> updateLmsNotAvailable(final Long examId, final String updateId) { public Result<ExamRecord> updateLmsNotAvailable(final Long examId, final boolean available, final String updateId) {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
// check internal persistent write-lock // check internal persistent write-lock
@ -300,7 +300,7 @@ public class ExamRecordDAO {
null, null, null, null,
Utils.getMillisecondsNow(), Utils.getMillisecondsNow(),
null, null, null, null, null, null,
BooleanUtils.toIntegerObject(false)); BooleanUtils.toIntegerObject(available));
this.examRecordMapper.updateByPrimaryKeySelective(examRecord); this.examRecordMapper.updateByPrimaryKeySelective(examRecord);
return this.examRecordMapper.selectByPrimaryKey(examId); return this.examRecordMapper.selectByPrimaryKey(examId);

View file

@ -166,6 +166,7 @@ public class MockCourseAccessAPI implements CourseAccessAPI {
public Result<QuizData> getQuiz(final String id) { public Result<QuizData> getQuiz(final String id) {
return Result.of(this.mockups return Result.of(this.mockups
.stream() .stream()
.map(this::getExternalAddressAlias)
.filter(q -> id.equals(q.id)) .filter(q -> id.equals(q.id))
.findFirst() .findFirst()
.get()); .get());

View file

@ -8,6 +8,7 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.session.impl; package ch.ethz.seb.sebserver.webservice.servicelayer.session.impl;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -85,9 +86,14 @@ class ExamUpdateHandler {
final Set<String> failedOrMissing = new HashSet<>(exams.keySet()); final Set<String> failedOrMissing = new HashSet<>(exams.keySet());
final String updateId = this.createUpdateId(); final String updateId = this.createUpdateId();
this.lmsAPIService.getLmsAPITemplate(lmsSetupId) this.lmsAPIService
.getLmsAPITemplate(lmsSetupId)
.flatMap(template -> template.getQuizzes(new HashSet<>(exams.keySet()))) .flatMap(template -> template.getQuizzes(new HashSet<>(exams.keySet())))
.getOrThrow() .onError(error -> log.warn(
"Failed to get quizzes form LMS Setup: {} cause: {}",
lmsSetupId,
error.getMessage()))
.getOr(Collections.emptyList())
.stream() .stream()
.forEach(quiz -> { .forEach(quiz -> {
@ -102,11 +108,17 @@ class ExamUpdateHandler {
log.error("Failed to update quiz data for exam: {}", quiz, log.error("Failed to update quiz data for exam: {}", quiz,
updateQuizData.getError()); updateQuizData.getError());
} else { } else {
if (!exam.lmsAvailable) {
this.examDAO.markLMSAvailability(quiz.id, true, updateId);
}
failedOrMissing.remove(quiz.id); failedOrMissing.remove(quiz.id);
log.info("Updated quiz data for exam: {}", updateQuizData.get()); log.info("Updated quiz data for exam: {}", updateQuizData.get());
} }
} else { } else {
if (!exam.lmsAvailable) {
this.examDAO.markLMSAvailability(quiz.id, true, updateId);
}
failedOrMissing.remove(quiz.id); failedOrMissing.remove(quiz.id);
} }
} catch (final Exception e) { } catch (final Exception e) {
@ -214,6 +226,7 @@ class ExamUpdateHandler {
final String updateId) { final String updateId) {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
final Exam exam = exams.get(quizId);
final LmsAPITemplate lmsTemplate = this.lmsAPIService final LmsAPITemplate lmsTemplate = this.lmsAPIService
.getLmsAPITemplate(lmsSetupId) .getLmsAPITemplate(lmsSetupId)
.getOrThrow(); .getOrThrow();
@ -230,7 +243,6 @@ class ExamUpdateHandler {
log.info("Try to recover quiz data for Moodle quiz with internal identifier: {}", quizId); log.info("Try to recover quiz data for Moodle quiz with internal identifier: {}", quizId);
final Exam exam = exams.get(quizId);
if (exam != null && exam.name != null) { if (exam != null && exam.name != null) {
log.debug("Found formerName quiz name: {}", exam.name); log.debug("Found formerName quiz name: {}", exam.name);
@ -270,7 +282,9 @@ class ExamUpdateHandler {
} }
} }
this.examDAO.markLMSNotAvailable(quizId, updateId); if (exam.lmsAvailable) {
this.examDAO.markLMSAvailability(quizId, false, updateId);
}
throw new RuntimeException("Not Available"); throw new RuntimeException("Not Available");
}); });
} }

View file

@ -34,5 +34,5 @@ ALTER TABLE `exam`
ADD COLUMN IF NOT EXISTS `quiz_name` VARCHAR(255) NULL AFTER `last_modified`, ADD COLUMN IF NOT EXISTS `quiz_name` VARCHAR(255) NULL AFTER `last_modified`,
ADD COLUMN IF NOT EXISTS `quiz_start_time` DATETIME NULL AFTER `quiz_name`, ADD COLUMN IF NOT EXISTS `quiz_start_time` DATETIME NULL AFTER `quiz_name`,
ADD COLUMN IF NOT EXISTS `quiz_end_time` DATETIME NULL AFTER `quiz_start_time`, ADD COLUMN IF NOT EXISTS `quiz_end_time` DATETIME NULL AFTER `quiz_start_time`,
ADD COLUMN IF NOT EXISTS `lms_available` INT(1) NULL AFTER `quiz_end_time`, ADD COLUMN IF NOT EXISTS `lms_available` INT(1) NULL AFTER `quiz_end_time`
; ;

View file

@ -909,6 +909,11 @@ TableItem:linesvisible:even {
color: inherit; color: inherit;
} }
TableItem:linesvisible:even.disabled {
background-color: #ffffff;
color: #aaaaaa;
}
Table-RowOverlay { Table-RowOverlay {
background-color: transparent; background-color: transparent;
color: inherit; color: inherit;