starting collect all room impl

This commit is contained in:
anhefti 2020-10-26 14:54:54 +01:00
parent f7d80ed4da
commit b3f83877f2
5 changed files with 50 additions and 3 deletions

View file

@ -34,6 +34,7 @@ public class ProctoringSettings implements Entity {
public static final String ATTR_APP_KEY = "appKey";
public static final String ATTR_APP_SECRET = "appSecret";
public static final String ATTR_COLLECTING_ROOM_SIZE = "collectingRoomSize";
public static final String ATTR_COLLECT_ALL_ROOM_NAME = "collectAllRoomName";
@JsonProperty(Domain.EXAM.ATTR_ID)
public final Long examId;

View file

@ -62,9 +62,10 @@ public interface AdditionalAttributesDAO {
/** Use this to delete an additional attribute by its entity identifier and name.
*
* @param type the entity type
* @param entityId the entity identifier (primary-key)
* @param name the name of the additional attribute */
void delete(Long entityId, String name);
void delete(EntityType type, Long entityId, String name);
/** Use this to delete all additional attributes for a given entity.
*

View file

@ -145,10 +145,13 @@ public class AdditionalAttributesDAOImpl implements AdditionalAttributesDAO {
@Override
@Transactional
public void delete(final Long entityId, final String name) {
public void delete(final EntityType type, final Long entityId, final String name) {
this.additionalAttributeRecordMapper
.deleteByExample()
.where(
AdditionalAttributeRecordDynamicSqlSupport.entityType,
SqlBuilder.isEqualTo(type.name()))
.and(
AdditionalAttributeRecordDynamicSqlSupport.entityId,
SqlBuilder.isEqualTo(entityId))
.and(

View file

@ -44,4 +44,8 @@ public interface ExamProcotringRoomService {
* name of an exam. */
void updateProctoringRooms();
Result<String> createCollectAllRoom(Long examId);
void disposeCollectAllRoom(Long examId);
}

View file

@ -25,6 +25,7 @@ import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.exam.ProctoringSettings;
import ch.ethz.seb.sebserver.gbl.model.exam.ProctoringSettings.ProctoringServerType;
import ch.ethz.seb.sebserver.gbl.model.exam.SEBProctoringConnectionData;
@ -40,6 +41,7 @@ import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientConnectionR
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ClientConnectionRecordMapper;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.RemoteProctoringRoomRecordDynamicSqlSupport;
import ch.ethz.seb.sebserver.webservice.datalayer.batis.model.ClientConnectionRecord;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.AdditionalAttributesDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.RemoteProctoringRoomDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.impl.ClientConnectionDAOImpl;
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamAdminService;
@ -53,24 +55,29 @@ public class ExamProcotringRoomServiceImpl implements ExamProcotringRoomService
private static final Logger log = LoggerFactory.getLogger(ExamProcotringRoomServiceImpl.class);
private final static String ACTIVE_COLLECTING_ALL_ROOM_ATTRIBUTE_NAME = "ACTIVE_COLLECTING_ALL_ROOM";
private final RemoteProctoringRoomDAO remoteProctoringRoomDAO;
private final ClientConnectionRecordMapper clientConnectionRecordMapper;
private final SEBInstructionService sebInstructionService;
private final ExamAdminService examAdminService;
private final ExamSessionCacheService examSessionCacheService;
private final AdditionalAttributesDAO additionalAttributesDAO;
public ExamProcotringRoomServiceImpl(
final RemoteProctoringRoomDAO remoteProctoringRoomDAO,
final ClientConnectionRecordMapper clientConnectionRecordMapper,
final SEBInstructionService sebInstructionService,
final ExamAdminService examAdminService,
final ExamSessionCacheService examSessionCacheService) {
final ExamSessionCacheService examSessionCacheService,
final AdditionalAttributesDAO additionalAttributesDAO) {
this.remoteProctoringRoomDAO = remoteProctoringRoomDAO;
this.clientConnectionRecordMapper = clientConnectionRecordMapper;
this.sebInstructionService = sebInstructionService;
this.examAdminService = examAdminService;
this.examSessionCacheService = examSessionCacheService;
this.additionalAttributesDAO = additionalAttributesDAO;
}
@Override
@ -127,6 +134,37 @@ public class ExamProcotringRoomServiceImpl implements ExamProcotringRoomService
});
}
@Override
@Transactional
public Result<String> createCollectAllRoom(final Long examId) {
final String newCollectingRoomName = UUID.randomUUID().toString();
return this.additionalAttributesDAO
.saveAdditionalAttribute(
EntityType.EXAM,
examId,
ACTIVE_COLLECTING_ALL_ROOM_ATTRIBUTE_NAME,
newCollectingRoomName)
.map(attr -> attr.getValue());
}
@Override
@Transactional
public void disposeCollectAllRoom(final Long examId) {
this.additionalAttributesDAO.delete(
EntityType.EXAM,
examId,
ACTIVE_COLLECTING_ALL_ROOM_ATTRIBUTE_NAME);
}
private Result<String> getActiveCollectingAllRoom(final Long examId) {
return this.additionalAttributesDAO
.getAdditionalAttribute(
EntityType.EXAM,
examId,
ACTIVE_COLLECTING_ALL_ROOM_ATTRIBUTE_NAME)
.map(attr -> attr.getValue());
}
// TODO considering doing bulk update here
private Collection<ClientConnectionRecord> flagUpdated(final Collection<ClientConnectionRecord> toUpdate) {
return toUpdate.stream().map(cc -> {