use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method exportCourseElement.
public MediaResource exportCourseElement() {
FileResourceManager frm = FileResourceManager.getInstance();
File unzippedDirRoot = frm.unzipFileResource(searchParams.getTestEntry().getOlatResource());
resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
ICourse course = CourseFactory.loadCourse(searchParams.getCourseEntry());
courseNode = course.getRunStructure().getNode(searchParams.getNodeIdent());
String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".xlsx";
if ("iqself".equals(courseNode.getType())) {
anonymizerCallback = course.getCourseEnvironment().getCoursePropertyManager();
}
// content
final List<AssessmentTestSession> sessions = testSessionDao.getTestSessionsOfResponse(searchParams);
final List<AssessmentResponse> responses = responseDao.getResponse(searchParams);
return new OpenXMLWorkbookResource(label) {
@Override
protected void generate(OutputStream out) {
try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
// headers
OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
exportSheet.setHeaderRows(2);
writeHeaders_1(exportSheet, workbook);
writeHeaders_2(exportSheet, workbook);
writeData(sessions, responses, exportSheet, workbook);
} catch (Exception e) {
log.error("", e);
}
}
};
}
use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method exportWorkbook.
public void exportWorkbook(OutputStream exportStream) {
RepositoryEntry testEntry = searchParams.getTestEntry();
FileResourceManager frm = FileResourceManager.getInstance();
File unzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
// content
final List<AssessmentTestSession> sessions = testSessionDao.getTestSessionsOfResponse(searchParams);
final List<AssessmentResponse> responses = responseDao.getResponse(searchParams);
try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(exportStream, 1)) {
// headers
OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
exportSheet.setHeaderRows(2);
writeHeaders_1(exportSheet, workbook);
writeHeaders_2(exportSheet, workbook);
writeData(sessions, responses, exportSheet, workbook);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.
the class QTI21ServiceImpl method validateAssessmentResult.
@Override
public DigitalSignatureValidation validateAssessmentResult(File xmlSignature) {
try {
Document signature = XMLDigitalSignatureUtil.getDocument(xmlSignature);
String uri = XMLDigitalSignatureUtil.getReferenceURI(signature);
// URI looks like: http://localhost:8081/olat/RepositoryEntry/688455680/CourseNode/95134692149905/TestSession/3231/assessmentResult.xml
String keyName = XMLDigitalSignatureUtil.getKeyName(signature);
int end = uri.indexOf("/assessmentResult");
if (end <= 0) {
return new DigitalSignatureValidation(DigitalSignatureValidation.Message.sessionNotFound, false);
}
int start = uri.lastIndexOf('/', end - 1);
if (start <= 0) {
return new DigitalSignatureValidation(DigitalSignatureValidation.Message.sessionNotFound, false);
}
String testSessionKey = uri.substring(start + 1, end);
AssessmentTestSession testSession = getAssessmentTestSession(new Long(testSessionKey));
if (testSession == null) {
return new DigitalSignatureValidation(DigitalSignatureValidation.Message.sessionNotFound, false);
}
File assessmentResult = getAssessmentResultFile(testSession);
File certificateFile = qtiModule.getDigitalSignatureCertificateFile();
X509CertificatePrivateKeyPair kp = null;
if (keyName != null && keyName.equals(certificateFile.getName())) {
kp = CryptoUtil.getX509CertificatePrivateKeyPairPfx(certificateFile, qtiModule.getDigitalSignatureCertificatePassword());
} else if (keyName != null) {
File olderCertificateFile = new File(certificateFile.getParentFile(), keyName);
if (olderCertificateFile.exists()) {
kp = CryptoUtil.getX509CertificatePrivateKeyPairPfx(olderCertificateFile, qtiModule.getDigitalSignatureCertificatePassword());
}
}
if (kp == null) {
// validate document against signature
if (XMLDigitalSignatureUtil.validate(uri, assessmentResult, xmlSignature)) {
return new DigitalSignatureValidation(DigitalSignatureValidation.Message.validItself, true);
}
} else if (XMLDigitalSignatureUtil.validate(uri, assessmentResult, xmlSignature, kp.getX509Cert().getPublicKey())) {
// validate document against signature but use the public key of the certificate
return new DigitalSignatureValidation(DigitalSignatureValidation.Message.validCertificate, true);
}
} catch (Exception e) {
log.error("", e);
}
return new DigitalSignatureValidation(DigitalSignatureValidation.Message.notValid, false);
}
use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.
the class QTI21ServiceImpl method createInMemoryAssessmentTestSession.
@Override
public AssessmentTestSession createInMemoryAssessmentTestSession(Identity identity) {
InMemoryAssessmentTestSession candidateSession = new InMemoryAssessmentTestSession();
candidateSession.setIdentity(identity);
candidateSession.setStorage(testSessionDao.createSessionStorage(candidateSession));
return candidateSession;
}
use of org.olat.ims.qti21.AssessmentTestSession in project OpenOLAT by OpenOLAT.
the class QTI21ServiceImpl method recordCandidateItemEvent.
@Override
public CandidateEvent recordCandidateItemEvent(AssessmentTestSession candidateSession, RepositoryEntryRef testEntry, RepositoryEntryRef entry, CandidateItemEventType itemEventType, ItemSessionState itemSessionState, NotificationRecorder notificationRecorder) {
CandidateEvent event = new CandidateEvent(candidateSession, testEntry, entry);
event.setItemEventType(itemEventType);
return event;
}
Aggregations