Search in sources :

Example 36 with CandidateEvent

use of org.olat.ims.qti21.model.audit.CandidateEvent 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)

Example 37 with CandidateEvent

use of org.olat.ims.qti21.model.audit.CandidateEvent in project OpenOLAT by OpenOLAT.

the class AssessmentItemDisplayController method handleResponses.

public void handleResponses(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap, Map<Identifier, ResponseInput> fileResponseMap, String candidateComment) {
    /* Retrieve current JQTI state and set up JQTI controller */
    NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
    ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
    /* Make sure an attempt is allowed */
    if (itemSessionState.isEnded()) {
        candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.RESPONSES_NOT_EXPECTED, null);
        logError("RESPONSES_NOT_EXPECTED", null);
        return;
    }
    /* Build response map in required format for JQTI+.
		 * NB: The following doesn't test for duplicate keys in the two maps. I'm not sure
		 * it's worth the effort.
		 */
    final Map<Identifier, ResponseData> responseDataMap = new HashMap<>();
    // final Map<Identifier, CandidateFileSubmission> fileSubmissionMap = new HashMap<>();
    final Map<Identifier, AssessmentResponse> assessmentResponseDataMap = new HashMap<>();
    if (stringResponseMap != null) {
        for (final Entry<Identifier, ResponseInput> stringResponseEntry : stringResponseMap.entrySet()) {
            Identifier identifier = stringResponseEntry.getKey();
            ResponseInput responseData = stringResponseEntry.getValue();
            if (responseData instanceof StringInput) {
                responseDataMap.put(identifier, new StringResponseData(((StringInput) responseData).getResponseData()));
            } else if (responseData instanceof Base64Input) {
            // TODO
            } else if (responseData instanceof FileInput) {
            }
        }
    }
    if (fileResponseMap != null) {
        for (final Entry<Identifier, ResponseInput> fileResponseEntry : fileResponseMap.entrySet()) {
            final Identifier identifier = fileResponseEntry.getKey();
            final FileInput multipartFile = (FileInput) fileResponseEntry.getValue();
            if (!multipartFile.isEmpty()) {
                // final CandidateFileSubmission fileSubmission = candidateUploadService.importFileSubmission(candidateSession, multipartFile);
                File storedFile = qtiService.importFileSubmission(candidateSession, multipartFile.getMultipartFileInfos());
                final FileResponseData fileResponseData = new FileResponseData(storedFile, multipartFile.getContentType(), multipartFile.getFileName());
                responseDataMap.put(identifier, fileResponseData);
                assessmentResponseDataMap.put(identifier, new AssessmentResponseData(identifier, fileResponseData));
            // fileSubmissionMap.put(identifier, fileSubmission);
            }
        }
    }
    /* Submit comment (if provided)
		 * NB: Do this first in case next actions end the item session.
		 */
    final Date timestamp = ureq.getRequestTimestamp();
    if (candidateComment != null) {
        try {
            itemSessionController.setCandidateComment(timestamp, candidateComment);
        } catch (final QtiCandidateStateException e) {
            candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.CANDIDATE_COMMENT_FORBIDDEN, e);
            logError("CANDIDATE_COMMENT_FORBIDDEN", null);
            return;
        } catch (final RuntimeException e) {
            logError("", e);
            // handleExplosion(e, candidateSession);
            return;
        }
    }
    /* Attempt to bind responses */
    boolean allResponsesValid = false, allResponsesBound = false;
    try {
        itemSessionController.bindResponses(timestamp, responseDataMap);
        /* Note any responses that failed to bind */
        final Set<Identifier> badResponseIdentifiers = itemSessionState.getUnboundResponseIdentifiers();
        allResponsesBound = badResponseIdentifiers.isEmpty();
        /* Now validate the responses according to any constraints specified by the interactions */
        if (allResponsesBound) {
            final Set<Identifier> invalidResponseIdentifiers = itemSessionState.getInvalidResponseIdentifiers();
            allResponsesValid = invalidResponseIdentifiers.isEmpty();
        }
        /* (We commit responses immediately here) */
        itemSessionController.commitResponses(timestamp);
        /* Invoke response processing (only if responses are valid) */
        if (allResponsesValid) {
            itemSessionController.performResponseProcessing(timestamp);
        }
    } catch (final QtiCandidateStateException e) {
        candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.RESPONSES_NOT_EXPECTED, null);
        logError("RESPONSES_NOT_EXPECTED", e);
        return;
    } catch (final RuntimeException e) {
        logError("", e);
        // handleExplosion(e, candidateSession);
        return;
    }
    /* Record resulting attempt and event */
    final CandidateItemEventType eventType = allResponsesBound ? (allResponsesValid ? CandidateItemEventType.ATTEMPT_VALID : CandidateItemEventType.RESPONSE_INVALID) : CandidateItemEventType.RESPONSE_BAD;
    final CandidateEvent candidateEvent = qtiService.recordCandidateItemEvent(candidateSession, null, entry, eventType, itemSessionState, notificationRecorder);
    candidateAuditLogger.logCandidateEvent(candidateEvent, assessmentResponseDataMap);
    lastEvent = candidateEvent;
    /* Record current result state, or finish session */
    updateSessionFinishedStatus(ureq);
}
Also used : QtiCandidateStateException(uk.ac.ed.ph.jqtiplus.exception.QtiCandidateStateException) CandidateItemEventType(org.olat.ims.qti21.model.audit.CandidateItemEventType) HashMap(java.util.HashMap) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) FileResponseData(uk.ac.ed.ph.jqtiplus.types.FileResponseData) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) AssessmentResponseData(org.olat.ims.qti21.model.audit.AssessmentResponseData) ResponseData(uk.ac.ed.ph.jqtiplus.types.ResponseData) NotificationRecorder(uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder) FileInput(org.olat.ims.qti21.ui.ResponseInput.FileInput) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Date(java.util.Date) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent) StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) FileResponseData(uk.ac.ed.ph.jqtiplus.types.FileResponseData) Base64Input(org.olat.ims.qti21.ui.ResponseInput.Base64Input) File(java.io.File) AssessmentResponseData(org.olat.ims.qti21.model.audit.AssessmentResponseData)

