Search in sources :

Example 46 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project OpenOLAT by OpenOLAT.

the class QuestionPoolServiceImpl method convertItems.

@Override
public List<QuestionItem> convertItems(Identity cloner, List<QuestionItemShort> itemsToConvert, String format, Locale locale) {
    QPoolSPI sp = qpoolModule.getQuestionPoolProvider(format);
    List<QuestionItem> convertedQuestions = new ArrayList<>(itemsToConvert.size());
    for (QuestionItemShort item : itemsToConvert) {
        QuestionItem convertedQuestion = sp.convert(cloner, item, locale);
        licenseService.copy(item, convertedQuestion);
        if (convertedQuestion != null) {
            convertedQuestions.add(convertedQuestion);
        }
    }
    dbInstance.commit();
    index(convertedQuestions);
    return convertedQuestions;
}
Also used : QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 47 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project OpenOLAT by OpenOLAT.

the class QuestionPoolServiceImpl method addItemsInPools.

@Override
public void addItemsInPools(List<? extends QuestionItemShort> items, List<Pool> pools, boolean editable) {
    if (items == null || items.isEmpty() || pools == null || pools.isEmpty()) {
        // nothing to do
        return;
    }
    List<Long> keys = new ArrayList<>(items.size());
    for (QuestionItemShort item : items) {
        poolDao.addItemToPool(item, pools, editable);
        keys.add(item.getKey());
    }
    dbInstance.commit();
    lifeIndexer.indexDocument(QItemDocument.TYPE, keys);
}
Also used : QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList)

Example 48 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project OpenOLAT by OpenOLAT.

the class CollectionDAO method deleteItemFromCollections.

public int deleteItemFromCollections(List<? extends QuestionItemShort> items) {
    // noting to do
    if (items == null || items.isEmpty())
        return 0;
    List<Long> keys = new ArrayList<>();
    for (QuestionItemShort item : items) {
        keys.add(item.getKey());
    }
    StringBuilder sb = new StringBuilder();
    sb.append("delete from qcollection2item coll2item where coll2item.item.key in (:itemKeys)");
    return dbInstance.getCurrentEntityManager().createQuery(sb.toString()).setParameter("itemKeys", keys).executeUpdate();
}
Also used : QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList)

Example 49 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project OpenOLAT by OpenOLAT.

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 50 with QuestionItemShort

use of org.olat.modules.qpool.QuestionItemShort in project OpenOLAT by OpenOLAT.

the class QuestionItemDetailsController method doDelete.

private void doDelete(UserRequest ureq, List<QuestionItemShort> items) {
    for (QuestionItemShort item : items) {
        QuestionItem qitem = qpoolService.loadItemById(item.getKey());
        QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.DELETE_QUESTION_ITEM);
        builder.withBefore(qitem);
        qpoolService.persist(builder.create());
    }
    qpoolService.deleteItems(items);
    fireEvent(ureq, new QPoolEvent(QPoolEvent.ITEM_DELETED));
    showInfo("item.deleted");
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QPoolEvent(org.olat.modules.qpool.ui.events.QPoolEvent) QuestionItem(org.olat.modules.qpool.QuestionItem)

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