use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project openolat by klemens.
the class QTI21ServiceImpl method getAssessmentResult.
@Override
public AssessmentResult getAssessmentResult(AssessmentTestSession candidateSession) {
File assessmentResultFile = getAssessmentResultFile(candidateSession);
ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentResultFile.getParentFile().toPath());
ResourceLocator inputResourceLocator = ImsQTI21Resource.createResolvingResourceLocator(fileResourceLocator);
URI assessmentResultUri = assessmentResultFile.toURI();
QtiObjectReader qtiObjectReader = qtiXmlReader().createQtiObjectReader(inputResourceLocator, false, false);
try {
QtiObjectReadResult<AssessmentResult> result = qtiObjectReader.lookupRootNode(assessmentResultUri, AssessmentResult.class);
return result.getRootNode();
} catch (XmlResourceNotFoundException | QtiXmlInterpretationException | ClassCastException e) {
log.error("", e);
return null;
}
}
use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project openolat by klemens.
the class CopyAndConvertVisitor method validate.
private boolean validate(Path inputFile, InputType type, boolean verbose) {
try {
QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
ResourceLocator fileResourceLocator = new PathResourceLocator(inputFile.getParent());
AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
RootNode rootNode = null;
BadResourceException e = null;
URI uri = new URI("zip", inputFile.getFileName().toString(), null);
if (type == InputType.assessmentItem) {
ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(uri);
e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(uri);
rootNode = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
} else if (type == InputType.assessmentTest) {
TestValidationResult testResult = assessmentObjectXmlLoader.loadResolveAndValidateTest(uri);
e = testResult.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
ResolvedAssessmentTest resolvedAssessmentTest = assessmentObjectXmlLoader.loadAndResolveAssessmentTest(uri);
rootNode = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
}
if (e != null && verbose) {
StringBuilder err = new StringBuilder();
BadRessourceHelper.extractMessage(e, err);
log.warn(err.toString());
}
return (rootNode != null) && (e == null || (e instanceof QtiXmlInterpretationException && ((QtiXmlInterpretationException) e).getXmlParseResult().getFatalErrors().isEmpty()));
} catch (URISyntaxException e) {
log.error("", e);
return false;
}
}
use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project openolat by klemens.
the class AssessmentTestDisplayController method getTestProcessingMap.
private TestProcessingMap getTestProcessingMap() {
boolean assessmentPackageIsValid = true;
BadResourceException ex = resolvedAssessmentTest.getTestLookup().getBadResourceException();
if (ex instanceof QtiXmlInterpretationException) {
try {
// try to log some informations
QtiXmlInterpretationException exml = (QtiXmlInterpretationException) ex;
logError(exml.getInterpretationFailureReason().toString(), null);
for (QtiModelBuildingError err : exml.getQtiModelBuildingErrors()) {
logError(err.toString(), null);
}
} catch (Exception e) {
logError("", e);
}
}
TestProcessingInitializer initializer = new TestProcessingInitializer(resolvedAssessmentTest, assessmentPackageIsValid);
TestProcessingMap result = initializer.initialize();
return result;
}
Aggregations