SEBSERV-417 apply exam_data before SEB restriction
This commit is contained in:
parent
8238361910
commit
df78a6a2a4
5 changed files with 54 additions and 48 deletions
|
@ -247,7 +247,10 @@ public class ExamAdminServiceImpl implements ExamAdminService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Exam> applyQuitPassword(final Exam exam) {
|
public Result<Exam> applyQuitPassword(final Exam exam) {
|
||||||
return this.sebRestrictionService.applyQuitPassword(exam);
|
return this.examConfigurationValueService
|
||||||
|
.applyQuitPasswordToConfigs(exam.id, exam.quitPassword)
|
||||||
|
.onError(t -> log.error("Failed to quit password for Exam: {}", exam, t))
|
||||||
|
.map(id -> exam);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,6 +27,7 @@ import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||||
import ch.ethz.seb.sebserver.gbl.util.Utils;
|
import ch.ethz.seb.sebserver.gbl.util.Utils;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.AdditionalAttributesDAO;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.AdditionalAttributesDAO;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO;
|
||||||
|
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamAdminService;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamImportService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamImportService;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamTemplateService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamTemplateService;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPIService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPIService;
|
||||||
|
@ -50,7 +51,7 @@ public class ExamImportServiceImpl implements ExamImportService {
|
||||||
|
|
||||||
private final ExamDAO examDAO;
|
private final ExamDAO examDAO;
|
||||||
private final ExamTemplateService examTemplateService;
|
private final ExamTemplateService examTemplateService;
|
||||||
private final SEBRestrictionService sebRestrictionService;
|
private final ExamAdminService examAdminService;
|
||||||
private final boolean appSignatureKeyEnabled;
|
private final boolean appSignatureKeyEnabled;
|
||||||
private final int defaultNumericalTrustThreshold;
|
private final int defaultNumericalTrustThreshold;
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ public class ExamImportServiceImpl implements ExamImportService {
|
||||||
final ExamDAO examDAO,
|
final ExamDAO examDAO,
|
||||||
final ExamTemplateService examTemplateService,
|
final ExamTemplateService examTemplateService,
|
||||||
final SEBRestrictionService sebRestrictionService,
|
final SEBRestrictionService sebRestrictionService,
|
||||||
|
final ExamAdminService examAdminService,
|
||||||
final AdditionalAttributesDAO additionalAttributesDAO,
|
final AdditionalAttributesDAO additionalAttributesDAO,
|
||||||
final LmsAPIService lmsAPIService,
|
final LmsAPIService lmsAPIService,
|
||||||
final @Value("${sebserver.webservice.api.admin.exam.app.signature.key.enabled:false}") boolean appSignatureKeyEnabled,
|
final @Value("${sebserver.webservice.api.admin.exam.app.signature.key.enabled:false}") boolean appSignatureKeyEnabled,
|
||||||
|
@ -65,7 +67,7 @@ public class ExamImportServiceImpl implements ExamImportService {
|
||||||
|
|
||||||
this.examDAO = examDAO;
|
this.examDAO = examDAO;
|
||||||
this.examTemplateService = examTemplateService;
|
this.examTemplateService = examTemplateService;
|
||||||
this.sebRestrictionService = sebRestrictionService;
|
this.examAdminService = examAdminService;
|
||||||
this.additionalAttributesDAO = additionalAttributesDAO;
|
this.additionalAttributesDAO = additionalAttributesDAO;
|
||||||
this.lmsAPIService = lmsAPIService;
|
this.lmsAPIService = lmsAPIService;
|
||||||
this.appSignatureKeyEnabled = appSignatureKeyEnabled;
|
this.appSignatureKeyEnabled = appSignatureKeyEnabled;
|
||||||
|
@ -99,7 +101,7 @@ public class ExamImportServiceImpl implements ExamImportService {
|
||||||
})
|
})
|
||||||
.flatMap(this::applyAdditionalSEBRestrictions)
|
.flatMap(this::applyAdditionalSEBRestrictions)
|
||||||
.onError(error -> errors.add(APIMessage.ErrorMessage.EXAM_IMPORT_ERROR_AUTO_RESTRICTION.of(error)))
|
.onError(error -> errors.add(APIMessage.ErrorMessage.EXAM_IMPORT_ERROR_AUTO_RESTRICTION.of(error)))
|
||||||
.flatMap(sebRestrictionService::applyQuitPassword)
|
.flatMap(examAdminService::applyQuitPassword)
|
||||||
.onError(error -> errors.add(APIMessage.ErrorMessage.EXAM_IMPORT_ERROR_QUIT_PASSWORD.of(error)))
|
.onError(error -> errors.add(APIMessage.ErrorMessage.EXAM_IMPORT_ERROR_QUIT_PASSWORD.of(error)))
|
||||||
.flatMap(examTemplateService::applyScreenProctoringSettingsForExam)
|
.flatMap(examTemplateService::applyScreenProctoringSettingsForExam)
|
||||||
.onError(error -> errors.add(APIMessage.ErrorMessage.EXAM_IMPORT_ERROR_SCREEN_PROCTORING_SETTINGS.of(error)));
|
.onError(error -> errors.add(APIMessage.ErrorMessage.EXAM_IMPORT_ERROR_SCREEN_PROCTORING_SETTINGS.of(error)));
|
||||||
|
|
|
@ -52,6 +52,16 @@ public interface SEBRestrictionService {
|
||||||
* @return Result refer to the Exam instance or to an error if happened */
|
* @return Result refer to the Exam instance or to an error if happened */
|
||||||
Result<Exam> applySEBClientRestriction(Exam exam);
|
Result<Exam> applySEBClientRestriction(Exam exam);
|
||||||
|
|
||||||
|
default Result<Exam> applySEBRestrictionIfExamRunning(final Exam exam) {
|
||||||
|
return Result.tryCatch(() -> {
|
||||||
|
if (exam.status != Exam.ExamStatus.RUNNING) {
|
||||||
|
return exam;
|
||||||
|
}
|
||||||
|
|
||||||
|
return applySEBClientRestriction(exam).getOrThrow();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Release SEB Client restriction within the LMS API for a specified Exam.
|
/** Release SEB Client restriction within the LMS API for a specified Exam.
|
||||||
*
|
*
|
||||||
* @param exam the Exam instance
|
* @param exam the Exam instance
|
||||||
|
@ -68,8 +78,6 @@ public interface SEBRestrictionService {
|
||||||
* to the LMS */
|
* to the LMS */
|
||||||
boolean checkSebRestrictionSet(Exam exam);
|
boolean checkSebRestrictionSet(Exam exam);
|
||||||
|
|
||||||
Result<Exam> applyQuitPassword(final Exam exam);
|
|
||||||
|
|
||||||
@EventListener
|
@EventListener
|
||||||
void notifyLmsSetupChange(final LmsSetupChangeEvent event);
|
void notifyLmsSetupChange(final LmsSetupChangeEvent event);
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
|
|
||||||
package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl;
|
package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl;
|
||||||
|
|
||||||
import static ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.LmsSetupRecordDynamicSqlSupport.lmsType;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -22,7 +20,6 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import ch.ethz.seb.sebserver.gbl.model.Activatable;
|
import ch.ethz.seb.sebserver.gbl.model.Activatable;
|
||||||
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.AdditionalAttributeRecord;
|
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.AdditionalAttributeRecord;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamConfigurationValueService;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -62,20 +59,17 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService {
|
||||||
private final LmsAPIService lmsAPIService;
|
private final LmsAPIService lmsAPIService;
|
||||||
private final AdditionalAttributesDAO additionalAttributesDAO;
|
private final AdditionalAttributesDAO additionalAttributesDAO;
|
||||||
private final ExamConfigService examConfigService;
|
private final ExamConfigService examConfigService;
|
||||||
private final ExamConfigurationValueService examConfigurationValueService;
|
|
||||||
|
|
||||||
protected SEBRestrictionServiceImpl(
|
protected SEBRestrictionServiceImpl(
|
||||||
final ExamDAO examDAO,
|
final ExamDAO examDAO,
|
||||||
final LmsAPIService lmsAPIService,
|
final LmsAPIService lmsAPIService,
|
||||||
final AdditionalAttributesDAO additionalAttributesDAO,
|
final AdditionalAttributesDAO additionalAttributesDAO,
|
||||||
final ExamConfigService examConfigService,
|
final ExamConfigService examConfigService) {
|
||||||
final ExamConfigurationValueService examConfigurationValueService) {
|
|
||||||
|
|
||||||
this.examDAO = examDAO;
|
this.examDAO = examDAO;
|
||||||
this.lmsAPIService = lmsAPIService;
|
this.lmsAPIService = lmsAPIService;
|
||||||
this.additionalAttributesDAO = additionalAttributesDAO;
|
this.additionalAttributesDAO = additionalAttributesDAO;
|
||||||
this.examConfigService = examConfigService;
|
this.examConfigService = examConfigService;
|
||||||
this.examConfigurationValueService = examConfigurationValueService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,13 +95,13 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// @Override
|
||||||
public Result<Exam> applyQuitPassword(final Exam exam) {
|
// public Result<Exam> applyQuitPassword(final Exam exam) {
|
||||||
return this.examConfigurationValueService
|
// return this.examConfigurationValueService
|
||||||
.applyQuitPasswordToConfigs(exam.id, exam.quitPassword)
|
// .applyQuitPasswordToConfigs(exam.id, exam.quitPassword)
|
||||||
.map(id -> applyQuitPasswordWithRestrictionIfNeeded(exam))
|
// .map(id -> applyQuitPasswordWithRestrictionIfNeeded(exam))
|
||||||
.onError(t -> log.error("Failed to quit password for Exam: {}", exam, t));
|
// .onError(t -> log.error("Failed to quit password for Exam: {}", exam, t));
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyLmsSetupChange(final LmsSetupChangeEvent event) {
|
public void notifyLmsSetupChange(final LmsSetupChangeEvent event) {
|
||||||
|
@ -122,11 +116,8 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService {
|
||||||
examDAO.allActiveForLMSSetup(Arrays.asList(lmsSetup.id))
|
examDAO.allActiveForLMSSetup(Arrays.asList(lmsSetup.id))
|
||||||
.getOrThrow()
|
.getOrThrow()
|
||||||
.forEach(exam -> {
|
.forEach(exam -> {
|
||||||
try {
|
this.applySEBRestrictionIfExamRunning(exam)
|
||||||
this.applySEBRestrictionIfExamRunning(exam);
|
.onError(error -> log.warn("Failed to update SEB restriction for exam: {} error: {}", exam.name, error.getMessage()));
|
||||||
} catch (final Exception e) {
|
|
||||||
log.warn("Failed to update SEB restriction for exam: {} error: {}", exam.name, e.getMessage());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else if (event.activation == Activatable.ActivationAction.DEACTIVATE) {
|
} else if (event.activation == Activatable.ActivationAction.DEACTIVATE) {
|
||||||
releaseAllRestrictionsOf(lmsSetup)
|
releaseAllRestrictionsOf(lmsSetup)
|
||||||
|
@ -161,29 +152,29 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Exam applyQuitPasswordWithRestrictionIfNeeded(final Exam exam) {
|
// private Exam applyQuitPasswordWithRestrictionIfNeeded(final Exam exam) {
|
||||||
if (exam.status != Exam.ExamStatus.RUNNING) {
|
// if (exam.status != Exam.ExamStatus.RUNNING) {
|
||||||
return exam;
|
// return exam;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// final LmsSetup lmsSetup = getLmsAPIService().getLmsSetup(exam.lmsSetupId).getOrThrow();
|
||||||
|
// if (!lmsSetup.lmsType.features.contains(Features.LMS_FULL_INTEGRATION)) {
|
||||||
|
// applySEBRestrictionIfExamRunning(exam);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return exam;
|
||||||
|
// }
|
||||||
|
|
||||||
final LmsSetup lmsSetup = getLmsAPIService().getLmsSetup(exam.lmsSetupId).getOrThrow();
|
// private Exam applySEBRestrictionIfExamRunning(final Exam exam) {
|
||||||
if (!lmsSetup.lmsType.features.contains(Features.LMS_FULL_INTEGRATION)) {
|
// if (exam.status != Exam.ExamStatus.RUNNING) {
|
||||||
applySEBRestrictionIfExamRunning(exam);
|
// return exam;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return exam;
|
// return this.applySEBClientRestriction(exam)
|
||||||
}
|
// .flatMap(e -> this.examDAO.setSEBRestriction(e.id, true))
|
||||||
|
// .onError(t -> log.error("Failed to update SEB Client restriction for Exam: {}", exam, t))
|
||||||
private Exam applySEBRestrictionIfExamRunning(final Exam exam) {
|
// .getOrThrow();
|
||||||
if (exam.status != Exam.ExamStatus.RUNNING) {
|
// }
|
||||||
return exam;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.applySEBClientRestriction(exam)
|
|
||||||
.flatMap(e -> this.examDAO.setSEBRestriction(e.id, true))
|
|
||||||
.onError(t -> log.error("Failed to update SEB Client restriction for Exam: {}", exam, t))
|
|
||||||
.getOrThrow();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|
|
@ -616,7 +616,9 @@ public class ExamAdministrationController extends EntityController<Exam, Exam> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Result<Exam> notifyCreated(final Exam entity) {
|
protected Result<Exam> notifyCreated(final Exam entity) {
|
||||||
return examImportService.applyExamImportInitialization(entity);
|
return examImportService.applyExamImportInitialization(entity)
|
||||||
|
.flatMap(this.fullLmsIntegrationService::applyExamDataToLMS)
|
||||||
|
.flatMap(this.sebRestrictionService::applySEBRestrictionIfExamRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue