SEBSERV-349 fixed
This commit is contained in:
parent
a6334bc436
commit
415dcee8cb
3 changed files with 18 additions and 8 deletions
|
@ -43,9 +43,9 @@ public class APIMessage implements Serializable {
|
||||||
RESOURCE_NOT_FOUND("1002", HttpStatus.NOT_FOUND, "resource not found"),
|
RESOURCE_NOT_FOUND("1002", HttpStatus.NOT_FOUND, "resource not found"),
|
||||||
ILLEGAL_API_ARGUMENT("1010", HttpStatus.BAD_REQUEST, "Illegal API request argument"),
|
ILLEGAL_API_ARGUMENT("1010", HttpStatus.BAD_REQUEST, "Illegal API request argument"),
|
||||||
UNEXPECTED("1100", HttpStatus.INTERNAL_SERVER_ERROR, "Unexpected internal server-side error"),
|
UNEXPECTED("1100", HttpStatus.INTERNAL_SERVER_ERROR, "Unexpected internal server-side error"),
|
||||||
|
INTEGRITY_VALIDATION("1101", HttpStatus.BAD_REQUEST, "Action would lied to an integrity violation"),
|
||||||
|
|
||||||
FIELD_VALIDATION("1200", HttpStatus.BAD_REQUEST, "Field validation error"),
|
FIELD_VALIDATION("1200", HttpStatus.BAD_REQUEST, "Field validation error"),
|
||||||
INTEGRITY_VALIDATION("1201", HttpStatus.BAD_REQUEST, "Action would lied to an integrity violation"),
|
|
||||||
PASSWORD_MISMATCH("1300", HttpStatus.BAD_REQUEST, "new password do not match confirmed password"),
|
PASSWORD_MISMATCH("1300", HttpStatus.BAD_REQUEST, "new password do not match confirmed password"),
|
||||||
MISSING_PASSWORD("1301", HttpStatus.BAD_REQUEST, "Missing Password"),
|
MISSING_PASSWORD("1301", HttpStatus.BAD_REQUEST, "Missing Password"),
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.Domain;
|
import ch.ethz.seb.sebserver.gbl.model.Domain;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
|
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport;
|
import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport;
|
||||||
|
import ch.ethz.seb.sebserver.gbl.model.Page;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamStatus;
|
import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamStatus;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.exam.ExamConfigurationMap;
|
import ch.ethz.seb.sebserver.gbl.model.exam.ExamConfigurationMap;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
|
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
|
||||||
|
@ -179,16 +180,24 @@ public class SEBExamConfigForm implements TemplateComposer {
|
||||||
.call()
|
.call()
|
||||||
.map(names -> names != null && !names.isEmpty())
|
.map(names -> names != null && !names.isEmpty())
|
||||||
.getOr(Boolean.FALSE);
|
.getOr(Boolean.FALSE);
|
||||||
final boolean hasRunningExam = isAttachedToExam && this.restService
|
final Result<Page<ExamConfigurationMap>> examsPage = this.restService
|
||||||
.getBuilder(GetExamConfigMappingsPage.class)
|
.getBuilder(GetExamConfigMappingsPage.class)
|
||||||
.withQueryParam(ExamConfigurationMap.FILTER_ATTR_CONFIG_ID, examConfig.getModelId())
|
.withQueryParam(ExamConfigurationMap.FILTER_ATTR_CONFIG_ID, examConfig.getModelId())
|
||||||
.call()
|
.call();
|
||||||
|
final boolean hasRunningExam = isAttachedToExam && examsPage
|
||||||
.map(res -> res.content
|
.map(res -> res.content
|
||||||
.stream()
|
.stream()
|
||||||
.filter(map -> map.examStatus == ExamStatus.RUNNING)
|
.filter(map -> map.examStatus == ExamStatus.RUNNING)
|
||||||
.findAny()
|
.findAny()
|
||||||
.isPresent())
|
.isPresent())
|
||||||
.getOr(false);
|
.getOr(false);
|
||||||
|
final boolean hasActiveExams = hasRunningExam || examsPage
|
||||||
|
.map(res -> res.content
|
||||||
|
.stream()
|
||||||
|
.filter(map -> map.examStatus == ExamStatus.UP_COMING)
|
||||||
|
.findAny()
|
||||||
|
.isPresent())
|
||||||
|
.getOr(false);
|
||||||
|
|
||||||
// new PageContext with actual EntityKey
|
// new PageContext with actual EntityKey
|
||||||
final PageContext formContext = pageContext.withEntityKey(examConfig.getEntityKey());
|
final PageContext formContext = pageContext.withEntityKey(examConfig.getEntityKey());
|
||||||
|
@ -261,7 +270,7 @@ public class SEBExamConfigForm implements TemplateComposer {
|
||||||
Domain.CONFIGURATION_NODE.ATTR_STATUS,
|
Domain.CONFIGURATION_NODE.ATTR_STATUS,
|
||||||
FORM_STATUS_TEXT_KEY,
|
FORM_STATUS_TEXT_KEY,
|
||||||
examConfig.status.name(),
|
examConfig.status.name(),
|
||||||
() -> resourceService.examConfigStatusResources(isAttachedToExam, hasRunningExam))
|
() -> resourceService.examConfigStatusResources(isAttachedToExam, hasActiveExams))
|
||||||
.withEmptyCellSeparation(!isReadonly))
|
.withEmptyCellSeparation(!isReadonly))
|
||||||
.buildFor((isNew)
|
.buildFor((isNew)
|
||||||
? this.restService.getRestCall(NewExamConfig.class)
|
? this.restService.getRestCall(NewExamConfig.class)
|
||||||
|
|
|
@ -66,8 +66,8 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.dao.TransactionHandler;
|
||||||
public class ExamConfigurationMapDAOImpl implements ExamConfigurationMapDAO {
|
public class ExamConfigurationMapDAOImpl implements ExamConfigurationMapDAO {
|
||||||
|
|
||||||
private static final List<String> ACTIVE_EXAM_STATE_NAMES = Arrays.asList(
|
private static final List<String> ACTIVE_EXAM_STATE_NAMES = Arrays.asList(
|
||||||
ExamStatus.FINISHED.name(),
|
ExamStatus.UP_COMING.name(),
|
||||||
ExamStatus.ARCHIVED.name());
|
ExamStatus.RUNNING.name());
|
||||||
|
|
||||||
private final ExamRecordMapper examRecordMapper;
|
private final ExamRecordMapper examRecordMapper;
|
||||||
private final ExamConfigurationMapRecordMapper examConfigurationMapRecordMapper;
|
private final ExamConfigurationMapRecordMapper examConfigurationMapRecordMapper;
|
||||||
|
@ -382,7 +382,7 @@ public class ExamConfigurationMapDAOImpl implements ExamConfigurationMapDAO {
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public Result<Boolean> checkNoActiveExamReferences(final Long configurationNodeId) {
|
public Result<Boolean> checkNoActiveExamReferences(final Long configurationNodeId) {
|
||||||
return Result.tryCatch(() -> !this.examConfigurationMapRecordMapper.selectByExample()
|
return Result.tryCatch(() -> this.examConfigurationMapRecordMapper.selectByExample()
|
||||||
.where(
|
.where(
|
||||||
ExamConfigurationMapRecordDynamicSqlSupport.configurationNodeId,
|
ExamConfigurationMapRecordDynamicSqlSupport.configurationNodeId,
|
||||||
isEqualTo(configurationNodeId))
|
isEqualTo(configurationNodeId))
|
||||||
|
@ -396,11 +396,12 @@ public class ExamConfigurationMapDAOImpl implements ExamConfigurationMapDAO {
|
||||||
|
|
||||||
private boolean isExamActive(final Long examId) {
|
private boolean isExamActive(final Long examId) {
|
||||||
try {
|
try {
|
||||||
return this.examRecordMapper.countByExample()
|
final boolean active = this.examRecordMapper.countByExample()
|
||||||
.where(ExamRecordDynamicSqlSupport.id, isEqualTo(examId))
|
.where(ExamRecordDynamicSqlSupport.id, isEqualTo(examId))
|
||||||
.and(ExamRecordDynamicSqlSupport.status, isIn(ACTIVE_EXAM_STATE_NAMES))
|
.and(ExamRecordDynamicSqlSupport.status, isIn(ACTIVE_EXAM_STATE_NAMES))
|
||||||
.build()
|
.build()
|
||||||
.execute() >= 1;
|
.execute() >= 1;
|
||||||
|
return active;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
log.warn("Failed to check exam status for exam: {}", examId, e);
|
log.warn("Failed to check exam status for exam: {}", examId, e);
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue