Search in sources :

Example 1 with CollectionToItem

use of org.olat.modules.qpool.model.CollectionToItem in project OpenOLAT by OpenOLAT.

the class CollectionDAO method addItemToCollection.

/**
 * Add an item to a collection
 * @param itemKey
 * @param collection
 * @return true if the item is in the collection after the call
 */
public boolean addItemToCollection(QuestionItemShort item, List<QuestionItemCollection> collections) {
    QuestionItemImpl lockedItem = questionItemDao.loadForUpdate(item);
    if (lockedItem == null) {
        return false;
    }
    Set<QuestionItemCollection> uniqueCollections = new HashSet<>(collections);
    for (QuestionItemCollection collection : uniqueCollections) {
        if (!isInCollection(collection, lockedItem)) {
            CollectionToItem coll2Item = new CollectionToItem();
            coll2Item.setCreationDate(new Date());
            coll2Item.setCollection(collection);
            coll2Item.setItem(lockedItem);
            dbInstance.getCurrentEntityManager().persist(coll2Item);
        }
    }
    dbInstance.commit();
    return true;
}
Also used : CollectionToItem(org.olat.modules.qpool.model.CollectionToItem) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Date(java.util.Date) HashSet(java.util.HashSet)

Example 2 with CollectionToItem

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

the class CollectionDAO method addItemToCollection.

/**
 * Add an item to a collection
 * @param itemKey
 * @param collection
 * @return true if the item is in the collection after the call
 */
public boolean addItemToCollection(QuestionItemShort item, List<QuestionItemCollection> collections) {
    QuestionItemImpl lockedItem = questionItemDao.loadForUpdate(item);
    if (lockedItem == null) {
        return false;
    }
    Set<QuestionItemCollection> uniqueCollections = new HashSet<>(collections);
    for (QuestionItemCollection collection : uniqueCollections) {
        if (!isInCollection(collection, lockedItem)) {
            CollectionToItem coll2Item = new CollectionToItem();
            coll2Item.setCreationDate(new Date());
            coll2Item.setCollection(collection);
            coll2Item.setItem(lockedItem);
            dbInstance.getCurrentEntityManager().persist(coll2Item);
        }
    }
    dbInstance.commit();
    return true;
}
Also used : CollectionToItem(org.olat.modules.qpool.model.CollectionToItem) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

Date (java.util.Date)2 HashSet (java.util.HashSet)2 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)2 CollectionToItem (org.olat.modules.qpool.model.CollectionToItem)2 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)2