Search in sources :

Example 41 with QtiXmlReader

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

the class OnyxToQtiWorksAssessementTestsTest method fixAssessmentTest.

@Test
public void fixAssessmentTest() throws IOException, XMLStreamException, SAXException, ParserConfigurationException, URISyntaxException {
    URL xmlUrl = OnyxToQtiWorksAssessementTestsTest.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);
    ResolvedAssessmentTest resolvedAssessmentTest = assessmentObjectXmlLoader.loadAndResolveAssessmentTest(outputFile.toURI());
    Assert.assertNotNull(resolvedAssessmentTest);
    AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
    TestValidationResult testResult = assessmentObjectXmlLoader.loadResolveAndValidateTest(outputFile.toURI());
    BadResourceException e = testResult.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    FileUtils.deleteDirsAndFiles(tmpDir.toPath());
    Assert.assertNotNull(assessmentTest);
    Assert.assertFalse(xmlFilename + " has fatal errors", 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) TestValidationResult(uk.ac.ed.ph.jqtiplus.validation.TestValidationResult) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) 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) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) 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) 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) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) Test(org.junit.Test)

Example 42 with QtiXmlReader

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

the class SingleChoiceAssessmentItemBuilderTest method loadAssessmentItem.

private AssessmentItem loadAssessmentItem(URL itemUrl) throws URISyntaxException {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(Paths.get(itemUrl.toURI()));
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ResolvedAssessmentItem item = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(itemUrl.toURI());
    return item.getItemLookup().getRootNodeHolder().getRootNode();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) 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) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)

Example 43 with QtiXmlReader

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

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 44 with QtiXmlReader

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

the class BigAssessmentTestPackageBuilder method openBigTest_sub.

public long openBigTest_sub() {
    final File resourceFile = new File("/HotCoffee/QTI/20160219-180424/testfa908329-ab44-4821-a20d-ca634b6afb06.xml");
    final QtiXmlReader qtiXmlReader = UnitTestHelper.createUnitTestQtiXmlReader();
    final ResourceLocator fileResourceLocator = new FileResourceLocator();
    final long start = System.nanoTime();
    final AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    final ResolvedAssessmentTest resolvedTest = assessmentObjectXmlLoader.loadAndResolveAssessmentTest(resourceFile.toURI());
    Assert.assertNotNull(resolvedTest);
    final AssessmentTest test = resolvedTest.getTestLookup().extractIfSuccessful();
    Assert.assertNotNull(test);
    final long time = (System.nanoTime() - start);
    final AssessmentItemRef itemRef = resolvedTest.getAssessmentItemRefs().get(0);
    final ResolvedAssessmentItem resolvedItem = resolvedTest.getResolvedAssessmentItem(itemRef);
    Assert.assertNotNull(resolvedItem);
    final AssessmentItem item = resolvedItem.getRootNodeLookup().extractIfSuccessful();
    Assert.assertNotNull(item);
    Assert.assertEquals(1, item.getItemBody().findInteractions().size());
    return time;
}
Also used : ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator)

Example 45 with QtiXmlReader

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

the class QTI21ServiceImpl method loadAndResolveAssessmentItemForCopy.

@Override
public ResolvedAssessmentItem loadAndResolveAssessmentItemForCopy(URI assessmentObjectSystemId, File resourceDirectory) {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(jqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(resourceDirectory.toPath());
    ResourceLocator inputResourceLocator = ImsQTI21Resource.createResolvingResourceLocator(fileResourceLocator);
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, inputResourceLocator);
    return assessmentObjectXmlLoader.loadAndResolveAssessmentItem(assessmentObjectSystemId);
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) ClassPathResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ClassPathResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) 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)

Aggregations

QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)48 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)48 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)44 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)40 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)34 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)26 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)22 IOException (java.io.IOException)16 File (java.io.File)14 ItemValidationResult (uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)14 URISyntaxException (java.net.URISyntaxException)12 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)12 URL (java.net.URL)10 Test (org.junit.Test)10 URI (java.net.URI)8 TestValidationResult (uk.ac.ed.ph.jqtiplus.validation.TestValidationResult)8 FileResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator)8 InputStream (java.io.InputStream)6 Writer (java.io.Writer)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6