Skip to content

Commit

Permalink
SEBSERV-435 fix monitoring update, fix group release when assign failed
Browse files Browse the repository at this point in the history
  • Loading branch information
anhefti committed Oct 30, 2023
1 parent aff3544 commit 0e1ee33
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public interface ScreenProctoringGroupDAO {
* @throws If the Result contains a AllGroupsFullException, there must be created a new Group first */
Result<ScreenProctoringGroup> reservePlaceInCollectingGroup(Long examId, int maxSize);

Result<ScreenProctoringGroup> 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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ public Result<ScreenProctoringGroup> reservePlaceInCollectingGroup(final Long ex
.onError(TransactionHandler::rollback);
}

@Override
@Transactional
public Result<ScreenProctoringGroup> 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<ScreenProctoringGroup> createNewGroup(final ScreenProctoringGroup group) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -115,10 +116,10 @@ default boolean isScreenProctoringEnabled(final Exam exam) {

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ public String createSEBSession(

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ public void notifyExamDeletion(final ExamDeletionEvent event) {

private void applyScreenProctoringSession(final ClientConnectionRecord ccRecord) {

Long placeReservedInGroup = null;

try {
final Long examId = ccRecord.getExamId();
final Exam runningExam = this.examSessionCacheService.getRunningExam(examId);
Expand All @@ -305,6 +307,7 @@ private void applyScreenProctoringSession(final ClientConnectionRecord ccRecord)
final ScreenProctoringGroup group = applySEBConnectionToGroup(
ccRecord,
runningExam);
placeReservedInGroup = group.id;

// create screen proctoring session for SEB connection on SPS service
final String spsSessionToken = this.screenProctoringAPIBinding
Expand All @@ -315,6 +318,15 @@ private void applyScreenProctoringSession(final ClientConnectionRecord ccRecord)

} 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()));
// }
}
}

Expand Down Expand Up @@ -348,7 +360,7 @@ private ScreenProctoringGroup applyToDefaultGroup(
final ClientConnectionRecord ccRecord,
final Exam exam) {

final ScreenProctoringGroup screenProctoringGroup = getProctoringGroup(exam);
final ScreenProctoringGroup screenProctoringGroup = reservePlaceOnProctoringGroup(exam);
this.clientConnectionDAO.assignToScreenProctoringGroup(
exam.id,
ccRecord.getConnectionToken(),
Expand All @@ -358,7 +370,7 @@ private ScreenProctoringGroup applyToDefaultGroup(
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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config/application-dev-ws.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0e1ee33

Please sign in to comment.