Skip to content

Commit

Permalink
SEBSERV-494 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
anhefti committed Nov 29, 2023
1 parent edf4706 commit 77198d4
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl;

import static ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ExamRecordDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import java.util.ArrayList;
Expand All @@ -25,6 +26,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.UpdateDSL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
Expand Down Expand Up @@ -88,7 +90,7 @@ public Result<Long> idByExternalQuizId(final String externalQuizId) {
return Result.tryCatch(() -> {
return this.examRecordMapper.selectIdsByExample()
.where(
ExamRecordDynamicSqlSupport.externalId,
externalId,
isEqualToWhenPresent(externalQuizId))
.build()
.execute()
Expand Down Expand Up @@ -126,7 +128,7 @@ public Result<Collection<Long>> allInstitutionIdsByQuizId(final String quizId) {
return Result.tryCatch(() -> {
return this.examRecordMapper.selectByExample()
.where(
ExamRecordDynamicSqlSupport.externalId,
externalId,
isEqualToWhenPresent(quizId))
.and(
ExamRecordDynamicSqlSupport.active,
Expand Down Expand Up @@ -314,20 +316,17 @@ public Result<ExamRecord> updateFromQuizData(
throw new IllegalStateException("Exam is currently locked: " + examId);
}

final ExamRecord examRecord = new ExamRecord(
examId,
null, null,
quizData.id,
null, null, null, null, null, null, null, null,
updateId,
null, null,
Utils.getMillisecondsNow(),
quizData.getName(),
quizData.getStartTime(),
quizData.getEndTime(),
BooleanUtils.toIntegerObject(true));
UpdateDSL.updateWithMapper(examRecordMapper::update, examRecord)
.set(externalId).equalTo(quizData.id)
.set(lastupdate).equalTo(updateId)
.set(lastModified).equalTo(Utils.getMillisecondsNow())
.set(quizName).equalTo(quizData.getName())
.set(quizStartTime).equalTo(quizData.getStartTime())
.set(quizEndTime).equalTo(quizData.getEndTime())
.where(id, isEqualTo(oldRecord::getId))
.build()
.execute();

this.examRecordMapper.updateByPrimaryKeySelective(examRecord);
return this.examRecordMapper.selectByPrimaryKey(examId);
})
.onError(TransactionHandler::rollback);
Expand Down Expand Up @@ -409,7 +408,7 @@ public Result<ExamRecord> createNew(final Exam exam) {
// fist check if it is not already existing
final List<ExamRecord> records = this.examRecordMapper.selectByExample()
.where(ExamRecordDynamicSqlSupport.lmsSetupId, isEqualTo(exam.lmsSetupId))
.and(ExamRecordDynamicSqlSupport.externalId, isEqualTo(exam.externalId))
.and(externalId, isEqualTo(exam.externalId))
.build()
.execute();

Expand Down

0 comments on commit 77198d4

Please sign in to comment.