From c3eda2b81d73d26e40884090ca5a2e3aa037a476 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 8 Sep 2021 16:02:58 +0200 Subject: [PATCH] Fixed Exam update task to not brake on single exam update error --- .../ch/ethz/seb/sebserver/gui/content/ExamForm.java | 6 +++--- .../session/impl/ExamSessionControlTask.java | 8 +++----- .../session/impl/ExamUpdateHandler.java | 13 ++++++------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java index f3c93f98..030a3ebe 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java @@ -390,7 +390,7 @@ public class ExamForm implements TemplateComposer { .withExec(this.examCreateClientConfigPopup.exportFunction( exam.institutionId, exam.getName())) - .publishIf(() -> modifyGrant && readonly) + .publishIf(() -> editable && readonly) .newAction(ActionDefinition.EXAM_MODIFY_SEB_RESTRICTION_DETAILS) .withEntityKey(entityKey) @@ -416,13 +416,13 @@ public class ExamForm implements TemplateComposer { .withEntityKey(entityKey) .withExec(this.examProctoringSettings.settingsFunction(this.pageService, modifyGrant)) .noEventPropagation() - .publishIf(() -> proctoringEnabled && readonly) + .publishIf(() -> editable && proctoringEnabled && readonly) .newAction(ActionDefinition.EXAM_PROCTORING_OFF) .withEntityKey(entityKey) .withExec(this.examProctoringSettings.settingsFunction(this.pageService, modifyGrant)) .noEventPropagation() - .publishIf(() -> !proctoringEnabled && readonly) + .publishIf(() -> editable && !proctoringEnabled && readonly) .newAction(ActionDefinition.EXAM_DELETE) .withEntityKey(entityKey) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionControlTask.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionControlTask.java index a1e77179..f2430c4f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionControlTask.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionControlTask.java @@ -133,7 +133,7 @@ class ExamSessionControlTask implements DisposableBean { .getOrThrow() .stream() .filter(exam -> exam.startTime.minus(this.examTimePrefix).isBefore(now)) - .map(exam -> this.examUpdateHandler.setRunning(exam, updateId)) + .flatMap(exam -> Result.skipOnError(this.examUpdateHandler.setRunning(exam, updateId))) .collect(Collectors.toMap(Exam::getId, Exam::getName)); if (!updated.isEmpty()) { @@ -158,10 +158,8 @@ class ExamSessionControlTask implements DisposableBean { .getOrThrow() .stream() .filter(exam -> exam.endTime != null && exam.endTime.plus(this.examTimeSuffix).isBefore(now)) - .map(exam -> this.examUpdateHandler.setFinished(exam, updateId)) - .map(this.examProcotringRoomService::disposeRoomsForExam) - .filter(result -> !result.hasError()) - .map(Result::get) + .flatMap(exam -> Result.skipOnError(this.examUpdateHandler.setFinished(exam, updateId))) + .flatMap(exam -> Result.skipOnError(this.examProcotringRoomService.disposeRoomsForExam(exam))) .collect(Collectors.toMap(Exam::getId, Exam::getName)); if (!updated.isEmpty()) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java index c83b9d60..95ac0472 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamUpdateHandler.java @@ -64,14 +64,15 @@ class ExamUpdateHandler { final DateTime now = DateTime.now(DateTimeZone.UTC); if (exam.getStatus() == ExamStatus.UP_COMING && exam.endTime.plus(this.examTimeSuffix).isBefore(now)) { - return setRunning(exam, this.createUpdateId()); + return setRunning(exam, this.createUpdateId()) + .getOr(exam); } else { return exam; } }); } - Exam setRunning(final Exam exam, final String updateId) { + Result setRunning(final Exam exam, final String updateId) { if (log.isDebugEnabled()) { log.debug("Update exam as running: {}", exam); } @@ -85,11 +86,10 @@ class ExamUpdateHandler { .flatMap(this.sebRestrictionService::applySEBClientRestriction) .flatMap(e -> this.examDAO.releaseLock(e.id, updateId)) .onError(error -> this.examDAO.forceUnlock(exam.id) - .onError(unlockError -> log.error("Failed to force unlock update look for exam: {}", exam.id))) - .getOrThrow(); + .onError(unlockError -> log.error("Failed to force unlock update look for exam: {}", exam.id))); } - Exam setFinished(final Exam exam, final String updateId) { + Result setFinished(final Exam exam, final String updateId) { if (log.isDebugEnabled()) { log.debug("Update exam as finished: {}", exam); } @@ -102,8 +102,7 @@ class ExamUpdateHandler { updateId)) .flatMap(this.sebRestrictionService::releaseSEBClientRestriction) .flatMap(e -> this.examDAO.releaseLock(e.id, updateId)) - .onError(error -> this.examDAO.forceUnlock(exam.id)) - .getOrThrow(); + .onError(error -> this.examDAO.forceUnlock(exam.id)); } }