Search in sources :

Example 81 with AssessmentTestSession

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);
            }
        }
    };
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) OpenXMLWorkbookResource(org.olat.core.util.openxml.OpenXMLWorkbookResource) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ICourse(org.olat.course.ICourse) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Date(java.util.Date) IOException(java.io.IOException) FileResourceManager(org.olat.fileresource.FileResourceManager) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) File(java.io.File)

Example 82 with AssessmentTestSession

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);
    }
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) FileResourceManager(org.olat.fileresource.FileResourceManager) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) RepositoryEntry(org.olat.repository.RepositoryEntry) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) File(java.io.File) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) IOException(java.io.IOException)

Example 83 with AssessmentTestSession

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);
}
Also used : X509CertificatePrivateKeyPair(org.olat.core.util.crypto.X509CertificatePrivateKeyPair) AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) InMemoryAssessmentTestSession(org.olat.ims.qti21.model.InMemoryAssessmentTestSession) DigitalSignatureValidation(org.olat.ims.qti21.model.DigitalSignatureValidation) Document(org.w3c.dom.Document) File(java.io.File) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) XmlResourceNotFoundException(uk.ac.ed.ph.jqtiplus.xmlutils.XmlResourceNotFoundException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 84 with AssessmentTestSession

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;
}
Also used : InMemoryAssessmentTestSession(org.olat.ims.qti21.model.InMemoryAssessmentTestSession)

Example 85 with AssessmentTestSession

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;
}
Also used : CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent)

Aggregations

AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)107 Identity (org.olat.core.id.Identity)45 RepositoryEntry (org.olat.repository.RepositoryEntry)36 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)32 File (java.io.File)30 ArrayList (java.util.ArrayList)24 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)24 Date (java.util.Date)22 Test (org.junit.Test)20 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)20 HashMap (java.util.HashMap)17 InMemoryAssessmentTestSession (org.olat.ims.qti21.model.InMemoryAssessmentTestSession)14 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)14 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)12 TestPlanNodeKey (uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)12 IOException (java.io.IOException)10 BigDecimal (java.math.BigDecimal)10 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)10 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)10 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)10