Search in sources :

Example 71 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method findBusinessGroupsOfAreaKeys_andGroupKeys.

@Test
public void findBusinessGroupsOfAreaKeys_andGroupKeys() {
    // create a resource, 3 area and 2 group
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    String areaName = UUID.randomUUID().toString();
    BGArea area1 = areaManager.createAndPersistBGArea("find-group-1-" + areaName, "description:" + areaName, resource.getOlatResource());
    BGArea area2 = areaManager.createAndPersistBGArea("find-group-2-" + areaName, "description:" + areaName, resource.getOlatResource());
    // create 2 groups
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "find-group-1-area", "find-group-in-area-1-desc", 0, -1, false, false, resource);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "find-group-2-area", "find-group-in-area-2-desc", 0, -1, false, false, resource);
    BusinessGroup group3 = businessGroupService.createBusinessGroup(null, "find-group-2-area", "find-group-in-area-3-desc", 0, -1, false, false, resource);
    dbInstance.commitAndCloseSession();
    // add the relations
    areaManager.addBGToBGArea(group1, area1);
    areaManager.addBGToBGArea(group1, area2);
    areaManager.addBGToBGArea(group2, area2);
    areaManager.addBGToBGArea(group3, area2);
    dbInstance.commitAndCloseSession();
    // check find area 2 -> all 3 groups
    List<Long> area2Key = Collections.singletonList(area2.getKey());
    List<BusinessGroup> groupsArea2 = areaManager.findBusinessGroupsOfAreaKeys(area2Key);
    Assert.assertNotNull(groupsArea2);
    Assert.assertEquals(3, groupsArea2.size());
    Assert.assertTrue(groupsArea2.contains(group1));
    Assert.assertTrue(groupsArea2.contains(group2));
    Assert.assertTrue(groupsArea2.contains(group3));
    List<Long> groupKeysArea2 = areaManager.findBusinessGroupKeysOfAreaKeys(area2Key);
    Assert.assertNotNull(groupKeysArea2);
    Assert.assertEquals(3, groupKeysArea2.size());
    Assert.assertTrue(groupKeysArea2.contains(group1.getKey()));
    Assert.assertTrue(groupKeysArea2.contains(group2.getKey()));
    Assert.assertTrue(groupKeysArea2.contains(group3.getKey()));
    // check find area 1 -> only group 1
    List<Long> area1Key = Collections.singletonList(area1.getKey());
    List<BusinessGroup> groupsArea1 = areaManager.findBusinessGroupsOfAreaKeys(area1Key);
    Assert.assertNotNull(groupsArea1);
    Assert.assertEquals(1, groupsArea1.size());
    Assert.assertTrue(groupsArea1.contains(group1));
    List<Long> groupKeysArea1 = areaManager.findBusinessGroupKeysOfAreaKeys(area1Key);
    Assert.assertNotNull(groupKeysArea1);
    Assert.assertEquals(1, groupKeysArea1.size());
    Assert.assertTrue(groupKeysArea1.contains(group1.getKey()));
    // check find area 1 and 2 -> all 3 groups
    List<Long> areaKeys = new ArrayList<>(2);
    areaKeys.add(area1.getKey());
    areaKeys.add(area2.getKey());
    List<BusinessGroup> groupsAreas = areaManager.findBusinessGroupsOfAreaKeys(areaKeys);
    Assert.assertNotNull(groupsAreas);
    Assert.assertEquals(3, groupsAreas.size());
    Assert.assertTrue(groupsAreas.contains(group1));
    Assert.assertTrue(groupsAreas.contains(group2));
    Assert.assertTrue(groupsAreas.contains(group3));
    List<Long> groupKeysAreas = areaManager.findBusinessGroupKeysOfAreaKeys(areaKeys);
    Assert.assertNotNull(groupKeysAreas);
    Assert.assertEquals(3, groupKeysAreas.size());
    Assert.assertTrue(groupKeysAreas.contains(group1.getKey()));
    Assert.assertTrue(groupKeysAreas.contains(group2.getKey()));
    Assert.assertTrue(groupKeysAreas.contains(group3.getKey()));
    // check with empty list
    List<BusinessGroup> emptyGroups = areaManager.findBusinessGroupsOfAreaKeys(Collections.<Long>emptyList());
    Assert.assertNotNull(emptyGroups);
    Assert.assertEquals(0, emptyGroups.size());
    List<Long> emptyGroupKeys = areaManager.findBusinessGroupKeysOfAreaKeys(Collections.<Long>emptyList());
    Assert.assertNotNull(emptyGroupKeys);
    Assert.assertEquals(0, emptyGroupKeys.size());
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 72 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class BGAreaManagerTest method addBGToBGArea.

