Search in sources :

Example 81 with QItemType

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);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 82 with QItemType

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()));
}
Also used : UserVO(org.olat.user.restapi.UserVO) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) URI(java.net.URI) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 83 with QItemType

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));
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) URI(java.net.URI) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 84 with QItemType

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()));
}
Also used : UserVO(org.olat.user.restapi.UserVO) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) URI(java.net.URI) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 85 with QItemType

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;
}
Also used : Date(java.util.Date) QItemType(org.olat.modules.qpool.model.QItemType)

Aggregations

QItemType (org.olat.modules.qpool.model.QItemType)118 Test (org.junit.Test)94 QuestionItem (org.olat.modules.qpool.QuestionItem)82 Identity (org.olat.core.id.Identity)58 BusinessGroup (org.olat.group.BusinessGroup)22 QuestionItemView (org.olat.modules.qpool.QuestionItemView)18 Pool (org.olat.modules.qpool.Pool)12 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)12 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)12 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 HttpResponse (org.apache.http.HttpResponse)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)8 QEducationalContext (org.olat.modules.qpool.model.QEducationalContext)8 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)8 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6 QuestionType (org.olat.modules.qpool.QuestionType)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 InputStream (java.io.InputStream)4