use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator 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.xmlutils.locators.ResourceLocator 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.xmlutils.locators.ResourceLocator in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest 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();
}
use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest method serializeAndReload.
/**
* The method serialize as xml the assessmentItem, load it, validate it and return the itemResult.
*
* @param assessmentItem
* @return
* @throws IOException
*/
private ItemValidationResult serializeAndReload(AssessmentItem assessmentItem) throws IOException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
File tmpDir = new File(WebappHelper.getTmpDir(), "itembuilder" + UUID.randomUUID());
tmpDir.mkdirs();
File outputFile = new File(tmpDir, "sc_item.xml");
try (FileOutputStream out = new FileOutputStream(outputFile)) {
qtiSerializer.serializeJqtiObject(assessmentItem, out);
} catch (Exception e) {
log.error("", e);
}
QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
ResourceLocator fileResourceLocator = new PathResourceLocator(outputFile.toPath());
AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
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.assertFalse("Has errors", (itemResult.getModelValidationErrors().size() > 0));
return itemResult;
}
use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator in project OpenOLAT by OpenOLAT.
the class AssessmentItemPackageTest method loadAssessmentItem.
@Test
public void loadAssessmentItem() throws URISyntaxException {
QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL testUrl = AssessmentItemPackageTest.class.getResource("assessment-item-single-choice.xml");
ResourceLocator fileResourceLocator = new PathResourceLocator(Paths.get(testUrl.toURI()));
AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
ResolvedAssessmentItem item = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(testUrl.toURI());
Assert.assertNotNull(item);
AssessmentItem assessmentItem = item.getItemLookup().getRootNodeHolder().getRootNode();
Assert.assertNotNull(assessmentItem);
qtiSerializer.serializeJqtiObject(assessmentItem, System.out);
}
Aggregations