use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project openolat by klemens.
the class QTIEditorPackageImpl method getQTIDocument.
/**
* @return Reutrns the QTIDocument structure
*/
public QTIDocument getQTIDocument() {
if (qtiDocument == null) {
if (hasSerializedQTIDocument()) {
qtiDocument = loadSerializedQTIDocument();
resumed = true;
} else {
unzipPackage();
Document doc = loadQTIDocument();
if (doc != null) {
ParserManager parser = new ParserManager();
qtiDocument = (QTIDocument) parser.parse(doc);
// grab assessment type
Metadata meta = qtiDocument.getAssessment().getMetadata();
String assessType = meta.getField(AssessmentInstance.QMD_LABEL_TYPE);
if (assessType != null) {
qtiDocument.setSurvey(assessType.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY));
}
resumed = false;
} else {
qtiDocument = null;
}
}
}
return qtiDocument;
}
use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project openolat by klemens.
the class QTIDocumentParser method parse.
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("questestinterop");
QTIDocument qtiDocument = new QTIDocument();
Object tmp = null;
Element qticomment = element.element("qticomment");
qtiDocument.setQticomment((QTIObject) parserManager.parse(qticomment));
Element objectbank = element.element("objectbank");
tmp = parserManager.parse(objectbank);
if (tmp != null) {
qtiDocument.setObjectbank((QTIObject) tmp);
}
Element assesment = element.element("assessment");
tmp = parserManager.parse(assesment);
if (tmp != null) {
qtiDocument.setAssessment((Assessment) tmp);
}
return qtiDocument;
}
use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project OpenOLAT by OpenOLAT.
the class QTI12To21ConverterTest method convert.
@Test
public void convert() throws URISyntaxException, IOException, XmlResourceNotFoundException, ImsManifestException {
QTIDocument doc = loadDocument("qti12_4questiontypes.xml");
File exportDir = new File(WebappHelper.getTmpDir(), "qti12to21" + UUID.randomUUID());
exportDir.mkdirs();
QTI12To21Converter converter = new QTI12To21Converter(exportDir, Locale.ENGLISH);
converter.convert(null, doc, null);
int validAssessmentItems = 0;
boolean validAssessmentTest = false;
QtiContentPackageSummary readableManifest = null;
File[] generatedFiles = exportDir.listFiles();
for (File generatedFile : generatedFiles) {
String filename = generatedFile.getName();
if (filename.equals("imsmanifest.xml")) {
readableManifest = new QtiContentPackageExtractor(exportDir).parse();
} else if (filename.startsWith("test")) {
validAssessmentTest = validateAssessmentTest(generatedFile);
} else if (filename.endsWith(".xml")) {
boolean validItem = validateAssessmentItem(generatedFile);
if (validItem) {
validAssessmentItems++;
}
}
}
// delete tmp
FileUtils.deleteDirsAndFiles(exportDir.toPath());
Assert.assertTrue(validAssessmentTest);
Assert.assertEquals(4, validAssessmentItems);
Assert.assertEquals(1, readableManifest.getTestResources().size());
Assert.assertEquals(4, readableManifest.getItemResources().size());
}
use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project OpenOLAT by OpenOLAT.
the class QTI12To21ConverterTest method loadDocument.
private QTIDocument loadDocument(String filename) {
try (InputStream in = QTI12To21ConverterTest.class.getResourceAsStream(filename)) {
XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
Document doc = xmlParser.parse(in, true);
ParserManager parser = new ParserManager();
return (QTIDocument) parser.parse(doc);
} catch (Exception e) {
log.error("Exception when parsing input QTI input stream for " + filename, e);
return null;
}
}
use of org.olat.ims.qti.editor.beecom.objects.QTIDocument in project OpenOLAT by OpenOLAT.
the class IQConfigurationController method needManualCorrectionQTI12.
private boolean needManualCorrectionQTI12(RepositoryEntry re) {
boolean needManualCorrection = false;
QTIDocument doc = TestFileResource.getQTIDocument(re.getOlatResource());
if (doc != null && doc.getAssessment() != null) {
Assessment ass = doc.getAssessment();
// Sections with their Items
List<Section> sections = ass.getSections();
for (Section section : sections) {
List<Item> items = section.getItems();
for (Item item : items) {
String ident = item.getIdent();
if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
needManualCorrection = true;
break;
}
}
}
}
return needManualCorrection;
}
Aggregations