use of org.olat.modules.qpool.QPoolSPI in project openolat by klemens.
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.QPoolSPI in project openolat by klemens.
the class QuestionPoolServiceImpl method copyItems.
@Override
public List<QuestionItem> copyItems(Identity owner, List<QuestionItemShort> itemsToCopy) {
List<QuestionItem> copies = new ArrayList<>();
for (QuestionItemShort itemToCopy : itemsToCopy) {
QuestionItemImpl original = questionItemDao.loadById(itemToCopy.getKey());
QuestionItemImpl copy = questionItemDao.copy(original);
questionItemDao.persist(owner, copy);
QPoolSPI provider = qpoolModule.getQuestionPoolProvider(copy.getFormat());
if (provider != null) {
provider.copyItem(original, copy);
}
licenseService.copy(original, copy);
copies.add(copy);
}
dbInstance.commit();
index(copies);
return copies;
}
use of org.olat.modules.qpool.QPoolSPI in project openolat by klemens.
the class QuestionPoolServiceImpl method importItems.
@Override
public List<QuestionItem> importItems(Identity owner, Locale defaultLocale, String filename, File file) {
List<QuestionItem> importedItem = null;
List<QPoolSPI> providers = qpoolModule.getQuestionPoolProviders();
for (QPoolSPI provider : providers) {
if (provider.isCompatible(filename, file)) {
importedItem = provider.importItems(owner, defaultLocale, filename, file);
}
}
dbInstance.commit();
index(importedItem);
return importedItem;
}
use of org.olat.modules.qpool.QPoolSPI in project openolat by klemens.
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;
}
Aggregations