Search in sources :

Example 16 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project OpenOLAT by OpenOLAT.

the class OpenOLATAssessementItemsTest method ourItem.

@Test
public void ourItem() throws IOException, XMLStreamException, SAXException, ParserConfigurationException, URISyntaxException {
    URL xmlUrl = OpenOLATAssessementItemsTest.class.getResource("resources/openolat/" + xmlFilename);
    File xmlFile = new File(xmlUrl.toURI());
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(xmlFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(xmlFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    Assert.assertFalse(xmlFilename + " has errors", (itemResult.getModelValidationErrors().size() > 0));
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) File(java.io.File) URL(java.net.URL) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult) Test(org.junit.Test)

Example 17 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project OpenOLAT by OpenOLAT.

the class QTI12To21ConverterTest method validateAssessmentItem.

private boolean validateAssessmentItem(File assessmentItemFile) {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentItemFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(assessmentItemFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    return itemResult.getModelValidationErrors().isEmpty();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) 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 18 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project OpenOLAT by OpenOLAT.

the class QTI12To21ConverterTest method validateAssessmentTest.

private boolean validateAssessmentTest(File assessmentTestFile) {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentTestFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    TestValidationResult test = assessmentObjectXmlLoader.loadResolveAndValidateTest(assessmentTestFile.toURI());
    for (Notification notification : test.getModelValidationErrors()) {
        log.error(notification.getQtiNode() + " : " + notification.getMessage());
    }
    BadResourceException e = test.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    return test.getModelValidationErrors().isEmpty();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) TestValidationResult(uk.ac.ed.ph.jqtiplus.validation.TestValidationResult) Notification(uk.ac.ed.ph.jqtiplus.notification.Notification) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)

Example 19 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project openolat by klemens.

the class Onyx38ToQtiWorksAssessementItemsTest method fixItem.

@Test
public void fixItem() throws IOException, XMLStreamException, SAXException, ParserConfigurationException, URISyntaxException {
    URL xmlUrl = Onyx38ToQtiWorksAssessementItemsTest.class.getResource("resources/onyx/" + xmlFilename);
    File xmlFile = new File(xmlUrl.toURI());
    File tmpDir = new File(WebappHelper.getTmpDir(), "onyx" + UUID.randomUUID());
    tmpDir.mkdirs();
    File outputFile = new File(tmpDir, "text.xml");
    try (InputStream in = Files.newInputStream(xmlFile.toPath());
        Writer out = Files.newBufferedWriter(outputFile.toPath(), Charset.forName("UTF-8"))) {
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        XMLStreamWriter xtw = xof.createXMLStreamWriter(out);
        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
        DefaultHandler2 myHandler = new Onyx38ToQtiWorksHandler(xtw);
        saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", myHandler);
        saxParser.parse(in, myHandler);
    } catch (Exception e1) {
        log.error("", e1);
        throw e1;
    }
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(outputFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(outputFile.toURI());
    Assert.assertNotNull(resolvedAssessmentItem);
    AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
    // validation is only
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(outputFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    FileUtils.deleteDirsAndFiles(tmpDir.toPath());
    Assert.assertNotNull(assessmentItem);
    Assert.assertFalse(BadRessourceHelper.hasFatalErrors(e));
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DefaultHandler2(org.xml.sax.ext.DefaultHandler2) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) InputStream(java.io.InputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) SAXParser(javax.xml.parsers.SAXParser) File(java.io.File) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Writer(java.io.Writer) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult) Test(org.junit.Test)

Example 20 with BadResourceException

use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project openolat by klemens.

the class OnyxToQtiWorksAssessementItemsTest method fixItem.

@Test
public void fixItem() throws IOException, XMLStreamException, SAXException, ParserConfigurationException, URISyntaxException {
    URL xmlUrl = OnyxToQtiWorksAssessementItemsTest.class.getResource("resources/onyx/" + xmlFilename);
    File xmlFile = new File(xmlUrl.toURI());
    File tmpDir = new File(WebappHelper.getTmpDir(), "onyx" + UUID.randomUUID());
    tmpDir.mkdirs();
    File outputFile = new File(tmpDir, "text.xml");
    try (InputStream in = Files.newInputStream(xmlFile.toPath());
        Writer out = Files.newBufferedWriter(outputFile.toPath(), Charset.forName("UTF-8"))) {
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        XMLStreamWriter xtw = xof.createXMLStreamWriter(out);
        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
        DefaultHandler2 myHandler = new OnyxToQtiWorksHandler(xtw, infos);
        saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", myHandler);
        saxParser.parse(in, myHandler);
    } catch (Exception e1) {
        log.error("", e1);
        throw e1;
    }
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(outputFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(outputFile.toURI());
    Assert.assertNotNull(resolvedAssessmentItem);
    AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
    // validation is only
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(outputFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    FileUtils.deleteDirsAndFiles(tmpDir.toPath());
    Assert.assertNotNull(assessmentItem);
    Assert.assertFalse(BadRessourceHelper.hasFatalErrors(e));
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DefaultHandler2(org.xml.sax.ext.DefaultHandler2) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) InputStream(java.io.InputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) SAXParser(javax.xml.parsers.SAXParser) File(java.io.File) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Writer(java.io.Writer) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult) Test(org.junit.Test)

Aggregations

BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)26 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)20 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)20 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)20 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)20 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)20 ItemValidationResult (uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)14 File (java.io.File)10 URISyntaxException (java.net.URISyntaxException)10 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)10 IOException (java.io.IOException)8 URL (java.net.URL)8 Test (org.junit.Test)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 TestValidationResult (uk.ac.ed.ph.jqtiplus.validation.TestValidationResult)8 InputStream (java.io.InputStream)6 Writer (java.io.Writer)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6 SAXParser (javax.xml.parsers.SAXParser)6 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)6