use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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 OpenOLAT.
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;
}
use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project openolat by klemens.
the class BadRessourceHelper method extractMessage.
public static void extractMessage(BadResourceException e, StringBuilder out) {
if (e instanceof QtiXmlInterpretationException) {
QtiXmlInterpretationException qe = (QtiXmlInterpretationException) e;
if (qe.getQtiModelBuildingErrors() != null) {
for (QtiModelBuildingError error : qe.getQtiModelBuildingErrors()) {
String localName = error.getElementLocalName();
String msg = error.getException().getMessage();
if (error.getElementLocation() != null) {
int lineNumber = error.getElementLocation().getLineNumber();
out.append(lineNumber + " :: " + localName + " :: " + msg + "\n");
} else {
out.append(localName + " :: " + msg + "\n");
}
}
}
if (qe.getInterpretationFailureReason() != null) {
InterpretationFailureReason reason = qe.getInterpretationFailureReason();
out.append("Failure: " + reason + "\n");
}
if (qe.getXmlParseResult() != null) {
XmlParseResult result = qe.getXmlParseResult();
if (result.getWarnings() != null) {
for (SAXParseException saxex : result.getWarnings()) {
int lineNumber = saxex.getLineNumber();
int columnNumber = saxex.getColumnNumber();
String msg = saxex.getMessage();
out.append("Warnings: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
}
}
if (result.getErrors() != null) {
for (SAXParseException saxex : result.getErrors()) {
int lineNumber = saxex.getLineNumber();
int columnNumber = saxex.getColumnNumber();
String msg = saxex.getMessage();
out.append("Error: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
}
}
if (result.getFatalErrors() != null) {
for (SAXParseException saxex : result.getFatalErrors()) {
int lineNumber = saxex.getLineNumber();
int columnNumber = saxex.getColumnNumber();
String msg = saxex.getMessage();
out.append("Fatal: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
}
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException in project OpenOLAT by OpenOLAT.
the class BadRessourceHelper method extractMessage.
public static void extractMessage(BadResourceException e, StringBuilder out) {
if (e instanceof QtiXmlInterpretationException) {
QtiXmlInterpretationException qe = (QtiXmlInterpretationException) e;
if (qe.getQtiModelBuildingErrors() != null) {
for (QtiModelBuildingError error : qe.getQtiModelBuildingErrors()) {
String localName = error.getElementLocalName();
String msg = error.getException().getMessage();
if (error.getElementLocation() != null) {
int lineNumber = error.getElementLocation().getLineNumber();
out.append(lineNumber + " :: " + localName + " :: " + msg + "\n");
} else {
out.append(localName + " :: " + msg + "\n");
}
}
}
if (qe.getInterpretationFailureReason() != null) {
InterpretationFailureReason reason = qe.getInterpretationFailureReason();
out.append("Failure: " + reason + "\n");
}
if (qe.getXmlParseResult() != null) {
XmlParseResult result = qe.getXmlParseResult();
if (result.getWarnings() != null) {
for (SAXParseException saxex : result.getWarnings()) {
int lineNumber = saxex.getLineNumber();
int columnNumber = saxex.getColumnNumber();
String msg = saxex.getMessage();
out.append("Warnings: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
}
}
if (result.getErrors() != null) {
for (SAXParseException saxex : result.getErrors()) {
int lineNumber = saxex.getLineNumber();
int columnNumber = saxex.getColumnNumber();
String msg = saxex.getMessage();
out.append("Error: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
}
}
if (result.getFatalErrors() != null) {
for (SAXParseException saxex : result.getFatalErrors()) {
int lineNumber = saxex.getLineNumber();
int columnNumber = saxex.getColumnNumber();
String msg = saxex.getMessage();
out.append("Fatal: " + lineNumber + ":" + columnNumber + " :: " + msg + "\n");
}
}
}
}
}
Aggregations