use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method getItems_all.
@Test
public void getItems_all() {
// create an author with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-all-" + UUID.randomUUID().toString());
QuestionItem item = questionDao.createAndPersist(id, "NGC all", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, fibType);
dbInstance.commitAndCloseSession();
// retrieve all items
List<QuestionItemFull> items = questionDao.getAllItems(0, -1);
Assert.assertNotNull(items);
Assert.assertTrue(items.size() >= 1);
Assert.assertTrue(items.contains(item));
}
use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.
the class QuestionPoolServiceImpl method export.
@Override
public MediaResource export(List<QuestionItemShort> items, ExportFormatOptions format, Locale locale) {
MediaResource mr = null;
if (DefaultExportFormat.ZIP_EXPORT_FORMAT.equals(format)) {
List<Long> keys = toKeys(items);
List<QuestionItemFull> fullItems = questionItemDao.loadByIds(keys);
mr = new ExportQItemsZipResource("UTF-8", locale, fullItems);
// make a zip with all items
} else {
QPoolSPI selectedSp = null;
List<QPoolSPI> sps = qpoolModule.getQuestionPoolProviders();
for (QPoolSPI sp : sps) {
if (sp.getTestExportFormats().contains(format)) {
selectedSp = sp;
break;
}
}
if (selectedSp != null) {
mr = selectedSp.exportTest(items, format, locale);
}
}
return mr;
}
use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.
the class QuestionPoolServiceImpl method exportItem.
@Override
public void exportItem(QuestionItemShort item, ZipOutputStream zout, Locale locale, Set<String> names) {
QPoolSPI provider = qpoolModule.getQuestionPoolProvider(item.getFormat());
if (provider == null) {
log.error("Not found provider for this format: " + item.getFormat());
} else {
QuestionItemFull fullItem;
if (item instanceof QuestionItemFull) {
fullItem = (QuestionItemFull) item;
} else {
fullItem = questionItemDao.loadById(item.getKey());
}
provider.exportItem(fullItem, zout, locale, names);
}
}
use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.
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);
}
}
use of org.olat.modules.qpool.QuestionItemFull in project OpenOLAT by OpenOLAT.
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);
}
}
Aggregations