use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
the class AssessmentTestComposerController method doInsert.
private void doInsert(UserRequest ureq, List<QuestionItemView> items) {
TreeNode selectedNode = menuTree.getSelectedNode();
TreeNode sectionNode = getNearestSection(selectedNode);
boolean allOk = true;
String firstItemId = null;
Map<AssessmentItemRef, AssessmentItem> flyingObjects = new HashMap<>();
try {
AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
for (QuestionItemView item : items) {
QuestionItemFull qItem = qti21QPoolServiceProvider.getFullQuestionItem(item);
AssessmentItem assessmentItem = qti21QPoolServiceProvider.exportToQTIEditor(qItem, getLocale(), unzippedDirRoot);
if (assessmentItem != null) {
AssessmentItemRef itemRef = doInsert(section, assessmentItem);
if (firstItemId == null) {
firstItemId = itemRef.getIdentifier().toString();
}
flyingObjects.put(itemRef, assessmentItem);
ManifestMetadataBuilder metadata = manifestBuilder.getResourceBuilderByHref(itemRef.getHref().toString());
metadata.appendMetadataFrom(qItem, assessmentItem, getLocale());
metadata.setOpenOLATMetadataCopiedAt(new Date());
} else {
allOk &= false;
}
}
} catch (IOException | URISyntaxException e) {
showError("error.import.question");
logError("", e);
}
if (!allOk) {
showError("error.import.question");
}
if (firstItemId != null) {
// persist metadata
doSaveAssessmentTest(ureq, flyingObjects);
doSaveManifest();
updateTreeModel(false);
TreeNode newItemNode = menuTree.getTreeModel().getNodeById(firstItemId);
menuTree.setSelectedNode(newItemNode);
menuTree.open(newItemNode);
partEditorFactory(ureq, newItemNode);
}
}
use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
the class QTIQPoolServiceProvider method exportToQTIEditor.
/**
* Export to QTI editor an item from the pool. The ident of the item
* is always regenerated as an UUID.
* @param qitem
* @param editorContainer
* @return
*/
public Item exportToQTIEditor(QuestionItemShort qitem, VFSContainer editorContainer) {
QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
QuestionItemFull fullItem = questionItemDao.loadById(qitem.getKey());
Element itemEl = processor.exportToQTIEditor(fullItem, editorContainer);
Item exportedItem = (Item) new ParserManager().parse(itemEl);
exportedItem.setIdent(QTIEditHelper.generateNewIdent(exportedItem.getIdent()));
return exportedItem;
}
use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
the class QTIExportProcessor method assembleTest.
/**
* <li>List all items
* <li>Rewrite path
* <li>Assemble qti.xml
* <li>Write files at new path
* @param fullItems
* @param zout
*/
public void assembleTest(List<QuestionItemFull> fullItems, ZipOutputStream zout) {
ItemsAndMaterials itemAndMaterials = new ItemsAndMaterials();
for (QuestionItemFull fullItem : fullItems) {
collectMaterials(fullItem, itemAndMaterials);
}
try {
byte[] buffer = new byte[FileUtils.BSIZE];
// write qti.xml
Element sectionEl = createSectionBasedAssessment("Assessment");
for (Element itemEl : itemAndMaterials.getItemEls()) {
// generate new ident per item
String ident = getAttributeValue(itemEl, "ident");
String exportIdent = QTIEditHelper.generateNewIdent(ident);
itemEl.addAttribute("ident", exportIdent);
sectionEl.add(itemEl);
}
zout.putNextEntry(new ZipEntry("qti.xml"));
XMLWriter xw = new XMLWriter(zout, new OutputFormat(" ", true));
xw.write(sectionEl.getDocument());
zout.closeEntry();
// write materials
for (ItemMaterial material : itemAndMaterials.getMaterials()) {
String exportPath = material.getExportUri();
zout.putNextEntry(new ZipEntry(exportPath));
InputStream in = material.getLeaf().getInputStream();
int c;
while ((c = in.read(buffer, 0, buffer.length)) != -1) {
zout.write(buffer, 0, c);
}
IOUtils.closeQuietly(in);
zout.closeEntry();
}
} catch (IOException e) {
log.error("", e);
}
}
use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
the class QTIQPoolServiceProvider method assembleTest.
public void assembleTest(List<QuestionItemShort> items, ZipOutputStream zout) {
List<Long> itemKeys = new ArrayList<>();
for (QuestionItemShort item : items) {
itemKeys.add(item.getKey());
}
List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
QTIExportProcessor processor = new QTIExportProcessor(qpoolFileStorage);
processor.assembleTest(fullItems, zout);
}
use of org.olat.modules.qpool.QuestionItemFull in project openolat by klemens.
the class ExportQItemsZipResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding(encoding);
} catch (Exception e) {
log.error("", e);
}
String label = "ExportItems";
String file = StringHelper.transformDisplayNameToFileSystemName(label) + ".zip";
String encodedFileName = StringHelper.urlEncodeUTF8(file);
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName);
hres.setHeader("Content-Description", encodedFileName);
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
zout.setLevel(9);
Set<String> names = new HashSet<>();
QPoolService qpoolService = CoreSpringFactory.getImpl(QPoolService.class);
for (QuestionItemFull item : items) {
qpoolService.exportItem(item, zout, locale, names);
}
} catch (IOException e) {
log.error("", e);
}
}
Aggregations