use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method shareItems_removeFromBusinessGroups.
@Test
public void shareItems_removeFromBusinessGroups() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-item-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-Item-Dup-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
questionDao.share(item, group.getResource());
dbInstance.commit();
// check them
List<QuestionItemView> shared = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
Assert.assertNotNull(shared);
Assert.assertEquals(1, shared.size());
// remove
questionDao.removeFromShare(Collections.<QuestionItemShort>singletonList(item), group.getResource());
dbInstance.commitAndCloseSession();
// check
int numOfStayingItems = questionDao.countSharedItemByResource(group.getResource(), null);
Assert.assertEquals(0, numOfStayingItems);
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionPoolTest method getAuthor.
@Test
public void getAuthor() throws IOException, URISyntaxException {
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("item-author-2");
QuestionItem item = questionDao.createAndPersist(author, "NGC 55", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/qpool/items/" + item.getKey() + "/authors/" + author.getKey()).build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
UserVO user = conn.parse(response.getEntity().getContent(), UserVO.class);
// check
Assert.assertNotNull(user);
Assert.assertTrue(author.getKey().equals(user.getKey()));
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionPoolTest method removeAuthor.
@Test
public void removeAuthor() 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");
List<Identity> authors = Collections.singletonList(coAuthor);
questionItemDao.addAuthors(authors, item);
dbInstance.commit();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/qpool/items/" + item.getKey() + "/authors/" + coAuthor.getKey()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// check
List<Identity> itemsAuthors = qpoolService.getAuthors(item);
Assert.assertNotNull(itemsAuthors);
Assert.assertEquals(1, itemsAuthors.size());
Assert.assertTrue(itemsAuthors.contains(author));
Assert.assertFalse(itemsAuthors.contains(coAuthor));
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionPoolTest method getAuthors.
@Test
public void getAuthors() 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);
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/qpool/items/" + item.getKey() + "/authors/").build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
List<UserVO> users = parseUserArray(response.getEntity().getContent());
// check
Assert.assertNotNull(users);
Assert.assertEquals(1, users.size());
Assert.assertTrue(author.getKey().equals(users.get(0).getKey()));
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QItemTypeDAO method create.
public QItemType create(String type, boolean deletable) {
QItemType itemType = new QItemType();
itemType.setCreationDate(new Date());
itemType.setType(type.toLowerCase());
itemType.setDeletable(deletable);
dbInstance.getCurrentEntityManager().persist(itemType);
return itemType;
}
Aggregations