Search in sources :

Example 1 with StringInput

use of org.olat.ims.qti21.ui.ResponseInput.StringInput in project OpenOLAT by OpenOLAT.

the class AbstractQtiWorksController method processTemporaryResponse.

protected void processTemporaryResponse(UserRequest ureq) {
    Map<Identifier, ResponseInput> stringResponseMap = extractStringResponseData();
    String cmd = ureq.getParameter("tmpResponse");
    String responseIdentifierString = cmd.substring("qtiworks_response_".length());
    String presentedFlag = "qtiworks_presented_".concat(responseIdentifierString);
    if (mainForm.getRequestParameterSet().contains(presentedFlag)) {
        Identifier responseIdentifier;
        try {
            responseIdentifier = getResponseIdentifierFromUniqueId(responseIdentifierString);
        // Identifier.parseString(responseIdentifierString);
        } catch (final QtiParseException e) {
            throw new RuntimeException("Bad response identifier encoded in parameter " + cmd, e);
        }
        String[] responseValues = new String[] { "submit" };
        StringInput stringResponseData = new StringInput(responseValues);
        stringResponseMap.put(responseIdentifier, stringResponseData);
    }
    fireTemporaryResponse(ureq, stringResponseMap);
}
Also used : StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) QtiParseException(uk.ac.ed.ph.jqtiplus.exception.QtiParseException)

Example 2 with StringInput

use of org.olat.ims.qti21.ui.ResponseInput.StringInput in project OpenOLAT by OpenOLAT.

the class AssessmentItemDisplayController method handleTemporaryResponses.

public void handleTemporaryResponses(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap) {
    /* 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, 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()));
            }
        }
    }
    final Date timestamp = ureq.getRequestTimestamp();
    /* Attempt to bind responses */
    boolean allResponsesValid = false;
    boolean allResponsesBound = false;
    try {
        itemSessionController.bindResponses(timestamp, responseDataMap);
    } catch (final QtiCandidateStateException e) {
        candidateAuditLogger.logAndThrowCandidateException(candidateSession, CandidateExceptionReason.RESPONSES_NOT_EXPECTED, null);
        logError("RESPONSES_NOT_EXPECTED", e);
        return;
    } catch (final RuntimeException e) {
        logError("", e);
        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;
}
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) 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)

Example 3 with StringInput

use of org.olat.ims.qti21.ui.ResponseInput.StringInput in project OpenOLAT by OpenOLAT.

the class AssessmentTestDisplayController method handleTemporaryResponse.

private void handleTemporaryResponse(UserRequest ureq, Map<Identifier, ResponseInput> stringResponseMap) {
    NotificationRecorder notificationRecorder = new NotificationRecorder(NotificationLevel.INFO);
    TestSessionState testSessionState = testSessionController.getTestSessionState();
    TestPlanNodeKey currentItemKey = testSessionState.getCurrentItemKey();
    if (currentItemKey == null) {
        // 
        return;
    }
    String cmd = ureq.getParameter("tmpResponse");
    if (!qtiWorksCtrl.validateResponseIdentifierCommand(cmd, currentItemKey)) {
        // this is not the right node in the plan
        return;
    }
    final Date timestamp = ureq.getRequestTimestamp();
    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()));
            }
        }
    }
    ParentPartItemRefs parentParts = getParentSection(currentItemKey);
    String assessmentItemIdentifier = currentItemKey.getIdentifier().toString();
    AssessmentItemSession itemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, assessmentItemIdentifier);
    TestPlanNode currentItemRefNode = testSessionState.getTestPlan().getNode(currentItemKey);
    ItemSessionController itemSessionController = (ItemSessionController) testSessionController.getItemProcessingContext(currentItemRefNode);
    ItemSessionState itemSessionState = itemSessionController.getItemSessionState();
    List<Interaction> interactions = itemSessionController.getInteractions();
    Map<Identifier, Interaction> interactionMap = new HashMap<>();
    for (Interaction interaction : interactions) {
        interactionMap.put(interaction.getResponseIdentifier(), interaction);
    }
    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;
                }
            default:
                throw new OLATRuntimeException("Unexpected switch case: " + responseData.getType());
        }
        candidateResponseMap.put(responseIdentifier, candidateItemResponse);
        itemSessionState.setRawResponseData(responseIdentifier, responseData);
        try {
            Interaction interaction = interactionMap.get(responseIdentifier);
            interaction.bindResponse(itemSessionController, responseData);
        } catch (final ResponseBindingException e) {
        // 
        }
    }
    /* Copy uncommitted responses over */
    for (final Entry<Identifier, Value> uncommittedResponseEntry : itemSessionState.getUncommittedResponseValues().entrySet()) {
        final Identifier identifier = uncommittedResponseEntry.getKey();
        final Value value = uncommittedResponseEntry.getValue();
        itemSessionState.setResponseValue(identifier, value);
    }
    /* Persist CandidateResponse entities */
    qtiService.recordTestAssessmentResponses(itemSession, candidateResponseMap.values());
    /* Record resulting event */
    final CandidateEvent candidateEvent = qtiService.recordCandidateTestEvent(candidateSession, testEntry, entry, CandidateTestEventType.ITEM_EVENT, null, currentItemKey, testSessionState, notificationRecorder);
    candidateAuditLogger.logCandidateEvent(candidateEvent, candidateResponseMap);
    /* Record current result state */
    AssessmentResult assessmentResult = computeTestAssessmentResult(timestamp, candidateSession);
    synchronized (this) {
        qtiService.recordTestAssessmentResult(candidateSession, testSessionState, assessmentResult, candidateAuditLogger);
    }
}
Also used : TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) HashMap(java.util.HashMap) ResponseBindingException(uk.ac.ed.ph.jqtiplus.exception.ResponseBindingException) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) 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) TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) Interaction(uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction) 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) ItemSessionController(uk.ac.ed.ph.jqtiplus.running.ItemSessionController) AssessmentResponse(org.olat.ims.qti21.AssessmentResponse) Date(java.util.Date) StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Value(uk.ac.ed.ph.jqtiplus.value.Value) NumberValue(uk.ac.ed.ph.jqtiplus.value.NumberValue) FloatValue(uk.ac.ed.ph.jqtiplus.value.FloatValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) BooleanValue(uk.ac.ed.ph.jqtiplus.value.BooleanValue) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Example 4 with StringInput

