use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException 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.provision.BadResourceException in project OpenOLAT by OpenOLAT.
the class QTI21AssessmentTestHandlerTest 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();
StringBuilder err = new StringBuilder();
BadRessourceHelper.extractMessage(e, err);
log.error(err.toString());
return test.getModelValidationErrors().isEmpty();
}
use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project OpenOLAT by OpenOLAT.
the class QTI21AssessmentTestHandlerTest 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();
}
use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project OpenOLAT by OpenOLAT.
the class QTI21StatisticResourceResult method buildRecursively.
private TreeNode buildRecursively(AssessmentItemRef itemRef, TreeNode parentNode) {
GenericTreeNode itemNode = new GenericTreeNode();
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
BadResourceException ex = resolvedAssessmentItem.getItemLookup().getBadResourceException();
if (ex == null) {
AssessmentItem assessmentItem = resolvedAssessmentItem.getItemLookup().getRootNodeHolder().getRootNode();
itemNode.setTitle(assessmentItem.getTitle());
QTI21QuestionType type = QTI21QuestionType.getTypeRelax(assessmentItem);
if (type != null) {
itemNode.setIconCssClass("o_icon ".concat(type.getCssClass()));
} else {
itemNode.setIconCssClass("o_icon o_mi_qtiunkown");
}
itemNode.setUserObject(itemRef);
parentNode.addChild(itemNode);
}
return itemNode;
}
use of uk.ac.ed.ph.jqtiplus.provision.BadResourceException in project OpenOLAT by OpenOLAT.
the class AssessmentTestEditorAndComposerTreeModel method buildRecursively.
private TreeNode buildRecursively(AssessmentItemRef itemRef, TreeNode parentNode) {
GenericTreeNode itemNode = new GenericTreeNode(itemRef.getIdentifier().toString());
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
if (resolvedAssessmentItem == null || resolvedAssessmentItem.getItemLookup() == null || resolvedAssessmentItem.getItemLookup().getRootNodeHolder() == null) {
itemNode.setTitle("ERROR - Not found");
itemNode.setIconCssClass("o_icon o_icon_error");
itemNode.setUserObject(itemRef);
parentNode.addChild(itemNode);
} else {
BadResourceException ex = resolvedAssessmentItem.getItemLookup().getBadResourceException();
if (ex != null) {
itemNode.setTitle("ERROR");
itemNode.setIconCssClass("o_icon o_icon_error");
itemNode.setUserObject(itemRef);
parentNode.addChild(itemNode);
} else {
AssessmentItem assessmentItem = resolvedAssessmentItem.getItemLookup().getRootNodeHolder().getRootNode();
itemNode.setTitle(assessmentItem.getTitle());
QTI21QuestionType type = QTI21QuestionType.getType(assessmentItem);
if (type != null) {
itemNode.setIconCssClass("o_icon ".concat(type.getCssClass()));
} else {
itemNode.setIconCssClass("o_icon o_mi_qtiunkown");
}
itemNode.setUserObject(itemRef);
parentNode.addChild(itemNode);
}
}
return itemNode;
}
Aggregations