Search in sources :

Example 1 with RootNode

use of uk.ac.ed.ph.jqtiplus.node.RootNode in project OpenOLAT by OpenOLAT.

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 2 with RootNode

use of uk.ac.ed.ph.jqtiplus.node.RootNode 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)

Aggregations

URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)2 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)2 RootNode (uk.ac.ed.ph.jqtiplus.node.RootNode)2 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)2 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)2 QtiXmlInterpretationException (uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException)2 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)2 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)2 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)2 ItemValidationResult (uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)2 TestValidationResult (uk.ac.ed.ph.jqtiplus.validation.TestValidationResult)2 FileResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator)2 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)2