Search in sources :

Example 26 with ResolvedAssessmentTest

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest in project OpenOLAT by OpenOLAT.

the class QTI21StatisticResourceResult method getTreeModel.

/**
 * Return the tree model for a test learn resource.
 *
 * @return
 */
public TreeModel getTreeModel() {
    GenericTreeModel treeModel = new GenericTreeModel();
    GenericTreeNode rootTreeNode = new GenericTreeNode();
    treeModel.setRootNode(rootTreeNode);
    FileResourceManager frm = FileResourceManager.getInstance();
    File unzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
    resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
    AssessmentTest test = resolvedAssessmentTest.getTestLookup().getRootNodeHolder().getRootNode();
    rootTreeNode.setTitle(test.getTitle());
    rootTreeNode.setUserObject(test);
    rootTreeNode.setIconCssClass("o_icon o_icon-lg o_qtiassessment_icon");
    buildRecursively(test, rootTreeNode);
    return treeModel;
}
Also used : ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) FileResourceManager(org.olat.fileresource.FileResourceManager) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) File(java.io.File)

Example 27 with ResolvedAssessmentTest

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest in project OpenOLAT by OpenOLAT.

the class IQTESTCourseNode method getQTI21TimeLimitMaxInSeconds.

/**
 * If the course element override the test configuration, the value is from
 * the course element's configuration. Else, the value is from the assessment
 * test.
 *
 * @param testEntry The test repository entry
 * @return the maximum time limit in seconds or -1 if no time limit is configured
 */
public int getQTI21TimeLimitMaxInSeconds(RepositoryEntry testEntry) {
    int timeLimit = -1;
    if (ImsQTI21Resource.TYPE_NAME.equals(testEntry.getOlatResource().getResourceableTypeName())) {
        ModuleConfiguration config = getModuleConfiguration();
        boolean configRef = config.getBooleanSafe(IQEditController.CONFIG_KEY_CONFIG_REF, false);
        if (!configRef && config.getIntegerSafe(IQEditController.CONFIG_KEY_TIME_LIMIT, -1) > 0) {
            timeLimit = config.getIntegerSafe(IQEditController.CONFIG_KEY_TIME_LIMIT, -1);
        } else {
            File unzippedDirRoot = FileResourceManager.getInstance().unzipFileResource(testEntry.getOlatResource());
            ResolvedAssessmentTest resolvedAssessmentTest = CoreSpringFactory.getImpl(QTI21Service.class).loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
            AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
            if (assessmentTest.getTimeLimits() != null && assessmentTest.getTimeLimits().getMaximum() != null) {
                timeLimit = assessmentTest.getTimeLimits().getMaximum().intValue();
            }
        }
    }
    return timeLimit;
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) ModuleConfiguration(org.olat.modules.ModuleConfiguration) QTI21Service(org.olat.ims.qti21.QTI21Service) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Example 28 with ResolvedAssessmentTest

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest in project OpenOLAT by OpenOLAT.

the class IQTESTCourseNode method hasQTI21TimeLimit.

/**
 * @param testEntry The test repository entry
 * @return true if the course node or the test has a time limit set.
 */
public boolean hasQTI21TimeLimit(RepositoryEntry testEntry) {
    boolean timeLimit = false;
    if (ImsQTI21Resource.TYPE_NAME.equals(testEntry.getOlatResource().getResourceableTypeName())) {
        ModuleConfiguration config = getModuleConfiguration();
        boolean configRef = config.getBooleanSafe(IQEditController.CONFIG_KEY_CONFIG_REF, false);
        if (!configRef && config.getIntegerSafe(IQEditController.CONFIG_KEY_TIME_LIMIT, -1) > 0) {
            timeLimit = true;
        } else {
            File unzippedDirRoot = FileResourceManager.getInstance().unzipFileResource(testEntry.getOlatResource());
            ResolvedAssessmentTest resolvedAssessmentTest = CoreSpringFactory.getImpl(QTI21Service.class).loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
            AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
            if (assessmentTest.getTimeLimits() != null && assessmentTest.getTimeLimits().getMaximum() != null) {
                timeLimit = true;
            }
        }
    }
    return timeLimit;
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) ModuleConfiguration(org.olat.modules.ModuleConfiguration) QTI21Service(org.olat.ims.qti21.QTI21Service) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) File(java.io.File)

Example 29 with ResolvedAssessmentTest

use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest 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 30 with ResolvedAssessmentTest

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

Aggregations

ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)40 File (java.io.File)32 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)24 FileResourceManager (org.olat.fileresource.FileResourceManager)16 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)8 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)8 HashMap (java.util.HashMap)7 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)6 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)6 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)6 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)6 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)6 URISyntaxException (java.net.URISyntaxException)4 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)4 Identity (org.olat.core.id.Identity)4 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)4