Search in sources :

Example 21 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.

the class PoolDAOTest method removeItemFromPools.

@Test
public void removeItemFromPools() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
    // create a pool with an item
    String poolName = "NGC-" + UUID.randomUUID().toString();
    Pool pool = poolDao.createPool(null, poolName, true);
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QuestionItem item = questionItemDao.createAndPersist(id, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    poolDao.addItemToPool(item, Collections.singletonList(pool), false);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
    params.setPoolKey(pool.getKey());
    // check the pool and remove the items
    List<QuestionItemView> items = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
    Assert.assertEquals(1, items.size());
    List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(items.get(0));
    int count = poolDao.removeFromPools(toDelete);
    Assert.assertEquals(1, count);
    dbInstance.commitAndCloseSession();
    // check if the pool is empty
    List<QuestionItemView> emptyItems = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
    Assert.assertTrue(emptyItems.isEmpty());
}
Also used : QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 22 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.

the class QuestionPoolServiceTest method deleteItems.

@Test
public void deleteItems() {
    // 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 item1 = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    dbInstance.commit();
    // share them
    questionDao.share(item1, group.getResource());
    dbInstance.commitAndCloseSession();
    // delete the items
    List<QuestionItemShort> toDelete = new ArrayList<>();
    toDelete.add(item1);
    toDelete.add(item2);
    qpoolService.deleteItems(toDelete);
    // make sure that changes are committed
    dbInstance.commit();
    // check if they exists
    QuestionItem deletedItem1 = questionDao.loadById(item1.getKey());
    Assert.assertNull(deletedItem1);
    QuestionItem deletedItem2 = questionDao.loadById(item2.getKey());
    Assert.assertNull(deletedItem2);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 23 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.

the class QuestionListController method doConfirmConversion.

private void doConfirmConversion(UserRequest ureq, List<QuestionItemShort> items) {
    Map<String, List<QuestionItemShort>> formatToItems = new HashMap<>();
    List<QPoolSPI> spies = qpoolModule.getQuestionPoolProviders();
    for (QuestionItemShort item : items) {
        for (QPoolSPI sp : spies) {
            if (sp != null && sp.isConversionPossible(item)) {
                List<QuestionItemShort> convertItems;
                if (formatToItems.containsKey(sp.getFormat())) {
                    convertItems = formatToItems.get(sp.getFormat());
                } else {
                    convertItems = new ArrayList<>(items.size());
                    formatToItems.put(sp.getFormat(), convertItems);
                }
                convertItems.add(item);
            }
        }
    }
    if (formatToItems.isEmpty()) {
        showWarning("convert.item.not.possible");
    } else {
        conversionConfirmationCtrl = new ConversionConfirmationController(ureq, getWindowControl(), formatToItems, getSource());
        listenTo(conversionConfirmationCtrl);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), conversionConfirmationCtrl.getInitialComponent(), true, translate("convert.item"));
        cmc.activate();
        listenTo(cmc);
    }
}
Also used : HashMap(java.util.HashMap) QPoolSPI(org.olat.modules.qpool.QPoolSPI) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QItemList(org.olat.modules.qpool.model.QItemList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 24 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.

the class QuestionListController method doExecuteExport.

private void doExecuteExport(UserRequest ureq, StepsRunContext runContext) {
    ExportFormatOptions format = (ExportFormatOptions) runContext.get("format");
    @SuppressWarnings("unchecked") List<QuestionItemShort> items = (List<QuestionItemShort>) runContext.get("itemsToExport");
    MediaResource mr = qpoolService.export(items, format, getLocale());
    if (mr != null) {
        ureq.getDispatchResult().setResultingMediaResource(mr);
    }
}
Also used : ExportFormatOptions(org.olat.modules.qpool.ExportFormatOptions) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QItemList(org.olat.modules.qpool.model.QItemList) List(java.util.List) ArrayList(java.util.ArrayList) MediaResource(org.olat.core.gui.media.MediaResource)

Example 25 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project openolat by klemens.

the class QuestionPoolMainEditorController method doDrop.

private void doDrop(UserRequest ureq, String targetId, String dropId) {
    try {
        int lastIndex = dropId.lastIndexOf('-');
        String rowStr = dropId.substring(lastIndex + 1, dropId.length());
        int row = Integer.parseInt(rowStr);
        QuestionItemShort item = ((QuestionsController) currentCtrl).getQuestionAt(row);
        TreeNode node = menuTree.getTreeModel().getNodeById(targetId);
        if (node != null) {
            Object userObj = node.getUserObject();
            if (userObj instanceof BusinessGroup) {
                doShareItemsOptions(ureq, singletonList(item), singletonList((BusinessGroup) userObj), null);
            } else if (userObj instanceof Pool) {
                doShareItemsOptions(ureq, singletonList(item), null, singletonList((Pool) userObj));
            } else if (userObj instanceof QuestionItemCollection) {
                qpoolService.addItemToCollection(singletonList(item), singletonList((QuestionItemCollection) userObj));
                showInfo("item.collectioned", item.getTitle());
            } else if (node instanceof MyQuestionsTreeNode) {
                doCopyToMyConfirmation(ureq, item);
            } else if (node instanceof MarkedQuestionsTreeNode) {
                String businessPath = "[QuestionItem:" + item.getKey() + "]";
                markManager.setMark(item, getIdentity(), null, businessPath);
                QItemMarkedEvent event = new QItemMarkedEvent("marked", item.getKey(), true);
                ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(event, QITEM_MARKED);
            }
        }
    } catch (Exception e) {
        logError("Cannot drop with id: " + dropId, e);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) MarkedQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MarkedQuestionsTreeNode) QItemMarkedEvent(org.olat.modules.qpool.ui.events.QItemMarkedEvent) MyQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MyQuestionsTreeNode) ControllerTreeNode(org.olat.modules.qpool.ui.tree.ControllerTreeNode) CollectionTreeNode(org.olat.modules.qpool.ui.tree.CollectionTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) MarkedQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MarkedQuestionsTreeNode) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) MyQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MyQuestionsTreeNode) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool)

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