Search in sources :

Example 46 with BusinessGroupQueryParams

use of org.olat.group.model.BusinessGroupQueryParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findPublicGroupsLimitedDate.

@Test
public void findPublicGroupsLimitedDate() {
    // create a group with an access control limited by a valid date
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-11");
    BusinessGroup groupVisible = businessGroupDao.createAndPersist(null, "access-grp-2", "access-grp-2-desc", 0, 5, true, false, true, false, false);
    // create and save an offer
    Offer offer = acService.createOffer(groupVisible.getResource(), "TestBGWorkflow");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, -1);
    offer.setValidFrom(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, 2);
    offer.setValidTo(cal.getTime());
    assertNotNull(offer);
    offer = acService.save(offer);
    acMethodManager.enableMethod(TokenAccessMethod.class, true);
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
    AccessMethod method = methods.get(0);
    OfferAccess access = acMethodManager.createOfferAccess(offer, method);
    acMethodManager.save(access);
    // create a group with an access control limited by dates in the past
    BusinessGroup oldGroup = businessGroupDao.createAndPersist(null, "access-grp-3", "access-grp-3-desc", 0, 5, true, false, true, false, false);
    // create and save an offer
    Offer oldOffer = acService.createOffer(oldGroup.getResource(), "TestBGWorkflow");
    cal.add(Calendar.HOUR_OF_DAY, -5);
    oldOffer.setValidFrom(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, -5);
    oldOffer.setValidTo(cal.getTime());
    assertNotNull(oldOffer);
    oldOffer = acService.save(oldOffer);
    OfferAccess oldAccess = acMethodManager.createOfferAccess(oldOffer, method);
    acMethodManager.save(oldAccess);
    dbInstance.commitAndCloseSession();
    // retrieve the offer
    BusinessGroupQueryParams paramsAll = new BusinessGroupQueryParams();
    paramsAll.setPublicGroups(Boolean.TRUE);
    List<BusinessGroupRow> accessGroups = businessGroupDao.searchBusinessGroupsWithMemberships(paramsAll, id);
    Assert.assertNotNull(accessGroups);
    Assert.assertTrue(accessGroups.size() >= 1);
    Assert.assertTrue(contains(accessGroups, groupVisible));
    Assert.assertFalse(contains(accessGroups, oldGroup));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) OfferAccess(org.olat.resource.accesscontrol.OfferAccess) BusinessGroup(org.olat.group.BusinessGroup) Offer(org.olat.resource.accesscontrol.Offer) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Example 47 with BusinessGroupQueryParams

use of org.olat.group.model.BusinessGroupQueryParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findBusinessGroupsByOwner.

