Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev-2.0' into development
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
#	src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ExamDAO.java
  • Loading branch information
anhefti committed Sep 25, 2024
2 parents 1d3a856 + e4c24e8 commit bdda9e2
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,6 @@ default Result<Exam> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exam> setSEBRestriction(final Long examId, final boolean sebRestriction) {
return this.examRecordDAO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -320,24 +321,33 @@ public Result<ExamRecord> 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<MyBatis3UpdateModelAdapter<Integer>> 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);
})
Expand Down Expand Up @@ -588,6 +598,22 @@ public Result<Collection<ExamRecord>> allOf(final Set<Long> pks) {
});
}

@Transactional
public Result<ExamRecord> 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
Expand All @@ -599,3 +625,4 @@ private String getEncryptedQuitPassword(final String pwd) {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,21 @@ public Result<Long> 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);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,11 @@ public Result<Exam> saveSEBRestrictionToExam(final Exam exam, final SEBRestricti
return Result.tryCatch(() -> {
// save Browser Exam Keys
final Collection<String> 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
Expand Down

0 comments on commit bdda9e2

Please sign in to comment.