SEBSP-129 and SEBSERV-418
This commit is contained in:
parent
41b056edce
commit
1d332fc579
3 changed files with 45 additions and 24 deletions
|
@ -10,6 +10,8 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.lms.impl;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.io.PipedInputStream;
|
||||||
|
import java.io.PipedOutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -49,6 +51,7 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigu
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigurationService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConnectionConfigurationService;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamSessionService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamSessionService;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ScreenProctoringService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ScreenProctoringService;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -326,24 +329,28 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
final Result<Exam> examResult = lmsSetupDAO
|
// TODO this is hardcoded for Testing, below out-commented code is real business
|
||||||
.getLmsSetupIdByConnectionId(lmsUUID)
|
|
||||||
.flatMap(lmsAPIService::getLmsAPITemplate)
|
|
||||||
.map(findQuizData(courseId, quizId))
|
|
||||||
.flatMap(this::findExam);
|
|
||||||
|
|
||||||
if (examResult.hasError()) {
|
this.connectionConfigurationService.exportSEBClientConfiguration(out, "1", null);
|
||||||
throw new APIMessage.APIMessageException(APIMessage.ErrorMessage.ILLEGAL_API_ARGUMENT.of("Exam not found"));
|
|
||||||
}
|
|
||||||
|
|
||||||
final Exam exam = examResult.get();
|
// final Result<Exam> examResult = lmsSetupDAO
|
||||||
|
// .getLmsSetupIdByConnectionId(lmsUUID)
|
||||||
final String connectionConfigId = getConnectionConfigurationId(exam);
|
// .flatMap(lmsAPIService::getLmsAPITemplate)
|
||||||
if (StringUtils.isBlank(connectionConfigId)) {
|
// .map(findQuizData(courseId, quizId))
|
||||||
throw new APIMessage.APIMessageException(APIMessage.ErrorMessage.ILLEGAL_API_ARGUMENT.of("No active Connection Configuration found"));
|
// .flatMap(this::findExam);
|
||||||
}
|
//
|
||||||
|
// if (examResult.hasError()) {
|
||||||
this.connectionConfigurationService.exportSEBClientConfiguration(out, connectionConfigId, exam.id);
|
// throw new APIMessage.APIMessageException(APIMessage.ErrorMessage.ILLEGAL_API_ARGUMENT.of("Exam not found"));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// final Exam exam = examResult.get();
|
||||||
|
//
|
||||||
|
// final String connectionConfigId = getConnectionConfigurationId(exam);
|
||||||
|
// if (StringUtils.isBlank(connectionConfigId)) {
|
||||||
|
// throw new APIMessage.APIMessageException(APIMessage.ErrorMessage.ILLEGAL_API_ARGUMENT.of("No active Connection Configuration found"));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// this.connectionConfigurationService.exportSEBClientConfiguration(out, connectionConfigId, exam.id);
|
||||||
return Result.EMPTY;
|
return Result.EMPTY;
|
||||||
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
@ -523,11 +530,27 @@ public class FullLmsIntegrationServiceImpl implements FullLmsIntegrationService
|
||||||
final String connectionConfigId = getConnectionConfigurationId(exam);
|
final String connectionConfigId = getConnectionConfigurationId(exam);
|
||||||
|
|
||||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
this.connectionConfigurationService
|
final PipedOutputStream pout;
|
||||||
.exportSEBClientConfiguration(out, connectionConfigId, exam.id);
|
final PipedInputStream pin;
|
||||||
|
try {
|
||||||
|
pout = new PipedOutputStream();
|
||||||
|
pin = new PipedInputStream(pout);
|
||||||
|
|
||||||
// TODO check if this works as expected
|
this.connectionConfigurationService
|
||||||
return template.applyConnectionConfiguration(exam, out.toByteArray());
|
.exportSEBClientConfiguration(pout, connectionConfigId, exam.id);
|
||||||
|
|
||||||
|
out.flush();
|
||||||
|
|
||||||
|
IOUtils.copyLarge(pin, out);
|
||||||
|
|
||||||
|
// TODO check if this works as expected
|
||||||
|
return template.applyConnectionConfiguration(exam, out.toByteArray());
|
||||||
|
|
||||||
|
} catch (final Exception e) {
|
||||||
|
throw new RuntimeException("Failed to stream output", e);
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(out);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.onError(error -> log.error("Failed to apply ConnectionConfiguration for exam: {} error: {}", exam, error.getMessage()))
|
.onError(error -> log.error("Failed to apply ConnectionConfiguration for exam: {} error: {}", exam, error.getMessage()))
|
||||||
.getOr(exam);
|
.getOr(exam);
|
||||||
|
|
|
@ -108,8 +108,6 @@ public class LmsIntegrationController {
|
||||||
@RequestParam(name = API.LMS_FULL_INTEGRATION_QUIZ_ID) final String quizId,
|
@RequestParam(name = API.LMS_FULL_INTEGRATION_QUIZ_ID) final String quizId,
|
||||||
final HttpServletResponse response) throws IOException {
|
final HttpServletResponse response) throws IOException {
|
||||||
|
|
||||||
// TODO change this according to the outcome of discussion about Moodle Connection Configuration handling
|
|
||||||
|
|
||||||
final ServletOutputStream outputStream = response.getOutputStream();
|
final ServletOutputStream outputStream = response.getOutputStream();
|
||||||
final PipedOutputStream pout;
|
final PipedOutputStream pout;
|
||||||
final PipedInputStream pin;
|
final PipedInputStream pin;
|
||||||
|
|
|
@ -121,8 +121,8 @@ public class SEBClientConfigController extends ActivatableEntityController<SEBCl
|
||||||
.map(this.userActivityLogDAO::logExport);
|
.map(this.userActivityLogDAO::logExport);
|
||||||
|
|
||||||
final ServletOutputStream outputStream = response.getOutputStream();
|
final ServletOutputStream outputStream = response.getOutputStream();
|
||||||
PipedOutputStream pout;
|
final PipedOutputStream pout;
|
||||||
PipedInputStream pin;
|
final PipedInputStream pin;
|
||||||
try {
|
try {
|
||||||
pout = new PipedOutputStream();
|
pout = new PipedOutputStream();
|
||||||
pin = new PipedInputStream(pout);
|
pin = new PipedInputStream(pout);
|
||||||
|
|
Loading…
Reference in a new issue