Skip to content

Commit e4c24e8

Browse files
committed
SEBSERV-585 fixed by saving BEK separately
1 parent 2c36033 commit e4c24e8

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamForm.java

-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ public void compose(final PageContext pageContext) {
195195
.onError(error -> pageContext.notifyLoadError(EntityType.EXAM, error))
196196
.getOrThrow();
197197

198-
199-
200198
// new PageContext with actual EntityKey
201199
final EntityKey entityKey = (readonly || !newExamNoLMS) ? pageContext.getEntityKey() : null;
202200
final PageContext formContext = pageContext.withEntityKey(exam.getEntityKey());

src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,6 @@ default Result<Exam> releaseLock(final Exam exam, final String updateId) {
249249
void markLMSAvailability(final String externalQuizId, final boolean available, final String updateId);
250250

251251
void updateQuitPassword(Exam exam, String quitPassword);
252-
253-
252+
253+
void saveBrowserExamKeys(Long examId, String bek);
254254
}

src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamDAOImpl.java

+7
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ public void updateQuitPassword(final Exam exam, final String quitPassword) {
248248
.onError(err -> log.error("Failed to update quit password on exam: {}", exam, err));
249249
}
250250

251+
@Override
252+
public void saveBrowserExamKeys(final Long examId, final String bek) {
253+
this.examRecordDAO
254+
.saveBrowserExamKeys(examId, bek)
255+
.onError(err -> log.error("Failed to update Browser Exam Keys on exam: {}", examId, err));
256+
}
257+
251258
@Override
252259
public Result<Exam> setSEBRestriction(final Long examId, final boolean sebRestriction) {
253260
return this.examRecordDAO

src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ExamRecordDAO.java

+17
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,22 @@ public Result<Collection<ExamRecord>> allOf(final Set<Long> pks) {
598598
});
599599
}
600600

601+
@Transactional
602+
public Result<ExamRecord> saveBrowserExamKeys(final Long examId, final String bek) {
603+
return Result.tryCatch(() -> {
604+
605+
UpdateDSL.updateWithMapper(examRecordMapper::update, ExamRecordDynamicSqlSupport.examRecord)
606+
.set(browserKeys).equalTo(bek)
607+
.set(lastModified).equalTo(Utils.getMillisecondsNow())
608+
.where(id, isEqualTo(examId))
609+
.build()
610+
.execute();
611+
612+
return this.examRecordMapper.selectByPrimaryKey(examId);
613+
})
614+
.onError(TransactionHandler::rollback);
615+
}
616+
601617
private String getEncryptedQuitPassword(final String pwd) {
602618
return (StringUtils.isNotBlank(pwd))
603619
? this.cryptor
@@ -609,3 +625,4 @@ private String getEncryptedQuitPassword(final String pwd) {
609625
}
610626

611627
}
628+

src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/SEBRestrictionServiceImpl.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,11 @@ public Result<Exam> saveSEBRestrictionToExam(final Exam exam, final SEBRestricti
259259
return Result.tryCatch(() -> {
260260
// save Browser Exam Keys
261261
final Collection<String> browserExamKeys = sebRestriction.getBrowserExamKeys();
262-
final Exam newExam = new Exam(
263-
exam.id,
264-
null, null, null, null, null, null, null, null, null,
265-
exam.supporter,
266-
exam.status,
267-
null,
268-
null,
262+
this.examDAO.saveBrowserExamKeys(
263+
exam.id,
269264
(browserExamKeys != null && !browserExamKeys.isEmpty())
270265
? StringUtils.join(browserExamKeys, Constants.LIST_SEPARATOR_CHAR)
271-
: StringUtils.EMPTY,
272-
null, null, null, null, null);
273-
274-
this.examDAO.save(newExam)
275-
.getOrThrow();
266+
: StringUtils.EMPTY);
276267

277268
// save additional restriction properties
278269
// remove old ones first by collecting its id's and then delete by id's

0 commit comments

Comments
 (0)