Search in sources :

Example 1 with QtiParseException

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

the class AbstractQtiWorksController method extractFileResponseData.

protected Map<Identifier, ResponseInput> extractFileResponseData() {
    Map<Identifier, ResponseInput> fileResponseMap = new HashMap<>();
    Set<String> parameterNames = new HashSet<>(mainForm.getRequestMultipartFilesSet());
    parameterNames.addAll(mainForm.getRequestParameterSet());
    for (String name : parameterNames) {
        if (name.startsWith("qtiworks_uploadpresented_")) {
            String responseIdentifierString = name.substring("qtiworks_uploadpresented_".length());
            Identifier responseIdentifier;
            try {
                responseIdentifier = getResponseIdentifierFromUniqueId(responseIdentifierString);
            // 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 = mainForm.getRequestMultipartFileInfos(multipartName);
            if (multipartFile == null) {
                throw new RuntimeException("Expected to find multipart file with name " + multipartName);
            }
            fileResponseMap.put(responseIdentifier, new FileInput(multipartFile));
        }
    }
    return fileResponseMap;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HashMap(java.util.HashMap) FileInput(org.olat.ims.qti21.ui.ResponseInput.FileInput) MultipartFileInfos(org.olat.core.gui.components.form.flexible.impl.MultipartFileInfos) QtiParseException(uk.ac.ed.ph.jqtiplus.exception.QtiParseException) HashSet(java.util.HashSet)

Example 2 with QtiParseException

use of uk.ac.ed.ph.jqtiplus.exception.QtiParseException 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 3 with QtiParseException

use of uk.ac.ed.ph.jqtiplus.exception.QtiParseException 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 4 with QtiParseException

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

the class AbstractQtiWorksController method extractFileResponseData.

protected Map<Identifier, ResponseInput> extractFileResponseData() {
    Map<Identifier, ResponseInput> fileResponseMap = new HashMap<>();
    Set<String> parameterNames = new HashSet<>(mainForm.getRequestMultipartFilesSet());
    parameterNames.addAll(mainForm.getRequestParameterSet());
    for (String name : parameterNames) {
        if (name.startsWith("qtiworks_uploadpresented_")) {
            String responseIdentifierString = name.substring("qtiworks_uploadpresented_".length());
            Identifier responseIdentifier;
            try {
                responseIdentifier = getResponseIdentifierFromUniqueId(responseIdentifierString);
            // 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 = mainForm.getRequestMultipartFileInfos(multipartName);
            if (multipartFile == null) {
                throw new RuntimeException("Expected to find multipart file with name " + multipartName);
            }
            fileResponseMap.put(responseIdentifier, new FileInput(multipartFile));
        }
    }
    return fileResponseMap;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) HashMap(java.util.HashMap) FileInput(org.olat.ims.qti21.ui.ResponseInput.FileInput) MultipartFileInfos(org.olat.core.gui.components.form.flexible.impl.MultipartFileInfos) QtiParseException(uk.ac.ed.ph.jqtiplus.exception.QtiParseException) HashSet(java.util.HashSet)

Example 5 with QtiParseException

use of uk.ac.ed.ph.jqtiplus.exception.QtiParseException 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

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