Search in sources :

Example 36 with BusinessGroup

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

the class BusinessGroupImportExportTest method importLearningGroupsAndAreasWithResource.

@Test
public void importLearningGroupsAndAreasWithResource() throws URISyntaxException {
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    URL input = BusinessGroupImportExportTest.class.getResource("learninggroupexport_3.xml");
    File importXml = new File(input.toURI());
    businessGroupService.importGroups(resource, importXml);
    dbInstance.commitAndCloseSession();
    // check if all three groups are imported
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, resource, 0, -1);
    Assert.assertNotNull(groups);
    Assert.assertEquals(3, groups.size());
    // check if all three areas are imported
    List<BGArea> areas = areaManager.findBGAreasInContext(resource.getOlatResource());
    Assert.assertNotNull(areas);
    Assert.assertEquals(3, areas.size());
    // check first area
    BGArea area1 = areaManager.findBGArea("Area 1", resource.getOlatResource());
    Assert.assertNotNull(area1);
    Assert.assertEquals("Area 1", area1.getName());
    Assert.assertEquals("<p>Area 1 description</p>", area1.getDescription());
    // check relation to groups
    List<BusinessGroup> groupArea1 = areaManager.findBusinessGroupsOfArea(area1);
    Assert.assertNotNull(groupArea1);
    Assert.assertEquals(2, groupArea1.size());
    Assert.assertTrue(groupArea1.get(0).getName().equals("Export group 1") || groupArea1.get(1).getName().equals("Export group 1"));
    Assert.assertTrue(groupArea1.get(0).getName().equals("Export group 2") || groupArea1.get(1).getName().equals("Export group 2"));
    // check empty area
    BGArea area3 = areaManager.findBGArea("Area 3", resource.getOlatResource());
    Assert.assertNotNull(area1);
    Assert.assertEquals("Area 3", area3.getName());
    // check relation to groups
    List<BusinessGroup> groupArea3 = areaManager.findBusinessGroupsOfArea(area3);
    Assert.assertNotNull(groupArea3);
    Assert.assertEquals(0, groupArea3.size());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 37 with BusinessGroup

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

the class BusinessGroupRelationDAOTest method getMemberKeysOrderByDate.

@Test
public void getMemberKeysOrderByDate() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1");
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsRndUser("ordered-1");
    BusinessGroup group = businessGroupDao.createAndPersist(null, "to-group-1", "to-group-1-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(id1, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id3, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // load the identities
    List<Long> ids = businessGroupRelationDao.getMemberKeysOrderByDate(group, GroupRoles.participant.name());
    Assert.assertNotNull(ids);
    Assert.assertEquals(3, ids.size());
    Assert.assertTrue(ids.contains(id1.getKey()));
    Assert.assertTrue(ids.contains(id2.getKey()));
    Assert.assertTrue(ids.contains(id3.getKey()));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 38 with BusinessGroup

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

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 39 with BusinessGroup

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

the class BusinessGroupRelationDAOTest method getDuplicateMemberships.

@Test
public void getDuplicateMemberships() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("wait-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("wait-1");
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "to-group-1", "to-group-1-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "to-group-2", "to-group-2-desc", -1, -1, false, false, false, false, false);
    BusinessGroup group3 = businessGroupDao.createAndPersist(null, "to-group-2", "to-group-2-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRole(id1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id1, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group3, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // id1 is a duplicate
    List<BusinessGroup> groups = new ArrayList<>(2);
    groups.add(group1);
    groups.add(group2);
    groups.add(group3);
    List<IdentityRef> duplicates = businessGroupRelationDao.getDuplicateMemberships(groups);
    Assert.assertNotNull(duplicates);
    Assert.assertEquals(1, duplicates.size());
    Assert.assertEquals(id1.getKey(), duplicates.get(0).getKey());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) IdentityRef(org.olat.basesecurity.IdentityRef) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 40 with BusinessGroup

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

the class BusinessGroupRelationDAOTest method countRoles.

@Test
public void countRoles() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("auth-" + UUID.randomUUID().toString());
    Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("not-auth");
    BusinessGroup group = businessGroupDao.createAndPersist(null, "rel-repo", "rel-repo-desc", 0, 10, true, false, false, false, false);
    businessGroupRelationDao.addRole(author, group, GroupRoles.coach.name());
    businessGroupRelationDao.addRole(test, group, GroupRoles.coach.name());
    dbInstance.commitAndCloseSession();
    int numOfCoachs = businessGroupRelationDao.countRoles(group, GroupRoles.coach.name());
    Assert.assertEquals(2, numOfCoachs);
    int numOfParticipants = businessGroupRelationDao.countRoles(group, GroupRoles.participant.name());
    Assert.assertEquals(0, numOfParticipants);
}
Also used : 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