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());
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations