Search in sources :

Example 56 with ItemSessionState

use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState 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 57 with ItemSessionState

use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.

the class AssessmentItemDisplayController method updateSessionFinishedStatus.

private AssessmentTestSession updateSessionFinishedStatus(UserRequest ureq) {
    /* Record current result state and maybe close session */
    final ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
    final AssessmentResult assessmentResult = computeAndRecordItemAssessmentResult(ureq);
    if (itemSessionState.isEnded()) {
        qtiService.finishItemSession(candidateSession, assessmentResult, null);
    } else {
        if (candidateSession != null && candidateSession.getFinishTime() != null) {
            /* (Session is being reopened) */
            candidateSession.setFinishTime(null);
            candidateSession = qtiService.updateAssessmentTestSession(candidateSession);
        }
    }
    return candidateSession;
}
Also used : ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) AssessmentResult(uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult)

Example 58 with ItemSessionState

use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.

the class AssessmentTestDisplayController method resumeSession.

private TestSessionController resumeSession(UserRequest ureq) {
    Date requestTimestamp = ureq.getRequestTimestamp();
    final NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
    TestSessionController controller = createTestSessionController(notificationRecorder);
    if (!controller.getTestSessionState().isEnded() && !controller.getTestSessionState().isExited()) {
        controller.unsuspendTestSession(requestTimestamp);
        TestSessionState testSessionState = controller.getTestSessionState();
        TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
        if (currentItemKey != null) {
            TestPlanNode currentItemNode = testSessionState.getTestPlan().getNode(currentItemKey);
            ItemProcessingContext itemProcessingContext = controller.getItemProcessingContext(currentItemNode);
            ItemSessionState itemSessionState = itemProcessingContext.getItemSessionState();
            if (itemProcessingContext instanceof ItemSessionController && itemSessionState.isSuspended()) {
                ItemSessionController itemSessionController = (ItemSessionController) itemProcessingContext;
                itemSessionController.unsuspendItemSession(requestTimestamp);
            }
        }
    }
    return controller;
}
Also used : TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) NotificationRecorder(uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder) TestSessionController(uk.ac.ed.ph.jqtiplus.running.TestSessionController) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) Date(java.util.Date) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey) ItemProcessingContext(uk.ac.ed.ph.jqtiplus.running.ItemProcessingContext)

Example 59 with ItemSessionState

use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.

the class AssessmentTestDisplayController method handleResponse.