@Test
public void addBGToBGArea() {
    // create a resource, an area, a group
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    String areaName = UUID.randomUUID().toString();
    BGArea area = areaManager.createAndPersistBGArea("area-" + areaName, "description:" + areaName, resource.getOlatResource());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "area-group", "area-group-desc", 0, -1, false, false, resource);
    dbInstance.commitAndCloseSession();
    // add the relation
    areaManager.addBGToBGArea(group, area);
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 73 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_8_2_0 method processArea.

private void processArea(BGAreaUpgrade area) {
    if (area.getResource() != null) {
        // already migrated
        return;
    }
    Long groupContextKey = area.getGroupContextKey();
    List<OLATResource> resources = findOLATResourcesForBGContext(groupContextKey);
    if (resources.isEmpty()) {
    // nothing to do
    } else {
        // reuse the area for the first resource
        Iterator<OLATResource> resourcesIt = resources.iterator();
        OLATResource firstResource = resourcesIt.next();
        area.setResource(firstResource);
        dbInstance.getCurrentEntityManager().merge(area);
        List<Long> firstResourcesGroupKeys = findBusinessGroupsOfResource(firstResource);
        List<BusinessGroup> originalGroupList = findBusinessGroupsOfArea(area);
        // remove the groups which aren't part of the first resource
        for (BusinessGroup group : originalGroupList) {
            if (!firstResourcesGroupKeys.contains(group.getKey())) {
                removeBGFromArea(group, area);
            }
        }
        // duplicate the areas for the next resources
        if (resourcesIt.hasNext()) {
            for (; resourcesIt.hasNext(); ) {
                OLATResource resource = resourcesIt.next();
                List<Long> resourcesGroupKeys = findBusinessGroupsOfResource(resource);
                BGArea existingArea = areaManager.findBGArea(area.getName(), resource);
                if (existingArea == null) {
                    BGArea copyArea = areaManager.createAndPersistBGArea(area.getName(), area.getDescription(), resource);
                    for (BusinessGroup group : originalGroupList) {
                        if (resourcesGroupKeys.contains(group.getKey())) {
                            areaManager.addBGToBGArea(group, copyArea);
                        }
                    }
                }
            }
        }
    }
    dbInstance.commitAndCloseSession();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) OLATResource(org.olat.resource.OLATResource)

Example 74 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class KeyAndNameConverterTest method convertAreaKeyToName.

@Test
public void convertAreaKeyToName() {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    BGArea newArea = new MockArea(567l, "Area 1");
    BGAreaReference areaRef = new BGAreaReference(newArea, null, null);
    envMapper.getAreas().add(areaRef);
    String convertedExp = convertExpressionKeyToName("inLearningArea(\"567\")", envMapper);
    Assert.assertEquals("inLearningArea(\"Area 1\")", convertedExp);
}
Also used : BGArea(org.olat.group.area.BGArea) BGAreaReference(org.olat.group.model.BGAreaReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper) Test(org.junit.Test)

Example 75 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class EnrollmentManagerSerialTest method getEnrollmentRows_withAreas.

