Search in sources :

Example 21 with QPoolSPI

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);
}
Also used : ExportFormatOptions(org.olat.modules.qpool.ExportFormatOptions) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) DefaultExportFormat(org.olat.modules.qpool.model.DefaultExportFormat) Test(org.junit.Test)

Example 22 with QPoolSPI

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;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 23 with QPoolSPI

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;
}
Also used : QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 24 with QPoolSPI

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;
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) QPoolSPI(org.olat.modules.qpool.QPoolSPI) MediaResource(org.olat.core.gui.media.MediaResource)

Aggregations

QPoolSPI (org.olat.modules.qpool.QPoolSPI)24 ArrayList (java.util.ArrayList)10 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)10 QuestionItem (org.olat.modules.qpool.QuestionItem)6 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)6 HashMap (java.util.HashMap)4 List (java.util.List)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)4 StringTokenizer (java.util.StringTokenizer)2 Document (org.apache.lucene.document.Document)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 Test (org.junit.Test)2 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)2 Component (org.olat.core.gui.components.Component)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 MediaResource (org.olat.core.gui.media.MediaResource)2 Identity (org.olat.core.id.Identity)2 User (org.olat.core.id.User)2