// public CandidateSession handleResponses(final CandidateSessionContext candidateSessionContext,
// final Map<Identifier, StringResponseData> stringResponseMap,
// final Map<Identifier, MultipartFile> fileResponseMap,
// final String candidateComment)
private void handleResponse(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap, Map<Identifier, ResponseInput> fileResponseMap, String candidateComment) {
    NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
    TestSessionState testSessionState = testSessionController.getTestSessionState();
    TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
    if (currentItemKey == null && getLastEvent() != null && getLastEvent().getTestEventType() == CandidateTestEventType.REVIEW_ITEM) {
        // someone try to send the form in review with tab / return
        return;
    }
    if (!qtiWorksCtrl.validatePresentedItem(currentItemKey)) {
        logError("Response send by browser doesn't match current item key", null);
        ServletUtil.printOutRequestParameters(ureq.getHttpReq());
        if (candidateSession != null && candidateSession.getFinishTime() != null) {
            showWarning("error.test.closed");
        } else {
            showWarning("error.reload.question");
        }
        // this is not the right node in the plan
        return;
    }
    final Map<Identifier, File> fileSubmissionMap = new HashMap<>();
    final Map<Identifier, ResponseData> responseDataMap = new HashMap<>();
    if (stringResponseMap != null) {
        for (final Entry<Identifier, ResponseInput> responseEntry : stringResponseMap.entrySet()) {
            final Identifier identifier = responseEntry.getKey();
            final ResponseInput responseData = responseEntry.getValue();
            if (responseData instanceof StringInput) {
                responseDataMap.put(identifier, new StringResponseData(((StringInput) responseData).getResponseData()));
            } else if (responseData instanceof Base64Input) {
                // only used from drawing interaction
                Base64Input fileInput = (Base64Input) responseData;
                String filename = "submitted_image.png";
                File storedFile = qtiService.importFileSubmission(candidateSession, filename, fileInput.getResponseData());
                responseDataMap.put(identifier, new FileResponseData(storedFile, fileInput.getContentType(), storedFile.getName()));
                fileSubmissionMap.put(identifier, storedFile);
            } else if (responseData instanceof FileInput) {
                FileInput fileInput = (FileInput) responseData;
                File storedFile = qtiService.importFileSubmission(candidateSession, fileInput.getMultipartFileInfos());
                responseDataMap.put(identifier, new FileResponseData(storedFile, fileInput.getContentType(), storedFile.getName()));
                fileSubmissionMap.put(identifier, storedFile);
            }
        }
    }
    ParentPartItemRefs parentParts = getParentSection(currentItemKey);
    String assessmentItemIdentifier = currentItemKey.getIdentifier().toString();
    AssessmentItemSession itemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, assessmentItemIdentifier);
    if (fileResponseMap != null) {
        for (Entry<Identifier, ResponseInput> fileResponseEntry : fileResponseMap.entrySet()) {
            Identifier identifier = fileResponseEntry.getKey();
            FileInput multipartFile = (FileInput) fileResponseEntry.getValue();
            if (!multipartFile.isEmpty()) {
                File storedFile = qtiService.importFileSubmission(candidateSession, multipartFile.getMultipartFileInfos());
                responseDataMap.put(identifier, new FileResponseData(storedFile, multipartFile.getContentType(), storedFile.getName()));
                fileSubmissionMap.put(identifier, storedFile);
            }
        }
    }
    Map<Identifier, AssessmentResponse> candidateResponseMap = qtiService.getAssessmentResponses(itemSession);
    for (Entry<Identifier, ResponseData> responseEntry : responseDataMap.entrySet()) {
        Identifier responseIdentifier = responseEntry.getKey();
        ResponseData responseData = responseEntry.getValue();
        AssessmentResponse candidateItemResponse;
        if (candidateResponseMap.containsKey(responseIdentifier)) {
            candidateItemResponse = candidateResponseMap.get(responseIdentifier);
        } else {
            candidateItemResponse = qtiService.createAssessmentResponse(candidateSession, itemSession, responseIdentifier.toString(), ResponseLegality.VALID, responseData.getType());
        }
        switch(responseData.getType()) {
            case STRING:
                {
                    List<String> data = ((StringResponseData) responseData).getResponseData();
                    String stringuifiedResponse = ResponseFormater.format(data);
                    candidateItemResponse.setStringuifiedResponse(stringuifiedResponse);
                    break;
                }
            case FILE:
                {
                    if (fileSubmissionMap.get(responseIdentifier) != null) {
                        File storedFile = fileSubmissionMap.get(responseIdentifier);
                        candidateItemResponse.setStringuifiedResponse(storedFile.getName());
                    }
                    break;
                }
            default:
                throw new OLATRuntimeException("Unexpected switch case: " + responseData.getType());
        }
        candidateResponseMap.put(responseIdentifier, candidateItemResponse);
    }
    boolean allResponsesValid = true;
    boolean allResponsesBound = true;
    final Date timestamp = ureq.getRequestTimestamp();
    if (candidateComment != null) {
        testSessionController.setCandidateCommentForCurrentItem(timestamp, candidateComment);
    }
    /* Attempt to bind responses (and maybe perform RP & OP) */
    testSessionController.handleResponsesToCurrentItem(timestamp, responseDataMap);
    /* Classify this event */
    final SubmissionMode submissionMode = testSessionController.getCurrentTestPart().getSubmissionMode();
    final CandidateItemEventType candidateItemEventType;
    if (allResponsesValid) {
        candidateItemEventType = submissionMode == SubmissionMode.INDIVIDUAL ? CandidateItemEventType.ATTEMPT_VALID : CandidateItemEventType.RESPONSE_VALID;
    } else {
        candidateItemEventType = allResponsesBound ? CandidateItemEventType.RESPONSE_INVALID : CandidateItemEventType.RESPONSE_BAD;
    }
    /* Record resulting event */
    final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.ITEM_EVENT, candidateItemEventType, currentItemKey, testSessionState, notificationRecorder);
    candidateAuditLogger.logCandidateEvent(candidateEvent, candidateResponseMap);
    this.lastEvent = candidateEvent;
    /* Record current result state */
    AssessmentResult assessmentResult = computeAndRecordTestAssessmentResult(timestamp, testSessionState, false);
    ItemSessionState itemSessionState = testSessionState.getCurrentItemSessionState();
    long itemDuration = itemSessionState.getDurationAccumulated();
    itemSession.setDuration(itemDuration);
    ItemResult itemResult = assessmentResult.getItemResult(assessmentItemIdentifier);
    collectOutcomeVariablesForItemSession(itemResult, itemSession);
    /* Persist CandidateResponse entities */
    qtiService.recordTestAssessmentResponses(itemSession, candidateResponseMap.values());
    /* Save any change to session state */
    candidateSession = qtiService.updateAssessmentTestSession(candidateSession);
    addToHistory(ureq, this);
    checkConcurrentExit(ureq);
}
Also used : TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) HashMap(java.util.HashMap) FileInput(org.olat.ims.qti21.ui.ResponseInput.FileInput) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) SubmissionMode(uk.ac.ed.ph.jqtiplus.node.test.SubmissionMode) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) AssessmentItemSession(org.olat.ims.qti21.AssessmentItemSession) List(java.util.List) AssessmentResult(uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult) ParentPartItemRefs(org.olat.ims.qti21.model.ParentPartItemRefs) CandidateItemEventType(org.olat.ims.qti21.model.audit.CandidateItemEventType) FileResponseData(uk.ac.ed.ph.jqtiplus.types.FileResponseData) StringResponseData(uk.ac.ed.ph.jqtiplus.types.StringResponseData) ResponseData(uk.ac.ed.ph.jqtiplus.types.ResponseData) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) NotificationRecorder(uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Date(java.util.Date) StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) ItemResult(uk.ac.ed.ph.jqtiplus.node.result.ItemResult) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) FileResponseData(uk.ac.ed.ph.jqtiplus.types.FileResponseData) Base64Input(org.olat.ims.qti21.ui.ResponseInput.Base64Input) File(java.io.File) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 60 with ItemSessionState