@Test
public void getEnrollmentRows_withAreas() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("en-area-1");
    Identity participant1 = JunitTestHelper.createAndPersistIdentityAsRndUser("en-part-1");
    Identity participant2 = JunitTestHelper.createAndPersistIdentityAsRndUser("en-part-2");
    Identity participant3 = JunitTestHelper.createAndPersistIdentityAsRndUser("en-part-3");
    Identity participant4 = JunitTestHelper.createAndPersistIdentityAsRndUser("en-part-4");
    Identity participant5 = JunitTestHelper.createAndPersistIdentityAsRndUser("en-part-5");
    Identity waiter1 = JunitTestHelper.createAndPersistIdentityAsRndUser("en-wait-3");
    Identity waiter2 = JunitTestHelper.createAndPersistIdentityAsRndUser("en-wait-4");
    Identity waiter3 = JunitTestHelper.createAndPersistIdentityAsRndUser("en-wait-5");
    // create a resource, an area, a group
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    String areaName = UUID.randomUUID().toString();
    BGArea area = areaManager.createAndPersistBGArea("en-area-" + areaName, "description:" + areaName, resource.getOlatResource());
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "en-area-group", "area-group-desc", 0, 10, false, false, resource);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "en-group-2", "area-group-desc", 0, 10, true, false, resource);
    BusinessGroup group3 = businessGroupService.createBusinessGroup(null, "en-group-3", "area-group-desc", 0, 10, true, false, resource);
    businessGroupRelationDao.addRole(participant1, group1, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(participant2, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(participant3, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(participant4, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(participant5, group2, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(waiter1, group2, GroupRoles.waiting.name());
    businessGroupRelationDao.addRole(waiter2, group2, GroupRoles.waiting.name());
    businessGroupRelationDao.addRole(waiter3, group2, GroupRoles.waiting.name());
    areaManager.addBGToBGArea(group1, area);
    areaManager.addBGToBGArea(group2, area);
    dbInstance.commitAndCloseSession();
    List<Long> groupKeys = new ArrayList<>();
    groupKeys.add(group2.getKey());
    groupKeys.add(group3.getKey());
    List<Long> areaKeys = new ArrayList<>();
    areaKeys.add(area.getKey());
    // check id enrollments
    List<EnrollmentRow> idEnrollments = enrollmentManager.getEnrollments(id, groupKeys, areaKeys, 128);
    Assert.assertNotNull(idEnrollments);
    Assert.assertEquals(3, idEnrollments.size());
    // check enrollment group 1
    EnrollmentRow enrollment1 = getEnrollmentRowFor(group1, idEnrollments);
    Assert.assertEquals(group1.getKey(), enrollment1.getKey());
    Assert.assertEquals(group1.getName(), enrollment1.getName());
    Assert.assertEquals(1, enrollment1.getNumOfParticipants());
    Assert.assertEquals(0, enrollment1.getNumInWaitingList());
    Assert.assertFalse(enrollment1.isParticipant());
    Assert.assertFalse(enrollment1.isWaiting());
    // check enrollment group 2
    EnrollmentRow enrollment2 = getEnrollmentRowFor(group2, idEnrollments);
    Assert.assertEquals(group2.getKey(), enrollment2.getKey());
    Assert.assertEquals(group2.getName(), enrollment2.getName());
    Assert.assertEquals(4, enrollment2.getNumOfParticipants());
    Assert.assertEquals(3, enrollment2.getNumInWaitingList());
    Assert.assertFalse(enrollment2.isParticipant());
    Assert.assertFalse(enrollment2.isWaiting());
    // check enrollment group 3
    EnrollmentRow enrollment3 = getEnrollmentRowFor(group3, idEnrollments);
    Assert.assertEquals(group3.getKey(), enrollment3.getKey());
    Assert.assertEquals(group3.getName(), enrollment3.getName());
    Assert.assertEquals(0, enrollment3.getNumOfParticipants());
    Assert.assertEquals(0, enrollment3.getNumInWaitingList());
    Assert.assertFalse(enrollment3.isParticipant());
    Assert.assertFalse(enrollment3.isWaiting());
    // check enrollments of participant5
    List<EnrollmentRow> part5Enrollments = enrollmentManager.getEnrollments(participant5, groupKeys, areaKeys, 128);
    Assert.assertNotNull(part5Enrollments);
    Assert.assertEquals(3, part5Enrollments.size());
    EnrollmentRow enrollment2_w5 = getEnrollmentRowFor(group2, part5Enrollments);
    Assert.assertEquals(group2.getKey(), enrollment2_w5.getKey());
    Assert.assertEquals(group2.getName(), enrollment2_w5.getName());
    Assert.assertEquals(4, enrollment2_w5.getNumOfParticipants());
    Assert.assertEquals(3, enrollment2_w5.getNumInWaitingList());
    Assert.assertTrue(enrollment2_w5.isParticipant());
    Assert.assertFalse(enrollment2_w5.isWaiting());
    // check enrollments of waiter 3
    List<EnrollmentRow> wait3Enrollments = enrollmentManager.getEnrollments(waiter3, groupKeys, areaKeys, 128);
    Assert.assertNotNull(wait3Enrollments);
    Assert.assertEquals(3, wait3Enrollments.size());
    EnrollmentRow enrollment2_p3 = getEnrollmentRowFor(group2, wait3Enrollments);
    Assert.assertEquals(group2.getKey(), enrollment2_p3.getKey());
    Assert.assertEquals(group2.getName(), enrollment2_p3.getName());
    Assert.assertEquals(4, enrollment2_p3.getNumOfParticipants());
    Assert.assertEquals(3, enrollment2_p3.getNumInWaitingList());
    Assert.assertFalse(enrollment2_p3.isParticipant());
    Assert.assertTrue(enrollment2_p3.isWaiting());
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

BGArea (org.olat.group.area.BGArea)124 BusinessGroup (org.olat.group.BusinessGroup)70 Test (org.junit.Test)68 RepositoryEntry (org.olat.repository.RepositoryEntry)52 ArrayList (java.util.ArrayList)22 Identity (org.olat.core.id.Identity)22 BGAreaReference (org.olat.group.model.BGAreaReference)18 AssessmentModeToArea (org.olat.course.assessment.AssessmentModeToArea)16 CourseEnvironmentMapper (org.olat.course.export.CourseEnvironmentMapper)16 HashSet (java.util.HashSet)14 AssessmentMode (org.olat.course.assessment.AssessmentMode)12 BusinessGroupReference (org.olat.group.model.BusinessGroupReference)12 OLATResource (org.olat.resource.OLATResource)12 AssessmentModeToGroup (org.olat.course.assessment.AssessmentModeToGroup)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 CollaborationTools (org.olat.collaboration.CollaborationTools)6 BusinessGroupShort (org.olat.group.BusinessGroupShort)6 File (java.io.File)4 IOException (java.io.IOException)4 Field (java.lang.reflect.Field)4