Skip to content

Commit

Permalink
Merge branch 'development' of github.com:SafeExamBrowser/seb-server i…
Browse files Browse the repository at this point in the history
…nto SEBSP-131
  • Loading branch information
Nadim Ritter committed Jul 2, 2024
2 parents 205e9b2 + 900bbfe commit bda460c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,6 @@ private Exam applyExamData(final Exam exam, final boolean deletion) {
if (!hasFullIntegration(exam.lmsSetupId)) {
return exam;
}
if (exam.examTemplateId == null) {
throw new IllegalStateException("Exam has no template id: " + exam.getName());
}

try {

Expand All @@ -569,7 +566,11 @@ private Exam applyExamData(final Exam exam, final boolean deletion) {
final String courseId = lmsAPITemplate.getCourseIdFromExam(exam);
final String quizId = lmsAPITemplate.getQuizIdFromExam(exam);

final String templateId = deletion ? null : String.valueOf(exam.examTemplateId);
final String templateId = deletion
? null
: exam.examTemplateId != null
? String.valueOf(exam.examTemplateId)
: "0";
final String quitPassword = deletion ? null : examConfigurationValueService.getQuitPassword(exam.id);
final String quitLink = deletion ? null : examConfigurationValueService.getQuitLink(exam.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,36 +119,20 @@ protected Result<ExamTemplate> validForSave(final ExamTemplate entity) {

@Override
protected Result<ExamTemplate> notifyCreated(final ExamTemplate entity) {
return notifyExamTemplateChange(entity);
return notifyExamTemplateChange(entity, ExamTemplateChangeEvent.ChangeState.CREATED);
}

@Override
protected Result<ExamTemplate> notifySaved(final ExamTemplate entity) {
return notifyExamTemplateChange(entity);
}

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);
return notifyExamTemplateChange(entity, ExamTemplateChangeEvent.ChangeState.MODIFIED);
}

@Override
protected Result<Pair<ExamTemplate, EntityProcessingReport>> notifyDeleted(final Pair<ExamTemplate, EntityProcessingReport> 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 {
Expand Down Expand Up @@ -637,4 +621,15 @@ private IndicatorTemplate checkIndicatorConsistency(final IndicatorTemplate indi
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);
}

}

0 comments on commit bda460c

Please sign in to comment.