Example 38 with CandidateEvent

use of org.olat.ims.qti21.model.audit.CandidateEvent in project OpenOLAT by OpenOLAT.

the class AssessmentItemDisplayController method requestSolution.

public void requestSolution(UserRequest ureq) {
    ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
    /* Make sure caller may do this */
    // itemDeliverySettings.isAllowSolutionWhenOpen()
    boolean allowSolutionWhenOpen = true;
    if (!itemSessionState.isEnded() && !allowSolutionWhenOpen) {
        candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.SOLUTION_WHEN_INTERACTING_FORBIDDEN, null);
        logError("SOLUTION_WHEN_INTERACTING_FORBIDDEN", null);
        return;
    } else if (itemSessionState.isEnded()) /* && !itemDeliverySettings.isAllowSoftResetWhenEnded() */
    {
        candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.SOLUTION_WHEN_ENDED_FORBIDDEN, null);
        logError("SOLUTION_WHEN_ENDED_FORBIDDEN", null);
        return;
    }
    /* End session if still open */
    final Date timestamp = ureq.getRequestTimestamp();
    boolean isClosingSession = false;
    if (!itemSessionState.isEnded()) {
        isClosingSession = true;
        try {
            itemSessionController.endItem(timestamp);
        } catch (final QtiCandidateStateException e) {
            candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.SOLUTION_WHEN_ENDED_FORBIDDEN, null);
            logError("SOLUTION_WHEN_ENDED_FORBIDDEN", e);
            return;
        } catch (final RuntimeException e) {
            logError("", e);
            // handleExplosion(e, candidateSession);
            return;
        }
    }
    /* Record current result state, and maybe close session */
    final AssessmentResult assessmentResult = computeAndRecordItemAssessmentResult(ureq);
    if (isClosingSession) {
        qtiService.finishItemSession(candidateSession, assessmentResult, timestamp);
    }
    /* Record and log event */
    final CandidateEvent candidateEvent = qtiService.recordCandidateItemEvent(candidateSession, null, entry, CandidateItemEventType.SOLUTION, itemSessionState);
    candidateAuditLogger.logCandidateEvent(candidateEvent);
    lastEvent = candidateEvent;
}
Also used : QtiCandidateStateException(uk.ac.ed.ph.jqtiplus.exception.QtiCandidateStateException) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) AssessmentResult(uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult) Date(java.util.Date) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent)

Example 39 with CandidateEvent

use of org.olat.ims.qti21.model.audit.CandidateEvent in project OpenOLAT by OpenOLAT.

the class AssessmentItemDisplayController method exitSession.

