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