Search in sources :

Example 71 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class QItemQueriesDAOTest method getSharedItemByResource_orderBy.

@Test
public void getSharedItemByResource_orderBy() {
    // create a group to share 1 item
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QShare-2-" + UUID.randomUUID());
    BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao-3", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item = questionDao.createAndPersist(id, "Share-Item-3", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    dbInstance.commit();
    // share them
    List<OLATResource> resources = new ArrayList<>();
    resources.add(group.getResource());
    questionDao.share(item, resources, false);
    dbInstance.commitAndCloseSession();
    // test order by
    for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
        SortKey sortAsc = new SortKey(order.name(), true);
        List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1, sortAsc);
        Assert.assertNotNull(ascOrderedItems);
        SortKey sortDesc = new SortKey(order.name(), false);
        List<QuestionItemView> descOrderedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1, sortDesc);
        Assert.assertNotNull(descOrderedItems);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) SortKey(org.olat.core.commons.persistence.SortKey) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 72 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class QItemQueriesDAOTest method getSharedItemByResource_subset.

@Test
public void getSharedItemByResource_subset() {
    // create a group to share 2 items
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QShare-1-" + UUID.randomUUID());
    BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item1 = questionDao.createAndPersist(id, "Share-Item-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    QuestionItem item2 = questionDao.createAndPersist(id, "Share-Item-2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType);
    dbInstance.commit();
    // share them
    questionDao.share(item1, group.getResource());
    questionDao.share(item2, group.getResource());
    // retrieve them
    List<QuestionItemView> sharedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
    List<Long> sharedItemKeys = new ArrayList<>();
    for (QuestionItemView sharedItem : sharedItems) {
        sharedItemKeys.add(sharedItem.getKey());
    }
    Assert.assertNotNull(sharedItems);
    Assert.assertEquals(2, sharedItems.size());
    Assert.assertTrue(sharedItemKeys.contains(item1.getKey()));
    Assert.assertTrue(sharedItemKeys.contains(item2.getKey()));
    // retrieve limited sub set
    List<QuestionItemView> limitedSharedItems = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), Collections.singletonList(item1.getKey()), null, 0, -1);
    Assert.assertNotNull(limitedSharedItems);
    Assert.assertEquals(1, limitedSharedItems.size());
    Assert.assertEquals(item1.getKey(), limitedSharedItems.get(0).getKey());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 73 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class QItemQueriesDAOTest method shouldGetItemsIsEditableInAShare.

@Test
public void shouldGetItemsIsEditableInAShare() {
    Identity owner1 = createRandomIdentity();
    QuestionItem item11 = createRandomItem(owner1);
    QuestionItem item12 = createRandomItem(owner1);
    QuestionItem item13 = createRandomItem(owner1);
    BusinessGroup group = businessGroupDao.createAndPersist(owner1, "QPool", "QPool", -1, -1, false, false, false, false, false);
    List<OLATResource> groupResources = Arrays.asList(group.getResource());
    questionDao.share(item11, groupResources, true);
    questionDao.share(item12, groupResources, false);
    dbInstance.commitAndCloseSession();
    SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null);
    List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1);
    assertThat(filterByKey(loadedItems, item11).isEditableInShare()).isTrue();
    assertThat(filterByKey(loadedItems, item12).isEditableInShare()).isFalse();
    assertThat(filterByKey(loadedItems, item13).isEditableInShare()).isFalse();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResource(org.olat.resource.OLATResource) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Example 74 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class ACFrontendManagerTest method testFreeAccesToBusinessGroup_full.

/**
 * Test free access to a group without waiting list and which is full
 */
@Test
public void testFreeAccesToBusinessGroup_full() {
    // create a group with a free offer, fill 2 places on 2
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
    businessGroupRelationDao.addRole(id1, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
    Offer offer = acService.createOffer(group.getResource(), "Free group (waiting)");
    offer = acService.save(offer);
    List<AccessMethod> freeMethods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
    OfferAccess offerAccess = acService.createOfferAccess(offer, freeMethods.get(0));
    Assert.assertNotNull(offerAccess);
    dbInstance.commitAndCloseSession();
    // access it
    AccessResult result = acService.accessResource(id3, offerAccess, null);
    Assert.assertNotNull(result);
    Assert.assertFalse(result.isAccessible());
    dbInstance.commitAndCloseSession();
    // is id a waiting?
    boolean participant = businessGroupRelationDao.hasRole(id3, group, GroupRoles.participant.name());
    Assert.assertFalse(participant);
    boolean waiting = businessGroupRelationDao.hasRole(id3, group, GroupRoles.waiting.name());
    Assert.assertFalse(waiting);
}
Also used : PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 75 with BusinessGroup

use of org.olat.group.BusinessGroup in project OpenOLAT by OpenOLAT.

the class ACFrontendManagerTest method testPaiedAccesToBusinessGroup_full.

@Test
public void testPaiedAccesToBusinessGroup_full() {
    // enable paypal
    boolean enabled = acModule.isPaypalEnabled();
    if (!enabled) {
        acModule.setPaypalEnabled(true);
    }
    // create a group with a free offer
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("pay-1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
    Offer offer = acService.createOffer(group.getResource(), "Free group (waiting)");
    offer = acService.save(offer);
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(PaypalAccessMethod.class);
    Assert.assertFalse(methods.isEmpty());
    OfferAccess offerAccess = acService.createOfferAccess(offer, methods.get(0));
    Assert.assertNotNull(offerAccess);
    dbInstance.commitAndCloseSession();
    // admin fill the group
    businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id3, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // id1 try to reserve a place before the payment process
    boolean reserved = acService.reserveAccessToResource(id1, offerAccess);
    Assert.assertFalse(reserved);
    if (!enabled) {
        acModule.setPaypalEnabled(false);
    }
}
Also used : PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

BusinessGroup (org.olat.group.BusinessGroup)1034 Test (org.junit.Test)536 Identity (org.olat.core.id.Identity)536 RepositoryEntry (org.olat.repository.RepositoryEntry)324 ArrayList (java.util.ArrayList)224 BusinessGroupService (org.olat.group.BusinessGroupService)116 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)84 BGArea (org.olat.group.area.BGArea)70 CollaborationTools (org.olat.collaboration.CollaborationTools)58 OLATResource (org.olat.resource.OLATResource)56 Date (java.util.Date)54 HashSet (java.util.HashSet)50 File (java.io.File)46 Path (javax.ws.rs.Path)42 Group (org.olat.basesecurity.Group)42 HashMap (java.util.HashMap)38 Roles (org.olat.core.id.Roles)38 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)38 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)38 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)38