use of org.olat.modules.qpool.QuestionItemShort in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method removeFromShare.
@Test
public void removeFromShare() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-rm-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdrm", "gdrm-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commit();
// share them
questionDao.share(item, group.getResource());
// retrieve them as a check
List<QuestionItemView> shared = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
Assert.assertEquals(1, shared.size());
// and remove the items
List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(shared.get(0));
int count = questionDao.removeFromShares(toDelete);
Assert.assertEquals(1, count);
// make sure that changes are committed
dbInstance.commit();
}
use of org.olat.modules.qpool.QuestionItemShort in project OpenOLAT by OpenOLAT.
the class QuestionPoolServiceImplTest method shouldGetExportFormatOptions.
@Test
public void shouldGetExportFormatOptions() {
String formatA = "A";
String formatB = "B";
QuestionItemImpl formatAItem = new QuestionItemImpl();
formatAItem.setFormat(formatA);
List<QuestionItemShort> items = Arrays.asList(formatAItem);
ExportFormatOptions exportFormatAR = new DefaultExportFormat(formatA, Outcome.repository, null);
ExportFormatOptions exportFormatAD = new DefaultExportFormat(formatA, Outcome.download, null);
List<ExportFormatOptions> exportFormatsA = Arrays.asList(exportFormatAD, exportFormatAR);
ExportFormatOptions exportFormatBR = new DefaultExportFormat(formatA, Outcome.repository, null);
List<ExportFormatOptions> exportFormatsB = Arrays.asList(exportFormatBR);
QPoolSPI spiA = mock(QPoolSPI.class);
when(spiA.getTestExportFormats()).thenReturn(exportFormatsA);
when(qPoolModuleMock.getQuestionPoolProvider(formatA)).thenReturn(spiA);
QPoolSPI spiB = mock(QPoolSPI.class);
when(spiB.getTestExportFormats()).thenReturn(exportFormatsB);
when(qPoolModuleMock.getQuestionPoolProvider(formatB)).thenReturn(spiB);
Set<ExportFormatOptions> exportFormatOptions = sut.getExportFormatOptions(items, Outcome.repository);
assertThat(exportFormatOptions).hasSize(1).containsExactly(exportFormatAR);
}
use of org.olat.modules.qpool.QuestionItemShort in project OpenOLAT by OpenOLAT.
the class QTI12And21PoolWordExport method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding(encoding);
} catch (Exception e) {
log.error("", e);
}
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
String label = "Items_Export";
String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
List<Long> itemKeys = new ArrayList<>();
for (QuestionItemShort item : items) {
itemKeys.add(item.getKey());
}
List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
String file = secureLabel + ".zip";
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
zout.setLevel(9);
ZipEntry test = new ZipEntry(secureLabel + ".docx");
zout.putNextEntry(test);
exportItems(fullItems, zout, false);
zout.closeEntry();
ZipEntry responses = new ZipEntry(secureLabel + "_responses.docx");
zout.putNextEntry(responses);
exportItems(fullItems, zout, true);
zout.closeEntry();
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.
the class QTI21QPoolServiceProvider method loadQuestionFullItems.
private List<QuestionItemFull> loadQuestionFullItems(List<QuestionItemShort> items) {
List<Long> itemKeys = toKeys(items);
List<QuestionItemFull> fullItems = questionItemDao.loadByIds(itemKeys);
Map<Long, QuestionItemFull> fullItemMap = new HashMap<>();
for (QuestionItemFull fullItem : fullItems) {
fullItemMap.put(fullItem.getKey(), fullItem);
}
// reorder the fullItems;
List<QuestionItemFull> reorderedFullItems = new ArrayList<>(fullItems.size());
for (QuestionItemShort item : items) {
QuestionItemFull itemFull = fullItemMap.get(item.getKey());
if (itemFull != null) {
reorderedFullItems.add(itemFull);
}
}
return reorderedFullItems;
}
use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.
the class QuestionDAOTest method removeFromShare.
@Test
public void removeFromShare() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-rm-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdrm", "gdrm-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commit();
// share them
questionDao.share(item, group.getResource());
// retrieve them as a check
List<QuestionItemView> shared = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
Assert.assertEquals(1, shared.size());
// and remove the items
List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(shared.get(0));
int count = questionDao.removeFromShares(toDelete);
Assert.assertEquals(1, count);
// make sure that changes are committed
dbInstance.commit();
}
Aggregations