From c81d5dadbfd4852c965b0002c212d4e4ffd47ec0 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 2 Sep 2024 15:11:45 +0200 Subject: [PATCH 1/3] prepare for next patch release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4cb2d09f0..ec47f0aac 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ jar - 2.0.0 + 2.0.1 ${sebserver-version} ${sebserver-version} UTF-8 From 2c3603338d583b5d2cf5dea8b4bbf33c1d28d109 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 25 Sep 2024 10:13:45 +0200 Subject: [PATCH 2/3] SEBSERV-595 fixed --- .../servicelayer/dao/impl/ExamRecordDAO.java | 46 +++++++++++-------- .../ExamConfigurationValueServiceImpl.java | 9 ++-- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java index 8dcc4119d..18637324a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java @@ -23,6 +23,7 @@ import org.mybatis.dynamic.sql.SqlCriterion; import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter; import org.mybatis.dynamic.sql.select.QueryExpressionDSL; +import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter; import org.mybatis.dynamic.sql.update.UpdateDSL; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -320,24 +321,33 @@ public Result save(final Exam exam) { exam.status); } - UpdateDSL.updateWithMapper(examRecordMapper::update, examRecord) - .set(supporter).equalTo((exam.supporter != null) - ? StringUtils.join(exam.supporter, Constants.LIST_SEPARATOR_CHAR) - : null) - .set(type).equalTo((exam.type != null) - ? exam.type.name() - : ExamType.UNDEFINED.name()) - .set(quitPassword).equalTo(getEncryptedQuitPassword(exam.quitPassword)) - .set(browserKeys).equalToWhenPresent(exam.browserExamKeys) - .set(lmsSebRestriction).equalTo(1) // seb restriction (deprecated) - .set(examTemplateId).equalTo(oldRecord.getExamTemplateId()) - .set(lastModified).equalTo(Utils.getMillisecondsNow()) - .set(quizName).equalToWhenPresent(exam.lmsSetupId == null ? exam.name : null) - .set(quizStartTime).equalToWhenPresent(exam.lmsSetupId == null ? exam.startTime : null) - .set(quizEndTime).equalToWhenPresent(exam.lmsSetupId == null ? exam.endTime : null) - .where(id, isEqualTo(exam.id)) - .build() - .execute(); + final UpdateDSL> clause = UpdateDSL.updateWithMapper( + examRecordMapper::update, + examRecord) + .set(supporter).equalTo((exam.supporter != null) + ? StringUtils.join(exam.supporter, Constants.LIST_SEPARATOR_CHAR) + : null) + .set(type).equalTo((exam.type != null) + ? exam.type.name() + : ExamType.UNDEFINED.name()) + .set(browserKeys).equalToWhenPresent(exam.browserExamKeys) + .set(lmsSebRestriction).equalTo(1) // seb restriction (deprecated) + .set(examTemplateId).equalTo(oldRecord.getExamTemplateId()) + .set(lastModified).equalTo(Utils.getMillisecondsNow()) + .set(quizName).equalToWhenPresent(exam.lmsSetupId == null ? exam.name : null) + .set(quizStartTime).equalToWhenPresent(exam.lmsSetupId == null ? exam.startTime : null) + .set(quizEndTime).equalToWhenPresent(exam.lmsSetupId == null ? exam.endTime : null); + + if (StringUtils.isBlank(exam.quitPassword)) { + clause.set(quitPassword).equalToNull(); + } else { + clause.set(quitPassword).equalTo(getEncryptedQuitPassword(exam.quitPassword)); + } + + clause + .where(id, isEqualTo(exam.id)) + .build() + .execute(); return this.examRecordMapper.selectByPrimaryKey(exam.id); }) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamConfigurationValueServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamConfigurationValueServiceImpl.java index 226bd39fd..d59798d78 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamConfigurationValueServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/impl/ExamConfigurationValueServiceImpl.java @@ -141,18 +141,21 @@ public Result applyQuitPasswordToConfigs(final Long examId, final String q return Result.tryCatch(() -> { final String oldQuitPassword = this.getQuitPassword(examId); - final String newQuitPassword = quitSecret != null + final String newQuitPassword = StringUtils.isNotBlank(quitSecret) ? this.cryptor .decrypt(quitSecret) .getOr(quitSecret) .toString() - : null; + : StringUtils.EMPTY; if (Objects.equals(oldQuitPassword, newQuitPassword)) { return examId; } - return saveSEBAttributeValueToConfig(examId, CONFIG_ATTR_NAME_QUIT_SECRET, quitSecret); + return saveSEBAttributeValueToConfig( + examId, + CONFIG_ATTR_NAME_QUIT_SECRET, + StringUtils.isBlank(quitSecret) ? StringUtils.EMPTY : quitSecret); }); } From e4c24e8f4493c07d1e0be14a9d393bbaeedb6001 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 25 Sep 2024 11:32:19 +0200 Subject: [PATCH 3/3] SEBSERV-585 fixed by saving BEK separately --- .../sebserver/gui/content/exam/ExamForm.java | 2 -- .../webservice/servicelayer/dao/ExamDAO.java | 4 ++-- .../servicelayer/dao/impl/ExamDAOImpl.java | 7 +++++++ .../servicelayer/dao/impl/ExamRecordDAO.java | 17 +++++++++++++++++ .../lms/impl/SEBRestrictionServiceImpl.java | 15 +++------------ 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java index 1f7e38162..445d5f68e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java @@ -195,8 +195,6 @@ public void compose(final PageContext pageContext) { .onError(error -> pageContext.notifyLoadError(EntityType.EXAM, error)) .getOrThrow(); - - // new PageContext with actual EntityKey final EntityKey entityKey = (readonly || !newExamNoLMS) ? pageContext.getEntityKey() : null; final PageContext formContext = pageContext.withEntityKey(exam.getEntityKey()); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java index ac504cec7..be4ed8f3d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java @@ -249,6 +249,6 @@ default Result releaseLock(final Exam exam, final String updateId) { void markLMSAvailability(final String externalQuizId, final boolean available, final String updateId); void updateQuitPassword(Exam exam, String quitPassword); - - + + void saveBrowserExamKeys(Long examId, String bek); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java index 0a9ddbba8..1753c49d9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java @@ -248,6 +248,13 @@ public void updateQuitPassword(final Exam exam, final String quitPassword) { .onError(err -> log.error("Failed to update quit password on exam: {}", exam, err)); } + @Override + public void saveBrowserExamKeys(final Long examId, final String bek) { + this.examRecordDAO + .saveBrowserExamKeys(examId, bek) + .onError(err -> log.error("Failed to update Browser Exam Keys on exam: {}", examId, err)); + } + @Override public Result setSEBRestriction(final Long examId, final boolean sebRestriction) { return this.examRecordDAO diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java index 18637324a..aa6db6b61 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java @@ -598,6 +598,22 @@ public Result> allOf(final Set pks) { }); } + @Transactional + public Result saveBrowserExamKeys(final Long examId, final String bek) { + return Result.tryCatch(() -> { + + UpdateDSL.updateWithMapper(examRecordMapper::update, ExamRecordDynamicSqlSupport.examRecord) + .set(browserKeys).equalTo(bek) + .set(lastModified).equalTo(Utils.getMillisecondsNow()) + .where(id, isEqualTo(examId)) + .build() + .execute(); + + return this.examRecordMapper.selectByPrimaryKey(examId); + }) + .onError(TransactionHandler::rollback); + } + private String getEncryptedQuitPassword(final String pwd) { return (StringUtils.isNotBlank(pwd)) ? this.cryptor @@ -609,3 +625,4 @@ private String getEncryptedQuitPassword(final String pwd) { } } + diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java index e1273c3f5..523b97c70 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java @@ -259,20 +259,11 @@ public Result saveSEBRestrictionToExam(final Exam exam, final SEBRestricti return Result.tryCatch(() -> { // save Browser Exam Keys final Collection browserExamKeys = sebRestriction.getBrowserExamKeys(); - final Exam newExam = new Exam( - exam.id, - null, null, null, null, null, null, null, null, null, - exam.supporter, - exam.status, - null, - null, + this.examDAO.saveBrowserExamKeys( + exam.id, (browserExamKeys != null && !browserExamKeys.isEmpty()) ? StringUtils.join(browserExamKeys, Constants.LIST_SEPARATOR_CHAR) - : StringUtils.EMPTY, - null, null, null, null, null); - - this.examDAO.save(newExam) - .getOrThrow(); + : StringUtils.EMPTY); // save additional restriction properties // remove old ones first by collecting its id's and then delete by id's