public void exitSession(UserRequest ureq) {
    ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
    /* Are we terminating a session that hasn't already been ended? If so end the session and record final result. */
    final Date currentTimestamp = ureq.getRequestTimestamp();
    if (!itemSessionState.isEnded()) {
        try {
            itemSessionController.endItem(currentTimestamp);
        } catch (final RuntimeException e) {
            logError("", e);
            // handleExplosion(e, candidateSession);
            return;
        }
        final AssessmentResult assessmentResult = computeAndRecordItemAssessmentResult(ureq);
        qtiService.finishItemSession(candidateSession, assessmentResult, currentTimestamp);
    }
    /* Update session entity */
    candidateSession.setTerminationTime(currentTimestamp);
    candidateSession = qtiService.updateAssessmentTestSession(candidateSession);
    /* Record and log event */
    final CandidateEvent candidateEvent = qtiService.recordCandidateItemEvent(candidateSession, null, entry, CandidateItemEventType.EXIT, itemSessionState);
    lastEvent = candidateEvent;
    candidateAuditLogger.logCandidateEvent(candidateEvent);
}
Also used : ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) AssessmentResult(uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult) Date(java.util.Date) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent)

Example 40 with CandidateEvent

use of org.olat.ims.qti21.model.audit.CandidateEvent in project OpenOLAT by OpenOLAT.

the class AssessmentTestDisplayController method initOrResumeAssessmentTestSession.

private void initOrResumeAssessmentTestSession(UserRequest ureq, boolean authorMode) {
    AssessmentEntry assessmentEntry = assessmentService.getOrCreateAssessmentEntry(assessedIdentity, anonymousIdentifier, entry, subIdent, testEntry);
    if (outcomesListener == null) {
        boolean manualCorrections = AssessmentTestHelper.needManualCorrection(resolvedAssessmentTest);
        outcomesListener = new AssessmentEntryOutcomesListener(entry, testEntry, assessmentEntry, manualCorrections, assessmentService, authorMode);
    }
    AssessmentTestSession lastSession = qtiService.getResumableAssessmentTestSession(assessedIdentity, anonymousIdentifier, entry, subIdent, testEntry, authorMode);
    if (lastSession == null) {
        initNewAssessmentTestSession(ureq, assessmentEntry, authorMode);
    } else {
        candidateSession = lastSession;
        extraTime = lastSession.getExtraTime();
        candidateAuditLogger = qtiService.getAssessmentSessionAuditLogger(candidateSession, authorMode);
        lastEvent = new CandidateEvent(candidateSession, testEntry, entry);
        lastEvent.setTestEventType(CandidateTestEventType.ITEM_EVENT);
        if (authorMode) {
            // check that the resumed session match the current test
            try {
                testSessionController = resumeSession(ureq);
                if (!checkAuthorSession()) {
                    initNewAssessmentTestSession(ureq, assessmentEntry, authorMode);
                }
            } catch (Exception e) {
                logError("Cannot resume session as author", e);
                initNewAssessmentTestSession(ureq, assessmentEntry, authorMode);
            }
        } else {
            testSessionController = resumeSession(ureq);
        }
    }
}
Also used : AssessmentTestSession(org.olat.ims.qti21.AssessmentTestSession) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) ResponseBindingException(uk.ac.ed.ph.jqtiplus.exception.ResponseBindingException) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) QtiCandidateStateException(uk.ac.ed.ph.jqtiplus.exception.QtiCandidateStateException) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent)

Aggregations

CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)54 NotificationRecorder (uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder)36 Date (java.util.Date)34 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)32 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)22 QtiCandidateStateException (uk.ac.ed.ph.jqtiplus.exception.QtiCandidateStateException)21 AssessmentResult (uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult)20 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)20 TestPlanNodeKey (uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)16 TestPlanNode (uk.ac.ed.ph.jqtiplus.state.TestPlanNode)14 CandidateTestEventType (org.olat.ims.qti21.model.audit.CandidateTestEventType)12 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)10 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)10 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)10 HashMap (java.util.HashMap)8 CandidateItemEventType (org.olat.ims.qti21.model.audit.CandidateItemEventType)8 CandidateSessionContext (org.olat.ims.qti21.ui.CandidateSessionContext)8 StringInput (org.olat.ims.qti21.ui.ResponseInput.StringInput)8 FileResponseData (uk.ac.ed.ph.jqtiplus.types.FileResponseData)8 ResponseData (uk.ac.ed.ph.jqtiplus.types.ResponseData)8