use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest in project OpenOLAT by OpenOLAT.
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));
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest in project OpenOLAT by OpenOLAT.
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;
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method doNewSection.
private void doNewSection(UserRequest ureq, TreeNode selectedNode) {
AbstractPart parentPart;
TreeNode sectionNode = getNearestSection(selectedNode);
if (sectionNode != null) {
AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
parentPart = section.getParent();
} else if (selectedNode.getUserObject() instanceof TestPart) {
parentPart = (TestPart) selectedNode.getUserObject();
} else {
TreeNode rootNode = menuTree.getTreeModel().getRootNode();
AssessmentTest assessmentTest = (AssessmentTest) rootNode.getUserObject();
List<TestPart> parts = assessmentTest.getTestParts();
if (parts != null && parts.size() > 0) {
parentPart = parts.get(0);
} else {
showWarning("error.cannot.create.section");
return;
}
}
AssessmentSection newSection;
if (parentPart instanceof TestPart) {
newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (TestPart) parentPart);
} else if (parentPart instanceof AssessmentSection) {
newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (AssessmentSection) parentPart);
} else {
showWarning("error.cannot.create.section");
return;
}
// save the test
URI testUri = resolvedAssessmentTest.getTestLookup().getSystemId();
File testFile = new File(testUri);
qtiService.updateAssesmentObject(testFile, resolvedAssessmentTest);
assessmentChanged(ureq);
// reload the test
updateTreeModel(false);
TreeNode newSectionNode = menuTree.getTreeModel().getNodeById(newSection.getIdentifier().toString());
menuTree.setSelectedNode(newSectionNode);
menuTree.open(newSectionNode);
partEditorFactory(ureq, newSectionNode);
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest in project OpenOLAT by OpenOLAT.
the class QTI21AssessmentRunController method getAssessmentTestMaxTimeLimit.
/**
* @return The maximum time limit in seconds.
*/
private Long getAssessmentTestMaxTimeLimit() {
if (overrideOptions != null && overrideOptions.getAssessmentTestMaxTimeLimit() != null) {
Long timeLimits = overrideOptions.getAssessmentTestMaxTimeLimit();
return timeLimits.longValue() > 0 ? timeLimits.longValue() : null;
}
FileResourceManager frm = FileResourceManager.getInstance();
File fUnzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(fUnzippedDirRoot, false, false);
AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
if (assessmentTest != null && assessmentTest.getTimeLimits() != null && assessmentTest.getTimeLimits().getMaximum() != null) {
return assessmentTest.getTimeLimits().getMaximum().longValue();
}
return null;
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest in project OpenOLAT by OpenOLAT.
the class QTI21QPoolServiceProvider method importRepositoryEntry.
public List<QuestionItem> importRepositoryEntry(Identity owner, RepositoryEntry repositoryEntry, Locale defaultLocale) {
FileResourceManager frm = FileResourceManager.getInstance();
File unzippedDirRoot = frm.unzipFileResource(repositoryEntry.getOlatResource());
ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, true);
ManifestBuilder clonedManifestBuilder = ManifestBuilder.read(new File(unzippedDirRoot, "imsmanifest.xml"));
List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getAssessmentItemRefs();
List<QuestionItem> importedItems = new ArrayList<>(itemRefs.size());
for (AssessmentItemRef itemRef : itemRefs) {
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
RootNodeLookup<AssessmentItem> rootNode = resolvedAssessmentItem.getItemLookup();
URI itemUri = rootNode.getSystemId();
File itemFile = new File(itemUri);
String relativePathToManifest = unzippedDirRoot.toPath().relativize(itemFile.toPath()).toString();
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
ResourceType resource = clonedManifestBuilder.getResourceTypeByHref(relativePathToManifest);
ManifestMetadataBuilder metadata = clonedManifestBuilder.getMetadataBuilder(resource, true);
QuestionItem qitem = importAssessmentItemRef(owner, assessmentItem, itemFile, metadata, defaultLocale);
importedItems.add(qitem);
}
return importedItems;
}
Aggregations