use of org.olat.ims.qti21.model.xml.ManifestBuilder in project openolat by klemens.
the class QTI21QPoolServiceProvider method importExcelItem.
public QuestionItemImpl importExcelItem(Identity owner, AssessmentItemAndMetadata itemAndMetadata, Locale defaultLocale) {
QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
String editor = itemAndMetadata.getEditor();
String editorVersion = itemAndMetadata.getEditorVersion();
AssessmentItemBuilder itemBuilder = itemAndMetadata.getItemBuilder();
itemBuilder.build();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
QuestionItemImpl qitem = processor.processItem(assessmentItem, null, null, editor, editorVersion, itemAndMetadata);
String originalItemFilename = qitem.getRootFilename();
File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
File itemFile = new File(itemStorage, originalItemFilename);
qtiService.persistAssessmentObject(itemFile, assessmentItem);
// create manifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
ManifestMetadataBuilder metadataBuilder = manifest.getMetadataBuilder(resource, true);
itemAndMetadata.toBuilder(metadataBuilder, defaultLocale);
manifest.write(new File(itemStorage, "imsmanifest.xml"));
return qitem;
}
use of org.olat.ims.qti21.model.xml.ManifestBuilder in project openolat by klemens.
the class QTI21AssessmentTestHandler method createMinimalAssessmentTest.
public void createMinimalAssessmentTest(String displayName, File directory, Locale locale) {
ManifestBuilder manifestBuilder = ManifestBuilder.createAssessmentTestBuilder();
Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
// single choice
File itemFile = new File(directory, IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix()) + ".xml");
AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice(translator.translate("new.sc"), translator.translate("new.answer"));
QtiSerializer qtiSerializer = qtiService.qtiSerializer();
manifestBuilder.appendAssessmentItem(itemFile.getName());
// test
File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest(displayName, translator.translate("new.section"));
manifestBuilder.appendAssessmentTest(testFile.getName());
// item -> test
try {
AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
} catch (URISyntaxException e) {
log.error("", e);
}
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(assessmentItem, out);
} catch (Exception e) {
log.error("", e);
}
try (FileOutputStream out = new FileOutputStream(testFile)) {
qtiSerializer.serializeJqtiObject(assessmentTest, out);
} catch (Exception e) {
log.error("", e);
}
manifestBuilder.write(new File(directory, "imsmanifest.xml"));
}
use of org.olat.ims.qti21.model.xml.ManifestBuilder in project OpenOLAT by OpenOLAT.
the class QTI21IdentityListCourseNodeToolsController method doOpenCorrection.
private void doOpenCorrection(UserRequest ureq) {
File unzippedDirRoot = FileResourceManager.getInstance().unzipFileResource(testEntry.getOlatResource());
ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
ManifestBuilder manifestBuilder = ManifestBuilder.read(new File(unzippedDirRoot, "imsmanifest.xml"));
TestSessionState testSessionState = qtiService.loadTestSessionState(lastSession);
Map<Identity, AssessmentTestSession> lastSessionMap = new HashMap<>();
lastSessionMap.put(assessedIdentity, lastSession);
CorrectionOverviewModel model = new CorrectionOverviewModel(courseEntry, testCourseNode.getIdent(), testEntry, resolvedAssessmentTest, manifestBuilder, lastSessionMap, Collections.singletonMap(assessedIdentity, testSessionState));
correctionCtrl = new CorrectionIdentityAssessmentItemListController(ureq, getWindowControl(), stackPanel, model, lastSession, assessedIdentity);
listenTo(correctionCtrl);
stackPanel.pushController(translate("tool.correction"), correctionCtrl);
}
use of org.olat.ims.qti21.model.xml.ManifestBuilder in project OpenOLAT by OpenOLAT.
the class QTI21AssessmentTestHandler method createMinimalAssessmentTest.
public void createMinimalAssessmentTest(String displayName, File directory, Locale locale) {
ManifestBuilder manifestBuilder = ManifestBuilder.createAssessmentTestBuilder();
Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
// single choice
File itemFile = new File(directory, IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix()) + ".xml");
AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice(translator.translate("new.sc"), translator.translate("new.answer"));
QtiSerializer qtiSerializer = qtiService.qtiSerializer();
manifestBuilder.appendAssessmentItem(itemFile.getName());
// test
File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest(displayName, translator.translate("new.section"));
manifestBuilder.appendAssessmentTest(testFile.getName());
// item -> test
try {
AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
} catch (URISyntaxException e) {
log.error("", e);
}
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(assessmentItem, out);
} catch (Exception e) {
log.error("", e);
}
try (FileOutputStream out = new FileOutputStream(testFile)) {
qtiSerializer.serializeJqtiObject(assessmentTest, out);
} catch (Exception e) {
log.error("", e);
}
manifestBuilder.write(new File(directory, "imsmanifest.xml"));
}
use of org.olat.ims.qti21.model.xml.ManifestBuilder in project OpenOLAT by OpenOLAT.
the class QTI21ExportProcessor method process.
public void process(QuestionItemFull qitem, ZipOutputStream zout) {
String dir = qitem.getDirectory();
File rootDirectory = qpoolFileStorage.getDirectory(dir);
String rootDir = "qitem_" + qitem.getKey();
File imsmanifest = new File(rootDirectory, "imsmanifest.xml");
ManifestBuilder manifestBuilder;
if (imsmanifest.exists()) {
manifestBuilder = ManifestBuilder.read(imsmanifest);
} else {
manifestBuilder = new ManifestBuilder();
}
File resourceFile = new File(rootDirectory, qitem.getRootFilename());
URI assessmentItemUri = resourceFile.toURI();
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(assessmentItemUri, rootDirectory);
enrichWithMetadata(qitem, resolvedAssessmentItem, manifestBuilder);
try {
zout.putNextEntry(new ZipEntry(rootDir + "/imsmanifest.xml"));
manifestBuilder.write(new ShieldOutputStream(zout));
zout.closeEntry();
} catch (Exception e) {
log.error("", e);
}
try {
Files.walkFileTree(rootDirectory.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String filename = file.getFileName().toString();
if (!"imsmanifest.xml".equals(filename) && !filename.startsWith(".")) {
String relPath = rootDirectory.toPath().relativize(file).toString();
ZipUtil.addFileToZip(rootDir + "/" + relPath, file, zout);
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
log.error("", e);
}
}
Aggregations