@Test
public void findBusinessGroupsByOwner() {
    // 5 identities
    String marker = UUID.randomUUID().toString();
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser(marker);
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("ddao-2-" + marker);
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser(marker + "-ddao-3");
    Identity id4 = JunitTestHelper.createAndPersistIdentityAsUser("something-else-ddao-4");
    BusinessGroup group1 = businessGroupDao.createAndPersist(id1, "fingbgown-1", "fingbgown-1-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(id2, "fingbgown-2", "fingbgown-2-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(id3, "fingbgown-3", "fingbgown-3-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group4 = businessGroupDao.createAndPersist(id4, "fingbgown-4", "fingbgown-4-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    // check the same with the views
    BusinessGroupQueryParams searchParams = new BusinessGroupQueryParams();
    searchParams.setOwnerName(marker);
    List<BusinessGroupRow> groupViews = businessGroupDao.searchBusinessGroupsWithMemberships(searchParams, id1);
    Assert.assertNotNull(groupViews);
    Assert.assertEquals(3, groupViews.size());
    Assert.assertTrue(contains(groupViews, group1));
    Assert.assertTrue(contains(groupViews, group2));
    Assert.assertTrue(contains(groupViews, group3));
    Assert.assertFalse(contains(groupViews, group4));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Example 48 with BusinessGroupQueryParams

use of org.olat.group.model.BusinessGroupQueryParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findBusinessGroupWithAuthorConnection.

@Test
public void findBusinessGroupWithAuthorConnection() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsUser("bdao-5-" + UUID.randomUUID().toString());
    RepositoryEntry re = JunitTestHelper.createAndPersistRepositoryEntry();
    repositoryEntryRelationDao.addRole(author, re, GroupRoles.owner.name());
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "gdlo", "gdlo-desc", 0, 5, true, false, false, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(author, "gdmo", "gdmo-desc", 0, 5, true, false, false, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(author, "gdmo", "gdmo-desc", 0, 5, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, re);
    businessGroupRelationDao.addRelationToResource(group3, re);
    dbInstance.commitAndCloseSession();
    // check
    BusinessGroupQueryParams params = new BusinessGroupQueryParams();
    params.setAuthorConnection(true);
    List<StatisticsBusinessGroupRow> groups = businessGroupDao.searchBusinessGroupsForSelection(params, author);
    Assert.assertNotNull(groups);
    Assert.assertEquals(2, groups.size());
    Set<Long> retrievedGroupkey = new HashSet<Long>();
    for (StatisticsBusinessGroupRow group : groups) {
        retrievedGroupkey.add(group.getKey());
    }
    Assert.assertTrue(retrievedGroupkey.contains(group1.getKey()));
    Assert.assertTrue(retrievedGroupkey.contains(group3.getKey()));
    Assert.assertFalse(retrievedGroupkey.contains(group2.getKey()));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 49 with BusinessGroupQueryParams

use of org.olat.group.model.BusinessGroupQueryParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findMarkedBusinessGroup.

@Test
public void findMarkedBusinessGroup() {
    Identity marker = JunitTestHelper.createAndPersistIdentityAsUser("marker-" + UUID.randomUUID().toString());
    // create a group with a mark and an other without as control
    BusinessGroup group1 = businessGroupDao.createAndPersist(marker, "marked-grp-1", "marked-grp-1-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(marker, "marked-grp-2", "marked-grp-2-desc", 0, 5, true, false, true, false, false);
    markManager.setMark(group1.getResource(), marker, null, "[BusinessGroup:" + group1.getKey() + "]");
    dbInstance.commitAndCloseSession();
    // check the search with the views
    // check marked
    BusinessGroupQueryParams queryMarkedParams = new BusinessGroupQueryParams();
    queryMarkedParams.setOwner(true);
    queryMarkedParams.setMarked(true);
    List<BusinessGroupRow> markedGroupViews = businessGroupDao.searchBusinessGroupsWithMemberships(queryMarkedParams, marker);
    Assert.assertNotNull(markedGroupViews);
    Assert.assertEquals(1, markedGroupViews.size());
    Assert.assertTrue(contains(markedGroupViews, group1));
    Assert.assertFalse(contains(markedGroupViews, group2));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Example 50 with BusinessGroupQueryParams

use of org.olat.group.model.BusinessGroupQueryParams in project OpenOLAT by OpenOLAT.

the class BusinessGroupDAOTest method findBusinessGroupsByNameOrDesc.

@Test
public void findBusinessGroupsByNameOrDesc() {
    String marker = UUID.randomUUID().toString();
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-6");
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "fingbg-1", marker.toUpperCase() + "-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "fingbg-2", "fingbg-2-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, marker.toUpperCase() + "-xxx", "desc-fingb-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    params.setNameOrDesc(marker);
    List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(2, groups.size());
    Assert.assertTrue(groups.contains(group1));
    Assert.assertFalse(groups.contains(group2));
    Assert.assertTrue(groups.contains(group3));
    // check the same search with the views
    BusinessGroupQueryParams searchParams = new BusinessGroupQueryParams();
    searchParams.setNameOrDesc(marker);
    List<BusinessGroupRow> groupViews = businessGroupDao.searchBusinessGroupsWithMemberships(searchParams, identity);
    Assert.assertNotNull(groupViews);
    Assert.assertEquals(2, groupViews.size());
    Assert.assertTrue(contains(groupViews, group1));
    Assert.assertFalse(contains(groupViews, group2));
    Assert.assertTrue(contains(groupViews, group3));
}
Also used : BusinessGroupQueryParams(org.olat.group.model.BusinessGroupQueryParams) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) StatisticsBusinessGroupRow(org.olat.group.model.StatisticsBusinessGroupRow) BusinessGroupRow(org.olat.group.model.BusinessGroupRow) OpenBusinessGroupRow(org.olat.group.model.OpenBusinessGroupRow) Test(org.junit.Test)

Aggregations

BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)82 Test (org.junit.Test)38 Identity (org.olat.core.id.Identity)38 BusinessGroup (org.olat.group.BusinessGroup)38 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)38 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)36 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)34 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)16 RepositoryEntry (org.olat.repository.RepositoryEntry)8 Offer (org.olat.resource.accesscontrol.Offer)4 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)4 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)4 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)4 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 BGPermission (org.olat.course.member.PermissionHelper.BGPermission)2 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)2 BusinessGroupRowComparator (org.olat.group.model.comparator.BusinessGroupRowComparator)2