Search in sources :

Example 76 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.

the class BusinessGroupRelationDAOTest method findAndCountBusinessGroups.

@Test
public void findAndCountBusinessGroups() {
    // prepare 2 resources + 3 groups with 3 owners
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("wait-1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("wait-2-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("wait-3-" + UUID.randomUUID().toString());
    RepositoryEntry resource1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry resource2 = JunitTestHelper.createAndPersistRepositoryEntry();
    BusinessGroup group1 = businessGroupDao.createAndPersist(id1, "rel-bg-part-one", "rel-bgis-1-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group1, resource1);
    businessGroupRelationDao.addRelationToResource(group1, resource2);
    BusinessGroup group2 = businessGroupDao.createAndPersist(id2, "rel-bg-part-two", "rel-bgis-2-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group2, resource1);
    BusinessGroup group3 = businessGroupDao.createAndPersist(id3, "rel-bg-part-three", "rel-bgis-3-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group3, resource2);
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    // check resource 1
    int count1_1 = businessGroupDao.countBusinessGroups(params, resource1);
    Assert.assertEquals(2, count1_1);
    List<BusinessGroup> groups1_1 = businessGroupDao.findBusinessGroups(params, resource1, 0, -1);
    Assert.assertNotNull(groups1_1);
    Assert.assertEquals(2, groups1_1.size());
    Assert.assertTrue(groups1_1.contains(group1));
    Assert.assertTrue(groups1_1.contains(group2));
    // check owner 1 + resource 1
    SearchBusinessGroupParams paramsRestricted = new SearchBusinessGroupParams(id1, true, true);
    int count3_1 = businessGroupDao.countBusinessGroups(paramsRestricted, resource1);
    Assert.assertEquals(1, count3_1);
    List<BusinessGroup> groups3_1 = businessGroupDao.findBusinessGroups(paramsRestricted, resource1, 0, -1);
    Assert.assertNotNull(groups3_1);
    Assert.assertEquals(1, groups3_1.size());
    Assert.assertEquals(group1, groups3_1.get(0));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Example 77 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.

the class BusinessGroupServiceTest method testGroupsOfBGContext.

@Test
public void testGroupsOfBGContext() {
    RepositoryEntry c1 = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry c2 = JunitTestHelper.createAndPersistRepositoryEntry();
    // simulate user clicks
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params1 = new SearchBusinessGroupParams(null, false, false);
    assertTrue(businessGroupService.findBusinessGroups(params1, c1, 0, -1).isEmpty());
    assertTrue(businessGroupService.countBusinessGroups(params1, c1) == 0);
    // simulate user clicks
    dbInstance.commitAndCloseSession();
    BusinessGroup g1 = businessGroupService.createBusinessGroup(null, "g1", null, 0, 10, false, false, c1);
    assertNotNull(g1);
    BusinessGroup g2 = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, c1);
    assertNotNull(g2);
    BusinessGroup g3 = businessGroupService.createBusinessGroup(null, "g3", null, 0, 10, false, false, c2);
    assertNotNull(g3);
    BusinessGroup g2duplicate = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, c1);
    // name duplicate names are allowed per group context
    assertNotNull(g2duplicate);
    BusinessGroup g4 = businessGroupService.createBusinessGroup(null, "g2", null, 0, 10, false, false, c2);
    // name duplicate in other context allowed
    assertNotNull(g4);
    // simulate user clicks
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params2 = new SearchBusinessGroupParams(null, false, false);
    Assert.assertEquals(3, businessGroupService.findBusinessGroups(params2, c1, 0, -1).size());
    Assert.assertEquals(3, businessGroupService.countBusinessGroups(params2, c1));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Example 78 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.

the class BusinessGroupDAOTest method findBusinessGroupsByNameOrDescFuzzy.

@Test
public void findBusinessGroupsByNameOrDescFuzzy() {
    String marker = UUID.randomUUID().toString();
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-7");
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "fingbg-1", marker + "-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "fingbg-2", "desc-" + marker.toUpperCase(), 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "fingbg-3", "desc-" + marker + "-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(3, groups.size());
    Assert.assertTrue(groups.contains(group1));
    Assert.assertTrue(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(3, groupViews.size());
    Assert.assertTrue(contains(groupViews, group1));
    Assert.assertTrue(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)

Example 79 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.

the class BusinessGroupDAOTest method findBusinessGroupsByName.

@Test
public void findBusinessGroupsByName() {
    String marker = UUID.randomUUID().toString();
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("bg-search-2");
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, marker.toUpperCase(), "fingbg-1-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, marker + "xxx", "fingbg-2-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "yyy" + marker.toUpperCase(), "fingbg-3-desc", 0, 5, true, false, true, false, false);
    BusinessGroup group4 = businessGroupDao.createAndPersist(null, "yyyyZZZxxx", "fingbg-3-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    SearchBusinessGroupParams params = new SearchBusinessGroupParams();
    params.setName(marker);
    List<BusinessGroup> groups = businessGroupDao.findBusinessGroups(params, null, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(3, groups.size());
    Assert.assertTrue(groups.contains(group1));
    Assert.assertTrue(groups.contains(group2));
    Assert.assertTrue(groups.contains(group3));
    Assert.assertFalse(groups.contains(group4));
    // check the same with the views
    BusinessGroupQueryParams searchParams = new BusinessGroupQueryParams();
    searchParams.setName(marker);
    List<BusinessGroupRow> groupViews = businessGroupDao.searchBusinessGroupsWithMemberships(searchParams, identity);
    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) 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)

Example 80 with SearchBusinessGroupParams

use of org.olat.group.model.SearchBusinessGroupParams in project openolat by klemens.

the class BusinessGroupDAOTest method findManagedGroups.

@Test
public void findManagedGroups() {
    // create a managed group with an external ID
    String externalId = UUID.randomUUID().toString();
    String managedFlags = "title,description";
    BusinessGroup managedGroup = businessGroupDao.createAndPersist(null, "managed-grp-1", "managed-grp-1-desc", externalId, managedFlags, 0, 5, true, false, true, false, false);
    BusinessGroup freeGroup = businessGroupDao.createAndPersist(null, "free-grp-1", "free-grp-1-desc", 0, 5, true, false, true, false, false);
    dbInstance.commitAndCloseSession();
    // search managed group
    SearchBusinessGroupParams paramsManaged = new SearchBusinessGroupParams();
    paramsManaged.setManaged(Boolean.TRUE);
    List<BusinessGroup> managedGroups = businessGroupDao.findBusinessGroups(paramsManaged, null, 0, 0);
    Assert.assertNotNull(managedGroups);
    Assert.assertTrue(managedGroups.size() >= 1);
    Assert.assertTrue(managedGroups.contains(managedGroup));
    Assert.assertFalse(managedGroups.contains(freeGroup));
    // search free group
    SearchBusinessGroupParams paramsAll = new SearchBusinessGroupParams();
    paramsAll.setManaged(Boolean.FALSE);
    List<BusinessGroup> freeGroups = businessGroupDao.findBusinessGroups(paramsAll, null, 0, 0);
    Assert.assertNotNull(freeGroups);
    Assert.assertTrue(freeGroups.size() >= 1);
    Assert.assertTrue(freeGroups.contains(freeGroup));
    Assert.assertFalse(freeGroups.contains(managedGroup));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Test(org.junit.Test)

Aggregations

SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)92 BusinessGroup (org.olat.group.BusinessGroup)84 Identity (org.olat.core.id.Identity)36 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)26 BusinessGroupService (org.olat.group.BusinessGroupService)18 BusinessGroupQueryParams (org.olat.group.model.BusinessGroupQueryParams)16 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)16 OpenBusinessGroupRow (org.olat.group.model.OpenBusinessGroupRow)16 StatisticsBusinessGroupRow (org.olat.group.model.StatisticsBusinessGroupRow)16 RepositoryEntry (org.olat.repository.RepositoryEntry)16 HashSet (java.util.HashSet)12 GET (javax.ws.rs.GET)10 Produces (javax.ws.rs.Produces)10 Roles (org.olat.core.id.Roles)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)6 ICourse (org.olat.course.ICourse)6