Search in sources :

Example 46 with QuestionItem

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

the class MarkedItemsSource method addToSource.

@Override
public void addToSource(List<QuestionItem> items, boolean editable) {
    for (QuestionItem item : items) {
        String businessPath = "[QuestionItem:" + item.getResourceableId() + "]";
        markManager.setMark(item, identity, null, businessPath);
    }
}
Also used : QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 47 with QuestionItem

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

the class QuestionPoolTest method addAuthor.

@Test
public void addAuthor() throws IOException, URISyntaxException {
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("item-author-1");
    QuestionItem item = questionDao.createAndPersist(author, "NGC 55", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    Identity coAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("item-author-1");
    RestConnection conn = new RestConnection();
    Assert.assertTrue(conn.login("administrator", "openolat"));
    URI request = UriBuilder.fromUri(getContextURI()).path("/qpool/items/" + item.getKey() + "/authors/" + coAuthor.getKey()).build();
    HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    EntityUtils.consume(response.getEntity());
    // check
    List<Identity> authors = qpoolService.getAuthors(item);
    Assert.assertNotNull(authors);
    Assert.assertEquals(2, authors.size());
    Assert.assertTrue(authors.contains(author));
    Assert.assertTrue(authors.contains(coAuthor));
}
Also used : HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 48 with QuestionItem

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

the class PoolDAO method addItemToPool.

public void addItemToPool(QuestionItemShort item, List<Pool> pools, boolean editable) {
    QuestionItem lockedItem = questionItemDao.loadForUpdate(item);
    for (Pool pool : pools) {
        if (!isInPool(lockedItem, pool)) {
            PoolToItem p2i = new PoolToItem();
            p2i.setCreationDate(new Date());
            p2i.setItem(lockedItem);
            p2i.setEditable(editable);
            p2i.setPool(pool);
            dbInstance.getCurrentEntityManager().persist(p2i);
        }
    }
    // release lock asap
    dbInstance.commit();
}
Also used : PoolToItem(org.olat.modules.qpool.model.PoolToItem) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) QuestionItem(org.olat.modules.qpool.QuestionItem) Date(java.util.Date)

Example 49 with QuestionItem

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

the class QuestionPoolServiceImpl method copyItems.

@Override
public List<QuestionItem> copyItems(Identity owner, List<QuestionItemShort> itemsToCopy) {
    List<QuestionItem> copies = new ArrayList<>();
    for (QuestionItemShort itemToCopy : itemsToCopy) {
        QuestionItemImpl original = questionItemDao.loadById(itemToCopy.getKey());
        QuestionItemImpl copy = questionItemDao.copy(original);
        questionItemDao.persist(owner, copy);
        QPoolSPI provider = qpoolModule.getQuestionPoolProvider(copy.getFormat());
        if (provider != null) {
            provider.copyItem(original, copy);
        }
        licenseService.copy(original, copy);
        copies.add(copy);
    }
    dbInstance.commit();
    index(copies);
    return copies;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 50 with QuestionItem

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

the class QuestionItemDAO method share.

public void share(QuestionItem item, OLATResource resource) {
    QuestionItem lockedItem = loadForUpdate(item);
    if (!isShared(item, resource)) {
        EntityManager em = dbInstance.getCurrentEntityManager();
        ResourceShareImpl share = new ResourceShareImpl();
        share.setCreationDate(new Date());
        share.setItem(lockedItem);
        share.setResource(resource);
        em.persist(share);
    }
    // release the lock asap
    dbInstance.commit();
}
Also used : EntityManager(javax.persistence.EntityManager) ResourceShareImpl(org.olat.modules.qpool.model.ResourceShareImpl) QuestionItem(org.olat.modules.qpool.QuestionItem) Date(java.util.Date)

Aggregations

QuestionItem (org.olat.modules.qpool.QuestionItem)260 Test (org.junit.Test)160 Identity (org.olat.core.id.Identity)122 QItemType (org.olat.modules.qpool.model.QItemType)82 QuestionItemView (org.olat.modules.qpool.QuestionItemView)76 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)54 ArrayList (java.util.ArrayList)42 File (java.io.File)32 BusinessGroup (org.olat.group.BusinessGroup)32 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)32 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)30 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)28 URL (java.net.URL)24 Pool (org.olat.modules.qpool.Pool)20 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)16 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)16 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12