SEBSERV-494 fixed

This commit is contained in:
anhefti 2023-11-29 19:38:57 +01:00
parent edf4706da7
commit 77198d41c6

View file

@ -8,6 +8,7 @@
package ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl; 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 static org.mybatis.dynamic.sql.SqlBuilder.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -25,6 +26,7 @@ import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.SqlCriterion; import org.mybatis.dynamic.sql.SqlCriterion;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter; import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL; import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -88,7 +90,7 @@ public class ExamRecordDAO {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
return this.examRecordMapper.selectIdsByExample() return this.examRecordMapper.selectIdsByExample()
.where( .where(
ExamRecordDynamicSqlSupport.externalId, externalId,
isEqualToWhenPresent(externalQuizId)) isEqualToWhenPresent(externalQuizId))
.build() .build()
.execute() .execute()
@ -126,7 +128,7 @@ public class ExamRecordDAO {
return Result.tryCatch(() -> { return Result.tryCatch(() -> {
return this.examRecordMapper.selectByExample() return this.examRecordMapper.selectByExample()
.where( .where(
ExamRecordDynamicSqlSupport.externalId, externalId,
isEqualToWhenPresent(quizId)) isEqualToWhenPresent(quizId))
.and( .and(
ExamRecordDynamicSqlSupport.active, ExamRecordDynamicSqlSupport.active,
@ -314,20 +316,17 @@ public class ExamRecordDAO {
throw new IllegalStateException("Exam is currently locked: " + examId); throw new IllegalStateException("Exam is currently locked: " + examId);
} }
final ExamRecord examRecord = new ExamRecord( UpdateDSL.updateWithMapper(examRecordMapper::update, examRecord)
examId, .set(externalId).equalTo(quizData.id)
null, null, .set(lastupdate).equalTo(updateId)
quizData.id, .set(lastModified).equalTo(Utils.getMillisecondsNow())
null, null, null, null, null, null, null, null, .set(quizName).equalTo(quizData.getName())
updateId, .set(quizStartTime).equalTo(quizData.getStartTime())
null, null, .set(quizEndTime).equalTo(quizData.getEndTime())
Utils.getMillisecondsNow(), .where(id, isEqualTo(oldRecord::getId))
quizData.getName(), .build()
quizData.getStartTime(), .execute();
quizData.getEndTime(),
BooleanUtils.toIntegerObject(true));
this.examRecordMapper.updateByPrimaryKeySelective(examRecord);
return this.examRecordMapper.selectByPrimaryKey(examId); return this.examRecordMapper.selectByPrimaryKey(examId);
}) })
.onError(TransactionHandler::rollback); .onError(TransactionHandler::rollback);
@ -409,7 +408,7 @@ public class ExamRecordDAO {
// fist check if it is not already existing // fist check if it is not already existing
final List<ExamRecord> records = this.examRecordMapper.selectByExample() final List<ExamRecord> records = this.examRecordMapper.selectByExample()
.where(ExamRecordDynamicSqlSupport.lmsSetupId, isEqualTo(exam.lmsSetupId)) .where(ExamRecordDynamicSqlSupport.lmsSetupId, isEqualTo(exam.lmsSetupId))
.and(ExamRecordDynamicSqlSupport.externalId, isEqualTo(exam.externalId)) .and(externalId, isEqualTo(exam.externalId))
.build() .build()
.execute(); .execute();