use of uk.ac.ed.ph.jqtiplus.state.ItemSessionState in project OpenOLAT by OpenOLAT.

the class AssessmentTestDisplayController method suspendAssessmentTest.

/**
 * It suspend the current item
 * @return
 */
private boolean suspendAssessmentTest(Date requestTimestamp) {
    if (!deliveryOptions.isEnableSuspend() || testSessionController == null || testSessionController.getTestSessionState() == null || testSessionController.getTestSessionState().isEnded() || testSessionController.getTestSessionState().isExited() || testSessionController.getTestSessionState().isSuspended()) {
        return false;
    }
    testSessionController.touchDurations(currentRequestTimestamp);
    testSessionController.suspendTestSession(requestTimestamp);
    TestSessionState testSessionState = testSessionController.getTestSessionState();
    TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
    if (currentItemKey == null) {
        return false;
    }
    TestPlanNode currentItemNode = testSessionState.getTestPlan().getNode(currentItemKey);
    ItemProcessingContext itemProcessingContext = testSessionController.getItemProcessingContext(currentItemNode);
    ItemSessionState itemSessionState = itemProcessingContext.getItemSessionState();
    if (itemProcessingContext instanceof ItemSessionController && !itemSessionState.isEnded() && !itemSessionState.isExited() && itemSessionState.isOpen() && !itemSessionState.isSuspended()) {
        ItemSessionController itemSessionController = (ItemSessionController) itemProcessingContext;
        itemSessionController.suspendItemSession(requestTimestamp);
        computeAndRecordTestAssessmentResult(requestTimestamp, testSessionState, false);
        NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
        final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.SUSPEND, null, null, testSessionState, notificationRecorder);
        candidateAuditLogger.logCandidateEvent(candidateEvent);
        this.lastEvent = candidateEvent;
        return true;
    }
    return false;
}
Also used : TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) NotificationRecorder(uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey) ItemProcessingContext(uk.ac.ed.ph.jqtiplus.running.ItemProcessingContext) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent)

Aggregations

ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)88 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)30 Date (java.util.Date)28 HashMap (java.util.HashMap)28 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)28 TestPlanNodeKey (uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)26 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)24 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)24 TestPlanNode (uk.ac.ed.ph.jqtiplus.state.TestPlanNode)22 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)20 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)20 NotificationRecorder (uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder)20 ItemSessionController (uk.ac.ed.ph.jqtiplus.running.ItemSessionController)20 ArrayList (java.util.ArrayList)18 Map (java.util.Map)18 ResponseData (uk.ac.ed.ph.jqtiplus.types.ResponseData)18 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)16 List (java.util.List)14 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)12 Flow (uk.ac.ed.ph.jqtiplus.node.content.basic.Flow)12