Search in sources :

Example 11 with QtiParseException

use of uk.ac.ed.ph.jqtiplus.exception.QtiParseException in project openolat by klemens.

the class AbstractQtiWorksController method processResponse.

protected void processResponse(UserRequest ureq, FormItem source) {
    Map<Identifier, ResponseInput> stringResponseMap = extractStringResponseData();
    Map<Identifier, ResponseInput> fileResponseMap;
    if (mainForm.isMultipartEnabled()) {
        fileResponseMap = extractFileResponseData();
    } else {
        fileResponseMap = Collections.emptyMap();
    }
    if (source instanceof FormLink) {
        FormLink button = (FormLink) source;
        String cmd = button.getCmd();
        if (cmd != null && cmd.startsWith("qtiworks_response_")) {
            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;
                if (button.getUserObject() instanceof EndAttemptInteraction) {
                    responseValues = new String[] { ((EndAttemptInteraction) button.getUserObject()).getTitle() };
                } else {
                    responseValues = new String[] { "submit" };
                }
                StringInput stringResponseData = new StringInput(responseValues);
                stringResponseMap.put(responseIdentifier, stringResponseData);
            }
        }
    }
    String candidateComment = extractComment();
    fireResponse(ureq, source, stringResponseMap, fileResponseMap, candidateComment);
}
Also used : StringInput(org.olat.ims.qti21.ui.ResponseInput.StringInput) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) EndAttemptInteraction(uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) QtiParseException(uk.ac.ed.ph.jqtiplus.exception.QtiParseException)

Example 12 with QtiParseException

use of uk.ac.ed.ph.jqtiplus.exception.QtiParseException in project openolat by klemens.

the class AssessmentObjectFormItem method extractFileResponseData.

protected Map<Identifier, MultipartFileInfos> extractFileResponseData() {
    Map<Identifier, MultipartFileInfos> fileResponseMap = new HashMap<Identifier, MultipartFileInfos>();
    Set<String> parameterNames = new HashSet<>(getRootForm().getRequestMultipartFilesSet());
    parameterNames.addAll(getRootForm().getRequestParameterSet());
    for (String name : parameterNames) {
        if (name.startsWith("qtiworks_uploadpresented_")) {
            String responseIdentifierString = name.substring("qtiworks_uploadpresented_".length());
            Identifier responseIdentifier;
            try {
                responseIdentifier = Identifier.parseString(responseIdentifierString);
            } catch (final QtiParseException e) {
                throw new RuntimeException("Bad response identifier encoded in parameter " + name, e);
            }
            String multipartName = "qtiworks_uploadresponse_" + responseIdentifierString;
            MultipartFileInfos multipartFile = getRootForm().getRequestMultipartFileInfos(multipartName);
            if (multipartFile == null) {
                throw new RuntimeException("Expected to find multipart file with name " + multipartName);
            }
            fileResponseMap.put(responseIdentifier, multipartFile);
        }
    }
    return fileResponseMap;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HashMap(java.util.HashMap) MultipartFileInfos(org.olat.core.gui.components.form.flexible.impl.MultipartFileInfos) QtiParseException(uk.ac.ed.ph.jqtiplus.exception.QtiParseException) HashSet(java.util.HashSet)

Aggregations

QtiParseException (uk.ac.ed.ph.jqtiplus.exception.QtiParseException)12 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)12 HashMap (java.util.HashMap)8 StringInput (org.olat.ims.qti21.ui.ResponseInput.StringInput)6 HashSet (java.util.HashSet)4 MultipartFileInfos (org.olat.core.gui.components.form.flexible.impl.MultipartFileInfos)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 Base64Input (org.olat.ims.qti21.ui.ResponseInput.Base64Input)2 FileInput (org.olat.ims.qti21.ui.ResponseInput.FileInput)2 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)2 StringResponseData (uk.ac.ed.ph.jqtiplus.types.StringResponseData)2