SEBSERV-556 fixed notify exam template deletion to moodle

This commit is contained in:
anhefti 2024-07-01 12:23:31 +02:00
parent b0617803f1
commit ee89d2a24e
2 changed files with 24 additions and 20 deletions

View file

@ -14,10 +14,19 @@ import org.springframework.context.ApplicationEvent;
public class ExamTemplateChangeEvent extends ApplicationEvent { public class ExamTemplateChangeEvent extends ApplicationEvent {
public static enum ChangeState {
CREATED,
MODIFIED,
DELETED,
}
private static final long serialVersionUID = -7239994198026689531L; 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); super(source);
this.changeState = changeState;
} }
public ExamTemplate getExamTemplate() { public ExamTemplate getExamTemplate() {

View file

@ -119,36 +119,20 @@ public class ExamTemplateController extends EntityController<ExamTemplate, ExamT
@Override @Override
protected Result<ExamTemplate> notifyCreated(final ExamTemplate entity) { protected Result<ExamTemplate> notifyCreated(final ExamTemplate entity) {
return notifyExamTemplateChange(entity); return notifyExamTemplateChange(entity, ExamTemplateChangeEvent.ChangeState.CREATED);
} }
@Override @Override
protected Result<ExamTemplate> notifySaved(final ExamTemplate entity) { protected Result<ExamTemplate> notifySaved(final ExamTemplate entity) {
return notifyExamTemplateChange(entity); return notifyExamTemplateChange(entity, ExamTemplateChangeEvent.ChangeState.MODIFIED);
}
private Result<ExamTemplate> 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);
} }
@Override @Override
protected Result<Pair<ExamTemplate, EntityProcessingReport>> notifyDeleted(final Pair<ExamTemplate, EntityProcessingReport> pair) { protected Result<Pair<ExamTemplate, EntityProcessingReport>> notifyDeleted(final Pair<ExamTemplate, EntityProcessingReport> pair) {
notifyExamTemplateChange(pair.a, ExamTemplateChangeEvent.ChangeState.DELETED);
return super.notifyDeleted(pair); 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) { private ExamTemplate applyQuitPasswordIfNeeded(final ExamTemplate entity) {
if (entity.configTemplateId != null) { if (entity.configTemplateId != null) {
try { try {
@ -637,4 +621,15 @@ public class ExamTemplateController extends EntityController<ExamTemplate, ExamT
return indicatorTemplate; return indicatorTemplate;
} }
private Result<ExamTemplate> 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);
}
} }