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 | ||||
|     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 | ||||
|  |  | |||
|  | @ -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.webservice.servicelayer.dao.AdditionalAttributesDAO; | ||||
| 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.ExamTemplateService; | ||||
| import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPIService; | ||||
|  | @ -50,7 +51,7 @@ public class ExamImportServiceImpl implements ExamImportService { | |||
| 
 | ||||
|     private final ExamDAO examDAO; | ||||
|     private final ExamTemplateService examTemplateService; | ||||
|     private final SEBRestrictionService sebRestrictionService; | ||||
|     private final ExamAdminService examAdminService; | ||||
|     private final boolean appSignatureKeyEnabled; | ||||
|     private final int defaultNumericalTrustThreshold; | ||||
| 
 | ||||
|  | @ -58,6 +59,7 @@ public class ExamImportServiceImpl implements ExamImportService { | |||
|             final ExamDAO examDAO, | ||||
|             final ExamTemplateService examTemplateService, | ||||
|             final SEBRestrictionService sebRestrictionService, | ||||
|             final ExamAdminService examAdminService, | ||||
|             final AdditionalAttributesDAO additionalAttributesDAO, | ||||
|             final LmsAPIService lmsAPIService, | ||||
|             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.examTemplateService = examTemplateService; | ||||
|         this.sebRestrictionService = sebRestrictionService; | ||||
|         this.examAdminService = examAdminService; | ||||
|         this.additionalAttributesDAO = additionalAttributesDAO; | ||||
|         this.lmsAPIService = lmsAPIService; | ||||
|         this.appSignatureKeyEnabled = appSignatureKeyEnabled; | ||||
|  | @ -99,7 +101,7 @@ public class ExamImportServiceImpl implements ExamImportService { | |||
|                 }) | ||||
|                 .flatMap(this::applyAdditionalSEBRestrictions) | ||||
|                 .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))) | ||||
|                 .flatMap(examTemplateService::applyScreenProctoringSettingsForExam) | ||||
|                 .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 */ | ||||
|     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. | ||||
|      * | ||||
|      * @param exam the Exam instance | ||||
|  | @ -68,8 +78,6 @@ public interface SEBRestrictionService { | |||
|      *         to the LMS */ | ||||
|     boolean checkSebRestrictionSet(Exam exam); | ||||
| 
 | ||||
|     Result<Exam> applyQuitPassword(final Exam exam); | ||||
| 
 | ||||
|     @EventListener | ||||
|     void notifyLmsSetupChange(final LmsSetupChangeEvent event); | ||||
| 
 | ||||
|  |  | |||
|  | @ -8,8 +8,6 @@ | |||
| 
 | ||||
| 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.Arrays; | ||||
| 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.webservice.datalayer.batis.model.AdditionalAttributeRecord; | ||||
| import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamConfigurationValueService; | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | @ -62,20 +59,17 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService { | |||
|     private final LmsAPIService lmsAPIService; | ||||
|     private final AdditionalAttributesDAO additionalAttributesDAO; | ||||
|     private final ExamConfigService examConfigService; | ||||
|     private final ExamConfigurationValueService examConfigurationValueService; | ||||
| 
 | ||||
|     protected SEBRestrictionServiceImpl( | ||||
|             final ExamDAO examDAO, | ||||
|             final LmsAPIService lmsAPIService, | ||||
|             final AdditionalAttributesDAO additionalAttributesDAO, | ||||
|             final ExamConfigService examConfigService, | ||||
|             final ExamConfigurationValueService examConfigurationValueService) { | ||||
|             final ExamConfigService examConfigService) { | ||||
| 
 | ||||
|         this.examDAO = examDAO; | ||||
|         this.lmsAPIService = lmsAPIService; | ||||
|         this.additionalAttributesDAO = additionalAttributesDAO; | ||||
|         this.examConfigService = examConfigService; | ||||
|         this.examConfigurationValueService = examConfigurationValueService; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | @ -101,13 +95,13 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService { | |||
|         return true; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public Result<Exam> applyQuitPassword(final Exam exam) { | ||||
|         return this.examConfigurationValueService | ||||
|                 .applyQuitPasswordToConfigs(exam.id, exam.quitPassword) | ||||
|                 .map(id -> applyQuitPasswordWithRestrictionIfNeeded(exam)) | ||||
|                 .onError(t -> log.error("Failed to quit password for Exam: {}", exam, t)); | ||||
|     } | ||||
| //    @Override | ||||
| //    public Result<Exam> applyQuitPassword(final Exam exam) { | ||||
| //        return this.examConfigurationValueService | ||||
| //                .applyQuitPasswordToConfigs(exam.id, exam.quitPassword) | ||||
| //                .map(id -> applyQuitPasswordWithRestrictionIfNeeded(exam)) | ||||
| //                .onError(t -> log.error("Failed to quit password for Exam: {}", exam, t)); | ||||
| //    } | ||||
| 
 | ||||
|     @Override | ||||
|     public void notifyLmsSetupChange(final LmsSetupChangeEvent event) { | ||||
|  | @ -122,11 +116,8 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService { | |||
|                 examDAO.allActiveForLMSSetup(Arrays.asList(lmsSetup.id)) | ||||
|                         .getOrThrow() | ||||
|                         .forEach(exam -> { | ||||
|                             try { | ||||
|                                 this.applySEBRestrictionIfExamRunning(exam); | ||||
|                             } catch (final Exception e) { | ||||
|                                 log.warn("Failed to update SEB restriction for exam: {} error: {}", exam.name, e.getMessage()); | ||||
|                             } | ||||
|                             this.applySEBRestrictionIfExamRunning(exam) | ||||
|                                     .onError(error -> log.warn("Failed to update SEB restriction for exam: {} error: {}", exam.name, error.getMessage())); | ||||
|                         }); | ||||
|             } else if (event.activation == Activatable.ActivationAction.DEACTIVATE) { | ||||
|                 releaseAllRestrictionsOf(lmsSetup) | ||||
|  | @ -161,29 +152,29 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService { | |||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     private Exam applyQuitPasswordWithRestrictionIfNeeded(final Exam exam) { | ||||
|         if (exam.status != Exam.ExamStatus.RUNNING) { | ||||
|             return exam; | ||||
|         } | ||||
| //    private Exam applyQuitPasswordWithRestrictionIfNeeded(final Exam exam) { | ||||
| //        if (exam.status != Exam.ExamStatus.RUNNING) { | ||||
| //            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(); | ||||
|         if (!lmsSetup.lmsType.features.contains(Features.LMS_FULL_INTEGRATION)) { | ||||
|             applySEBRestrictionIfExamRunning(exam); | ||||
|         } | ||||
| 
 | ||||
|         return exam; | ||||
|     } | ||||
| 
 | ||||
|     private Exam applySEBRestrictionIfExamRunning(final Exam exam) { | ||||
|         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(); | ||||
|     } | ||||
| //    private Exam applySEBRestrictionIfExamRunning(final Exam exam) { | ||||
| //        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 | ||||
|     @Transactional | ||||
|  |  | |||
|  | @ -616,7 +616,9 @@ public class ExamAdministrationController extends EntityController<Exam, Exam> { | |||
| 
 | ||||
|     @Override | ||||
|     protected Result<Exam> notifyCreated(final Exam entity) { | ||||
|         return examImportService.applyExamImportInitialization(entity); | ||||
|         return examImportService.applyExamImportInitialization(entity) | ||||
|                 .flatMap(this.fullLmsIntegrationService::applyExamDataToLMS) | ||||
|                 .flatMap(this.sebRestrictionService::applySEBRestrictionIfExamRunning); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 anhefti
						anhefti