Search in sources :

Example 16 with QuestionItemShort

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();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 17 with QuestionItemShort

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);
}
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 18 with QuestionItemShort

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);
    }
}
Also used : QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) ZipOutputStream(java.util.zip.ZipOutputStream) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 19 with QuestionItemShort

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

Example 20 with QuestionItemShort

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();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Aggregations

QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)76 ArrayList (java.util.ArrayList)52 QuestionItem (org.olat.modules.qpool.QuestionItem)28 Identity (org.olat.core.id.Identity)14 List (java.util.List)12 BusinessGroup (org.olat.group.BusinessGroup)12 Test (org.junit.Test)10 QPoolSPI (org.olat.modules.qpool.QPoolSPI)10 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 QItemType (org.olat.modules.qpool.model.QItemType)8 HashMap (java.util.HashMap)6 ExportFormatOptions (org.olat.modules.qpool.ExportFormatOptions)6 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)6 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6 QuestionItemView (org.olat.modules.qpool.QuestionItemView)6 QItemList (org.olat.modules.qpool.model.QItemList)6 QItemEdited (org.olat.modules.qpool.ui.events.QItemEdited)6 QPoolEvent (org.olat.modules.qpool.ui.events.QPoolEvent)6 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)5 Path (javax.ws.rs.Path)4