From 95c2057dadc0c2a3c241453d6003389d9b94124a Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 17 Jul 2024 14:28:27 +0200 Subject: [PATCH] improved sps group number update --- .../dao/ScreenProctoringGroupDAO.java | 2 + .../impl/ScreenProctoringGroupDAOImpl.java | 43 +++++++++---------- .../ScreenProctoringServiceImpl.java | 19 ++++---- 3 files changed, 33 insertions(+), 31 deletions(-) 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 faec1af5..92188373 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 @@ -81,4 +81,6 @@ public interface ScreenProctoringGroupDAO { void updateGroupSize(String groupUUID, Integer activeCount, Integer totalCount); void resetAllForExam(Long examId); + + boolean hasActiveGroups(); } 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 c8cb838f..55c8c1dc 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 @@ -16,6 +16,8 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import ch.ethz.seb.sebserver.gbl.model.exam.Exam; +import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.*; import org.mybatis.dynamic.sql.SqlBuilder; import org.mybatis.dynamic.sql.update.UpdateDSL; import org.slf4j.Logger; @@ -30,10 +32,6 @@ import ch.ethz.seb.sebserver.gbl.model.exam.ScreenProctoringSettings; import ch.ethz.seb.sebserver.gbl.model.session.ScreenProctoringGroup; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; import ch.ethz.seb.sebserver.gbl.util.Result; -import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.AdditionalAttributeRecordDynamicSqlSupport; -import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.AdditionalAttributeRecordMapper; -import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ScreenProctoringGroopRecordDynamicSqlSupport; -import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ScreenProctoringGroopRecordMapper; import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ScreenProctoringGroopRecord; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ScreenProctoringGroupDAO; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.TransactionHandler; @@ -280,6 +278,25 @@ public class ScreenProctoringGroupDAOImpl implements ScreenProctoringGroupDAO { } } + @Override + @Transactional(readOnly = true) + public boolean hasActiveGroups() { + try { + return this.screenProctoringGroopRecordMapper + .countByExample() + .leftJoin(ExamRecordDynamicSqlSupport.examRecord) + .on( + ScreenProctoringGroopRecordDynamicSqlSupport.examId, + equalTo(ExamRecordDynamicSqlSupport.id)) + .where(ExamRecordDynamicSqlSupport.status, isEqualTo(Exam.ExamStatus.RUNNING.name())) + .build() + .execute() > 0; + } catch (final Exception e) { + log.error("Failed to check active screen proctoring groups: ", e); + return false; + } + } + private ScreenProctoringGroup toDomainModel(final ScreenProctoringGroopRecord record) { return new ScreenProctoringGroup( record.getId(), @@ -289,24 +306,6 @@ public class ScreenProctoringGroupDAOImpl implements ScreenProctoringGroupDAO { record.getSize(), record.getData()); } - -// private ScreenProctoringGroopRecord updateCollectingGroup( -// final ScreenProctoringGroopRecord screenProctoringGroupRecord) { -// -// final Long id = screenProctoringGroupRecord.getId(); -// -// UpdateDSL.updateWithMapper( -// this.screenProctoringGroopRecordMapper::update, -// ScreenProctoringGroopRecordDynamicSqlSupport.screenProctoringGroopRecord) -// .set(ScreenProctoringGroopRecordDynamicSqlSupport.size) -// .equalTo(screenProctoringGroupRecord.getSize() + 1) -// .where(ScreenProctoringGroopRecordDynamicSqlSupport.id, isEqualTo(id)) -// .build() -// .execute(); -// -// return this.screenProctoringGroopRecordMapper.selectByPrimaryKey(id); -// } - public static final class AllGroupsFullException extends RuntimeException { private static final long serialVersionUID = 3283129187819160485L; } 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 59df8743..7aef6f5c 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 @@ -247,15 +247,16 @@ public class ScreenProctoringServiceImpl implements ScreenProctoringService { public void updateActiveGroups() { try { - screenProctoringAPIBinding - .getActiveGroupSessionCounts() - .forEach(groupCount -> { - screenProctoringGroupDAO.updateGroupSize( - groupCount.groupUUID, - groupCount.activeCount, - groupCount.totalCount); - }); - + if (screenProctoringGroupDAO.hasActiveGroups()) { + screenProctoringAPIBinding + .getActiveGroupSessionCounts() + .forEach(groupCount -> { + screenProctoringGroupDAO.updateGroupSize( + groupCount.groupUUID, + groupCount.activeCount, + groupCount.totalCount); + }); + } } catch (final Exception e) { log.warn("Failed to update actual group session counts."); }