use of org.olat.ims.qti21.ui.ResponseInput.StringInput in project openolat by klemens.

the class AbstractQtiWorksController method extractStringResponseData.

protected Map<Identifier, ResponseInput> extractStringResponseData() {
    final Map<Identifier, ResponseInput> responseMap = new HashMap<>();
    final Set<String> parameterNames = mainForm.getRequestParameterSet();
    for (final String name : parameterNames) {
        if (name.startsWith("qtiworks_presented_")) {
            final String responseIdentifierString = name.substring("qtiworks_presented_".length());
            final Identifier responseIdentifier;
            try {
                responseIdentifier = getResponseIdentifierFromUniqueId(responseIdentifierString);
            // responseIdentifier = Identifier.parseString(responseIdentifierString);
            } catch (final QtiParseException e) {
                // throw new BadResponseWebPayloadException("Bad response identifier encoded in parameter  " + name, e);
                throw new RuntimeException("Bad response identifier encoded in parameter  " + name, e);
            }
            String[] responseBase64Values = mainForm.getRequestParameterValues("qtiworks_response_64_" + responseIdentifierString);
            if (responseBase64Values != null && responseBase64Values.length == 1) {
                // only used from drawing interaction as image/png
                String responseData = responseBase64Values[0];
                if (responseData.startsWith(PNG_BASE64_PREFIX)) {
                    byte[] file = Base64.decodeBase64(responseData.substring(PNG_BASE64_PREFIX.length(), responseData.length()));
                    final Base64Input stringResponseData = new Base64Input("image/png", file);
                    responseMap.put(responseIdentifier, stringResponseData);
                }
            } else {
                final String[] responseValues = mainForm.getRequestParameterValues("qtiworks_response_" + responseIdentifierString);
                if (responseValues != null && responseValues.length > 0) {
                    for (int i = responseValues.length; i-- > 0; ) {
                        responseValues[i] = FilterFactory.getXMLValidCharacterFilter().filter(responseValues[i]);
                    }
                }
                final StringInput stringResponseData = new StringInput(responseValues);
                responseMap.put(responseIdentifier, stringResponseData);
            }
        }
    }
    return responseMap;
}
Also used : HashMap(java.util.HashMap) StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) Base64Input(org.olat.ims.qti21.ui.ResponseInput.Base64Input) QtiParseException(uk.ac.ed.ph.jqtiplus.exception.QtiParseException)

Example 5 with StringInput

use of org.olat.ims.qti21.ui.ResponseInput.StringInput in project openolat by klemens.

the class AbstractQtiWorksController method processTemporaryResponse.

protected void processTemporaryResponse(UserRequest ureq) {
    Map<Identifier, ResponseInput> stringResponseMap = extractStringResponseData();
    String cmd = ureq.getParameter("tmpResponse");
    String responseIdentifierString = cmd.substring("qtiworks_response_".length());
    String presentedFlag = "qtiworks_presented_".concat(responseIdentifierString);
    if (mainForm.getRequestParameterSet().contains(presentedFlag)) {
        Identifier responseIdentifier;
        try {
            responseIdentifier = getResponseIdentifierFromUniqueId(responseIdentifierString);
        // Identifier.parseString(responseIdentifierString);
        } catch (final QtiParseException e) {
            throw new RuntimeException("Bad response identifier encoded in parameter " + cmd, e);
        }
        String[] responseValues = new String[] { "submit" };
        StringInput stringResponseData = new StringInput(responseValues);
        stringResponseMap.put(responseIdentifier, stringResponseData);
    }
    fireTemporaryResponse(ureq, stringResponseMap);
}
Also used : StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) QtiParseException(uk.ac.ed.ph.jqtiplus.exception.QtiParseException)

Aggregations

StringInput (org.olat.ims.qti21.ui.ResponseInput.StringInput)14 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)14 HashMap (java.util.HashMap)10 Date (java.util.Date)8 AssessmentResponse (org.olat.ims.qti21.AssessmentResponse)8 CandidateEvent (org.olat.ims.qti21.model.audit.CandidateEvent)8 NotificationRecorder (uk.ac.ed.ph.jqtiplus.notification.NotificationRecorder)8 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)8 FileResponseData (uk.ac.ed.ph.jqtiplus.types.FileResponseData)8 ResponseData (uk.ac.ed.ph.jqtiplus.types.ResponseData)8 StringResponseData (uk.ac.ed.ph.jqtiplus.types.StringResponseData)8 CandidateItemEventType (org.olat.ims.qti21.model.audit.CandidateItemEventType)6 Base64Input (org.olat.ims.qti21.ui.ResponseInput.Base64Input)6 QtiParseException (uk.ac.ed.ph.jqtiplus.exception.QtiParseException)6 File (java.io.File)4 List (java.util.List)4 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)4 AssessmentItemSession (org.olat.ims.qti21.AssessmentItemSession)4 ParentPartItemRefs (org.olat.ims.qti21.model.ParentPartItemRefs)4 AssessmentResponseData (org.olat.ims.qti21.model.audit.AssessmentResponseData)4