SEBSERV-566 fixed, update SPS session

This commit is contained in:
anhefti 2024-07-16 16:25:02 +02:00
parent e70a209217
commit 4cd498d29e
2 changed files with 71 additions and 10 deletions

View file

@ -727,6 +727,45 @@ class ScreenProctoringAPIBinding {
return token;
}
String updateSEBSession(
final Long groupId,
final ClientConnectionRecord clientConnection) {
final String token = clientConnection.getConnectionToken();
final ScreenProctoringServiceOAuthTemplate apiTemplate = this.getAPITemplate(clientConnection.getExamId());
final String uri = UriComponentsBuilder
.fromUriString(apiTemplate.spsAPIAccessData.getSpsServiceURL())
.path(SPS_API.SESSION_ENDPOINT)
.pathSegment(token)
.build()
.toUriString();
final Map<String, String> params = new HashMap<>();
params.put(SPS_API.SESSION.ATTR_UUID, token);
params.put(SPS_API.SESSION.ATTR_GROUP_ID, String.valueOf(groupId));
params.put(SPS_API.SESSION.ATTR_CLIENT_IP, clientConnection.getClientAddress());
params.put(SPS_API.SESSION.ATTR_CLIENT_NAME, clientConnection.getExamUserSessionId());
params.put(SPS_API.SESSION.ATTR_CLIENT_MACHINE_NAME, clientConnection.getClientMachineName());
params.put(SPS_API.SESSION.ATTR_CLIENT_OS_NAME, clientConnection.getClientOsName());
params.put(SPS_API.SESSION.ATTR_CLIENT_VERSION, clientConnection.getClientVersion());
ResponseEntity<String> exchange = null;
try {
final String jsonSession = jsonMapper.writeValueAsString(params);
exchange = apiTemplate.exchangePUT(uri, jsonSession);
} catch (final JsonProcessingException e) {
throw new RuntimeException(e);
}
if (exchange.getStatusCode() != HttpStatus.OK) {
throw new RuntimeException(
"Failed to update SPS SEB session for SEB connection: " + token);
}
return token;
}
void deleteExamOnScreenProctoring(final Exam exam) {
try {
@ -1369,6 +1408,15 @@ class ScreenProctoringAPIBinding {
return exchange(url, HttpMethod.POST, body, getHeaders());
}
ResponseEntity<String> exchangePUT(
final String url,
final String body) {
final HttpHeaders httpHeaders = getHeaders();
httpHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
return exchange(url, HttpMethod.PUT, body, httpHeaders);
}
HttpHeaders getHeadersJSONRequest() {
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);

View file

@ -387,19 +387,32 @@ public class ScreenProctoringServiceImpl implements ScreenProctoringService {
try {
final Long examId = ccRecord.getExamId();
final Exam runningExam = this.examSessionCacheService.getRunningExam(examId);
final Long existingGroupId = ccRecord.getScreenProctoringGroupId();
// apply SEB connection to screen proctoring group
final ScreenProctoringGroup group = applySEBConnectionToGroup(
ccRecord,
runningExam);
placeReservedInGroup = group.id;
if (existingGroupId == null) {
// create screen proctoring session for SEB connection on SPS service
final String spsSessionToken = this.screenProctoringAPIBinding
.createSEBSession(examId, group, ccRecord);
// apply SEB connection to screen proctoring group
final ScreenProctoringGroup group = applySEBConnectionToGroup(
ccRecord,
runningExam);
placeReservedInGroup = group.id;
// create instruction for SEB and add it to instruction queue for SEB connection
registerJoinInstruction(ccRecord, spsSessionToken, group, runningExam);
// create screen proctoring session for SEB connection on SPS service
final String spsSessionToken = this.screenProctoringAPIBinding
.createSEBSession(examId, group, ccRecord);
// create instruction for SEB and add it to instruction queue for SEB connection
registerJoinInstruction(ccRecord, spsSessionToken, group, runningExam);
} else {
// just update session on SPS site
this.screenProctoringGroupDAO
.getScreenProctoringGroup(existingGroupId)
.map(group -> this.screenProctoringAPIBinding.updateSEBSession(
group.id,
ccRecord))
.onError(error -> log.error("Failed to update SEB Session on SPS: {}", ccRecord, error));
}
this.clientConnectionDAO
.markScreenProctoringApplied(ccRecord.getId(), ccRecord.getConnectionToken())