Search in sources :

Example 6 with QtiXmlInterpretationException

use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project openolat by klemens.

the class QTI21ServiceImpl method getAssessmentResult.

@Override
public AssessmentResult getAssessmentResult(AssessmentTestSession candidateSession) {
    File assessmentResultFile = getAssessmentResultFile(candidateSession);
    ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentResultFile.getParentFile().toPath());
    ResourceLocator inputResourceLocator = ImsQTI21Resource.createResolvingResourceLocator(fileResourceLocator);
    URI assessmentResultUri = assessmentResultFile.toURI();
    QtiObjectReader qtiObjectReader = qtiXmlReader().createQtiObjectReader(inputResourceLocator, false, false);
    try {
        QtiObjectReadResult<AssessmentResult> result = qtiObjectReader.lookupRootNode(assessmentResultUri, AssessmentResult.class);
        return result.getRootNode();
    } catch (XmlResourceNotFoundException | QtiXmlInterpretationException | ClassCastException e) {
        log.error("", e);
        return null;
    }
}
Also used : ClassPathResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ClassPathResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) XmlResourceNotFoundException(uk.ac.ed.ph.jqtiplus.xmlutils.XmlResourceNotFoundException) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) QtiObjectReader(uk.ac.ed.ph.jqtiplus.reading.QtiObjectReader) File(java.io.File) URI(java.net.URI) AssessmentResult(uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult) ClassPathResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ClassPathResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)

Example 7 with QtiXmlInterpretationException

use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project openolat by klemens.

the class CopyAndConvertVisitor method validate.

private boolean validate(Path inputFile, InputType type, boolean verbose) {
    try {
        QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
        ResourceLocator fileResourceLocator = new PathResourceLocator(inputFile.getParent());
        AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
        RootNode rootNode = null;
        BadResourceException e = null;
        URI uri = new URI("zip", inputFile.getFileName().toString(), null);
        if (type == InputType.assessmentItem) {
            ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(uri);
            e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
            ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(uri);
            rootNode = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
        } else if (type == InputType.assessmentTest) {
            TestValidationResult testResult = assessmentObjectXmlLoader.loadResolveAndValidateTest(uri);
            e = testResult.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
            ResolvedAssessmentTest resolvedAssessmentTest = assessmentObjectXmlLoader.loadAndResolveAssessmentTest(uri);
            rootNode = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
        }
        if (e != null && verbose) {
            StringBuilder err = new StringBuilder();
            BadRessourceHelper.extractMessage(e, err);
            log.warn(err.toString());
        }
        return (rootNode != null) && (e == null || (e instanceof QtiXmlInterpretationException && ((QtiXmlInterpretationException) e).getXmlParseResult().getFatalErrors().isEmpty()));
    } catch (URISyntaxException e) {
        log.error("", e);
        return false;
    }
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) RootNode(uk.ac.ed.ph.jqtiplus.node.RootNode) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) TestValidationResult(uk.ac.ed.ph.jqtiplus.validation.TestValidationResult) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) URISyntaxException(java.net.URISyntaxException) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) URI(java.net.URI) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)

Example 8 with QtiXmlInterpretationException

use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project openolat by klemens.

the class AssessmentTestDisplayController method getTestProcessingMap.

private TestProcessingMap getTestProcessingMap() {
    boolean assessmentPackageIsValid = true;
    BadResourceException ex = resolvedAssessmentTest.getTestLookup().getBadResourceException();
    if (ex instanceof QtiXmlInterpretationException) {
        try {
            // try to log some informations
            QtiXmlInterpretationException exml = (QtiXmlInterpretationException) ex;
            logError(exml.getInterpretationFailureReason().toString(), null);
            for (QtiModelBuildingError err : exml.getQtiModelBuildingErrors()) {
                logError(err.toString(), null);
            }
        } catch (Exception e) {
            logError("", e);
        }
    }
    TestProcessingInitializer initializer = new TestProcessingInitializer(resolvedAssessmentTest, assessmentPackageIsValid);
    TestProcessingMap result = initializer.initialize();
    return result;
}
Also used : TestProcessingMap(uk.ac.ed.ph.jqtiplus.state.TestProcessingMap) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) TestProcessingInitializer(uk.ac.ed.ph.jqtiplus.running.TestProcessingInitializer) QtiModelBuildingError(uk.ac.ed.ph.jqtiplus.reading.QtiModelBuildingError) 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)

Aggregations

QtiXmlInterpretationException (uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException)8 URI (java.net.URI)4 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)4 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)4 QtiModelBuildingError (uk.ac.ed.ph.jqtiplus.reading.QtiModelBuildingError)4 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)4 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 SAXParseException (org.xml.sax.SAXParseException)2 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)2 QtiCandidateStateException (uk.ac.ed.ph.jqtiplus.exception.QtiCandidateStateException)2 ResponseBindingException (uk.ac.ed.ph.jqtiplus.exception.ResponseBindingException)2 RootNode (uk.ac.ed.ph.jqtiplus.node.RootNode)2 AssessmentResult (uk.ac.ed.ph.jqtiplus.node.result.AssessmentResult)2 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)2 QtiObjectReader (uk.ac.ed.ph.jqtiplus.reading.QtiObjectReader)2 InterpretationFailureReason (uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException.InterpretationFailureReason)2 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)2 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)2