From ee89d2a24e566d696a193ef2adf865cd2006ce44 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 1 Jul 2024 12:23:31 +0200 Subject: [PATCH] SEBSERV-556 fixed notify exam template deletion to moodle --- .../exam/ExamTemplateChangeEvent.java | 11 ++++++- .../weblayer/api/ExamTemplateController.java | 33 ++++++++----------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamTemplateChangeEvent.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamTemplateChangeEvent.java index 774cc9e5..adf69c79 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamTemplateChangeEvent.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamTemplateChangeEvent.java @@ -14,10 +14,19 @@ import org.springframework.context.ApplicationEvent; public class ExamTemplateChangeEvent extends ApplicationEvent { + public static enum ChangeState { + CREATED, + MODIFIED, + DELETED, + } + private static final long serialVersionUID = -7239994198026689531L; - public ExamTemplateChangeEvent(final ExamTemplate source) { + public final ChangeState changeState; + + public ExamTemplateChangeEvent(final ExamTemplate source, final ChangeState changeState) { super(source); + this.changeState = changeState; } public ExamTemplate getExamTemplate() { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamTemplateController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamTemplateController.java index f8684682..ee23e091 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamTemplateController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamTemplateController.java @@ -119,36 +119,20 @@ public class ExamTemplateController extends EntityController notifyCreated(final ExamTemplate entity) { - return notifyExamTemplateChange(entity); + return notifyExamTemplateChange(entity, ExamTemplateChangeEvent.ChangeState.CREATED); } @Override protected Result notifySaved(final ExamTemplate entity) { - return notifyExamTemplateChange(entity); - } - - private Result notifyExamTemplateChange(final ExamTemplate entity) { - try { - applicationEventPublisher.publishEvent(new ExamTemplateChangeEvent(entity)); - } catch (final Exception e) { - log.error("Failed to notify ExamTemplate change: ", e); - } - return Result.of(entity); + return notifyExamTemplateChange(entity, ExamTemplateChangeEvent.ChangeState.MODIFIED); } @Override protected Result> notifyDeleted(final Pair pair) { + notifyExamTemplateChange(pair.a, ExamTemplateChangeEvent.ChangeState.DELETED); return super.notifyDeleted(pair); } - private void notifyChanged(final ExamTemplate examTemplate) { - try { - applicationEventPublisher.publishEvent(new ExamTemplateChangeEvent(examTemplate)); - } catch (final Exception e) { - log.error("Failed to notify Exam Template change: ", e); - } - } - private ExamTemplate applyQuitPasswordIfNeeded(final ExamTemplate entity) { if (entity.configTemplateId != null) { try { @@ -637,4 +621,15 @@ public class ExamTemplateController extends EntityController notifyExamTemplateChange( + final ExamTemplate entity, + final ExamTemplateChangeEvent.ChangeState changeState) { + try { + applicationEventPublisher.publishEvent(new ExamTemplateChangeEvent(entity, changeState)); + } catch (final Exception e) { + log.error("Failed to notify ExamTemplate change: ", e); + } + return Result.of(entity); + } + }