diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ScreenProctoringGroupDAO.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ScreenProctoringGroupDAO.java index 477bc2c4..452fe815 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ScreenProctoringGroupDAO.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ScreenProctoringGroupDAO.java @@ -59,6 +59,8 @@ public interface ScreenProctoringGroupDAO { * @throws If the Result contains a AllGroupsFullException, there must be created a new Group first */ Result reservePlaceInCollectingGroup(Long examId, int maxSize); + Result releasePlaceInCollectingGroup(Long examId, Long groupId); + /** This creates a new ScreenProctoringGroup with the given group data. * Note that examId and uuid and name are mandatory. The size is ignored and initially set to 0 * diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ScreenProctoringGroupDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ScreenProctoringGroupDAOImpl.java index dd0bf1a2..c46c4e8c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ScreenProctoringGroupDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ScreenProctoringGroupDAOImpl.java @@ -151,6 +151,28 @@ public class ScreenProctoringGroupDAOImpl implements ScreenProctoringGroupDAO { .onError(TransactionHandler::rollback); } + @Override + @Transactional + public Result releasePlaceInCollectingGroup(final Long examId, final Long groupId) { + return Result.tryCatch(() -> { + final ScreenProctoringGroopRecord record = + this.screenProctoringGroopRecordMapper.selectByPrimaryKey(groupId); + + UpdateDSL.updateWithMapper( + this.screenProctoringGroopRecordMapper::update, + ScreenProctoringGroopRecordDynamicSqlSupport.screenProctoringGroopRecord) + .set(ScreenProctoringGroopRecordDynamicSqlSupport.size) + .equalTo(record.getSize() - 1) + .where(ScreenProctoringGroopRecordDynamicSqlSupport.id, isEqualTo(groupId)) + .build() + .execute(); + + return this.screenProctoringGroopRecordMapper.selectByPrimaryKey(groupId); + }) + .map(this::toDomainModel) + .onError(TransactionHandler::rollback); + } + @Override @Transactional public Result createNewGroup(final ScreenProctoringGroup group) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java index 3070fec4..dc078cdf 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/exam/ExamAdminService.java @@ -26,6 +26,7 @@ import ch.ethz.seb.sebserver.gbl.model.exam.ClientGroupData.ClientOS; import ch.ethz.seb.sebserver.gbl.model.exam.Exam; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; import ch.ethz.seb.sebserver.gbl.model.exam.ProctoringServiceSettings; +import ch.ethz.seb.sebserver.gbl.model.exam.ScreenProctoringSettings; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.webservice.servicelayer.session.RemoteProctoringService; @@ -115,10 +116,10 @@ public interface ExamAdminService { if (exam.additionalAttributesIncluded()) { return BooleanUtils.toBoolean( - exam.getAdditionalAttribute(ProctoringServiceSettings.ATTR_ENABLE_PROCTORING)); + exam.getAdditionalAttribute(ScreenProctoringSettings.ATTR_ENABLE_SCREEN_PROCTORING)); } - return isProctoringEnabled(exam.id).getOr(false); + return isScreenProctoringEnabled(exam.id).getOr(false); } /** Updates needed additional attributes from assigned exam configuration for the exam diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ScreenProctoringAPIBinding.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ScreenProctoringAPIBinding.java index dc4f9c11..a0052f46 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ScreenProctoringAPIBinding.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ScreenProctoringAPIBinding.java @@ -487,7 +487,6 @@ class ScreenProctoringAPIBinding { final String token = clientConnection.getConnectionToken(); final ScreenProctoringServiceOAuthTemplate apiTemplate = this.getAPITemplate(examId); - final String uri = UriComponentsBuilder .fromUriString(this.apiTemplate.screenProctoringSettings.spsServiceURL) .path(SPS_API.SESSION_ENDPOINT) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ScreenProctoringServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ScreenProctoringServiceImpl.java index 1ecd33c7..fd7bfb27 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ScreenProctoringServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/proctoring/ScreenProctoringServiceImpl.java @@ -297,6 +297,8 @@ public class ScreenProctoringServiceImpl implements ScreenProctoringService { private void applyScreenProctoringSession(final ClientConnectionRecord ccRecord) { + Long placeReservedInGroup = null; + try { final Long examId = ccRecord.getExamId(); final Exam runningExam = this.examSessionCacheService.getRunningExam(examId); @@ -305,6 +307,7 @@ public class ScreenProctoringServiceImpl implements ScreenProctoringService { final ScreenProctoringGroup group = applySEBConnectionToGroup( ccRecord, runningExam); + placeReservedInGroup = group.id; // create screen proctoring session for SEB connection on SPS service final String spsSessionToken = this.screenProctoringAPIBinding @@ -315,6 +318,15 @@ public class ScreenProctoringServiceImpl implements ScreenProctoringService { } catch (final Exception e) { log.error("Failed to apply screen proctoring session to SEB with connection: ", ccRecord, e); + +// if (placeReservedInGroup != null) { +// // release reserved place in group +// this.screenProctoringGroupDAO.releasePlaceInCollectingGroup( +// ccRecord.getExamId(), +// placeReservedInGroup) +// .onError( +// error -> log.warn("Failed to release reserved place in group: {}", error.getMessage())); +// } } } @@ -348,7 +360,7 @@ public class ScreenProctoringServiceImpl implements ScreenProctoringService { final ClientConnectionRecord ccRecord, final Exam exam) { - final ScreenProctoringGroup screenProctoringGroup = getProctoringGroup(exam); + final ScreenProctoringGroup screenProctoringGroup = reservePlaceOnProctoringGroup(exam); this.clientConnectionDAO.assignToScreenProctoringGroup( exam.id, ccRecord.getConnectionToken(), @@ -358,7 +370,7 @@ public class ScreenProctoringServiceImpl implements ScreenProctoringService { return screenProctoringGroup; } - private ScreenProctoringGroup getProctoringGroup(final Exam exam) { + private ScreenProctoringGroup reservePlaceOnProctoringGroup(final Exam exam) { int collectingGroupSize = 0; if (exam.additionalAttributes.containsKey(ScreenProctoringSettings.ATTR_COLLECTING_GROUP_SIZE)) { diff --git a/src/main/resources/config/application-dev-ws.properties b/src/main/resources/config/application-dev-ws.properties index d2a040b4..b49bad3b 100644 --- a/src/main/resources/config/application-dev-ws.properties +++ b/src/main/resources/config/application-dev-ws.properties @@ -25,7 +25,7 @@ sebserver.webservice.clean-db-on-startup=false # webservice configuration sebserver.init.adminaccount.gen-on-init=false -sebserver.webservice.distributed=false +sebserver.webservice.distributed=true #sebserver.webservice.master.delay.threshold=10000 sebserver.webservice.http.external.scheme=http sebserver.webservice.http.external.servername=localhost