SEBSERV-457 check uses of lmsSetupId
This commit is contained in:
parent
cb9900a16d
commit
b4b5b6e410
4 changed files with 36 additions and 13 deletions
|
@ -409,18 +409,28 @@ public class ExamRecordDAO {
|
|||
return Result.tryCatch(() -> {
|
||||
|
||||
// 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))
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
// if there is already an existing imported exam for the quiz, this is
|
||||
// used to save instead of create a new one
|
||||
if (records != null && records.size() > 0) {
|
||||
final ExamRecord examRecord = records.get(0);
|
||||
// if the same institution tries to import an exam that already exists throw an error
|
||||
if (exam.institutionId.equals(examRecord.getInstitutionId())) {
|
||||
if (exam.lmsSetupId != null) {
|
||||
final List<ExamRecord> records = this.examRecordMapper.selectByExample()
|
||||
.where(lmsSetupId, isEqualTo(exam.lmsSetupId))
|
||||
.and(externalId, isEqualTo(exam.externalId))
|
||||
.build()
|
||||
.execute();
|
||||
// if there is already an existing imported exam for the quiz, this is
|
||||
// used to save instead of create a new one
|
||||
if (records != null && !records.isEmpty()) {
|
||||
final ExamRecord examRecord = records.get(0);
|
||||
// if the same institution tries to import an exam that already exists throw an error
|
||||
if (exam.institutionId.equals(examRecord.getInstitutionId())) {
|
||||
throw new DuplicateResourceException(EntityType.EXAM, exam.externalId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final Long nameCount = this.examRecordMapper.countByExample()
|
||||
.where(institutionId, isEqualTo(exam.institutionId))
|
||||
.and(quizName, isEqualTo(exam.name))
|
||||
.build()
|
||||
.execute();
|
||||
if (nameCount > 0) {
|
||||
throw new DuplicateResourceException(EntityType.EXAM, exam.externalId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ public class ExamAdminServiceImpl implements ExamAdminService {
|
|||
|
||||
@Override
|
||||
public Result<Boolean> isRestricted(final Exam exam) {
|
||||
if (exam == null) {
|
||||
if (exam == null || exam.lmsSetupId == null) {
|
||||
return Result.of(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,10 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService {
|
|||
|
||||
@Override
|
||||
public boolean checkSebRestrictionSet(final Exam exam) {
|
||||
if (exam == null || exam.lmsSetupId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final LmsSetup lmsSetup = this.lmsAPIService
|
||||
.getLmsSetup(exam.lmsSetupId)
|
||||
.getOr(null);
|
||||
|
@ -93,6 +97,10 @@ public class SEBRestrictionServiceImpl implements SEBRestrictionService {
|
|||
@Override
|
||||
@Transactional
|
||||
public Result<SEBRestriction> getSEBRestrictionFromExam(final Exam exam) {
|
||||
if (exam == null || exam.lmsSetupId == null) {
|
||||
return Result.ofError(new NoSEBRestrictionException("exam or lms setup has null reference"));
|
||||
}
|
||||
|
||||
return Result.tryCatch(() -> {
|
||||
// load the config keys from restriction and merge with new generated config keys
|
||||
final Collection<String> generatedKeys = this.examConfigService
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl.NoSEBRestrictionException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.mybatis.dynamic.sql.SqlTable;
|
||||
|
@ -735,6 +736,10 @@ public class ExamAdministrationController extends EntityController<Exam, Exam> {
|
|||
|
||||
private Result<Exam> applySEBRestriction(final Exam exam, final boolean restrict) {
|
||||
|
||||
if (exam == null || exam.lmsSetupId == null) {
|
||||
return Result.ofError(new NoSEBRestrictionException("exam or lms setup has null reference"));
|
||||
}
|
||||
|
||||
return Result.tryCatch(() -> {
|
||||
final LmsSetup lmsSetup = this.lmsAPIService.getLmsSetup(exam.lmsSetupId)
|
||||
.getOrThrow();
|
||||
|
|
Loading…
Reference in a new issue