Search in sources :

Example 46 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class BusinessGroupImportExport method importGroups.

public BusinessGroupEnvironment importGroups(RepositoryEntry re, File fGroupExportXML) {
    if (!fGroupExportXML.exists())
        return new BusinessGroupEnvironment();
    // start with a new connection
    dbInstance.commitAndCloseSession();
    OLATGroupExport groupConfig = null;
    try {
        groupConfig = xstream.fromXML(fGroupExportXML);
    } catch (Exception ce) {
        throw new OLATRuntimeException("Error importing group config.", ce);
    }
    if (groupConfig == null) {
        throw new AssertException("Invalid group export file. Root does not match.");
    }
    BusinessGroupEnvironment env = new BusinessGroupEnvironment();
    Set<BGArea> areaSet = new HashSet<BGArea>();
    // get areas
    int dbCount = 0;
    if (groupConfig.getAreas() != null && groupConfig.getAreas().getGroups() != null) {
        for (Area area : groupConfig.getAreas().getGroups()) {
            String areaName = area.name;
            String areaDesc = (area.description != null && !area.description.isEmpty()) ? area.description.get(0) : "";
            BGArea newArea = areaManager.createAndPersistBGArea(areaName, areaDesc, re.getOlatResource());
            if (areaSet.add(newArea)) {
                env.getAreas().add(new BGAreaReference(newArea, area.key, area.name));
            }
            if (dbCount++ % 25 == 0) {
                dbInstance.commitAndCloseSession();
            }
        }
    }
    // get groups
    if (groupConfig.getGroups() != null && groupConfig.getGroups().getGroups() != null) {
        for (Group group : groupConfig.getGroups().getGroups()) {
            // create group
            String groupName = group.name;
            String groupDesc = (group.description != null && !group.description.isEmpty()) ? group.description.get(0) : "";
            // get min/max participants
            int groupMinParticipants = group.minParticipants == null ? -1 : group.minParticipants.intValue();
            int groupMaxParticipants = group.maxParticipants == null ? -1 : group.maxParticipants.intValue();
            // waiting list configuration
            boolean waitingList = false;
            if (group.waitingList != null) {
                waitingList = group.waitingList.booleanValue();
            }
            boolean enableAutoCloseRanks = false;
            if (group.autoCloseRanks != null) {
                enableAutoCloseRanks = group.autoCloseRanks.booleanValue();
            }
            // get properties
            boolean showOwners = true;
            boolean showParticipants = true;
            boolean showWaitingList = true;
            if (group.showOwners != null) {
                showOwners = group.showOwners;
            }
            if (group.showParticipants != null) {
                showParticipants = group.showParticipants;
            }
            if (group.showWaitingList != null) {
                showWaitingList = group.showWaitingList;
            }
            BusinessGroup newGroup = businessGroupService.createBusinessGroup(null, groupName, groupDesc, groupMinParticipants, groupMaxParticipants, waitingList, enableAutoCloseRanks, re);
            // map the group
            env.getGroups().add(new BusinessGroupReference(newGroup, group.key, group.name));
            // get tools config
            String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
            CollabTools toolsConfig = group.tools;
            CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(newGroup);
            for (int i = 0; i < availableTools.length; i++) {
                try {
                    Field field = toolsConfig.getClass().getField(availableTools[i]);
                    Boolean val = field.getBoolean(toolsConfig);
                    if (val != null) {
                        ct.setToolEnabled(availableTools[i], val);
                    }
                } catch (NoSuchFieldException e) {
                // hasOpenMeetings compatibility
                } catch (Exception e) {
                    log.error("", e);
                }
            }
            if (group.calendarAccess != null) {
                Long calendarAccess = group.calendarAccess;
                ct.saveCalendarAccess(calendarAccess);
            }
            if (group.folderAccess != null) {
                ct.saveFolderAccess(group.folderAccess);
            }
            if (group.info != null) {
                ct.saveNews(group.info);
            }
            // get memberships
            List<String> memberships = group.areaRelations;
            if (memberships != null && memberships.size() > 0) {
                Set<String> uniqueMemberships = new HashSet<>(memberships);
                for (String membership : uniqueMemberships) {
                    BGArea area = areaManager.findBGArea(membership, re.getOlatResource());
                    if (area != null) {
                        areaManager.addBGToBGArea(newGroup, area);
                    } else {
                        log.error("Area not found", null);
                    }
                }
            }
            boolean download = groupModule.isUserListDownloadDefaultAllowed();
            newGroup = businessGroupService.updateDisplayMembers(newGroup, showOwners, showParticipants, showWaitingList, false, false, false, download);
            if (dbCount++ % 3 == 0) {
                dbInstance.commitAndCloseSession();
            }
        }
    }
    dbInstance.commitAndCloseSession();
    return env;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Field(java.lang.reflect.Field) BGArea(org.olat.group.area.BGArea) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) HashSet(java.util.HashSet) BusinessGroupEnvironment(org.olat.group.model.BusinessGroupEnvironment) AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) BGAreaReference(org.olat.group.model.BGAreaReference) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) BGArea(org.olat.group.area.BGArea) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) CollaborationTools(org.olat.collaboration.CollaborationTools)

Example 47 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class BusinessGroupServiceImpl method copyBusinessGroup.

@Override
public BusinessGroup copyBusinessGroup(Identity identity, BusinessGroup sourceBusinessGroup, String targetName, String targetDescription, Integer targetMin, Integer targetMax, boolean copyAreas, boolean copyCollabToolConfig, boolean copyRights, boolean copyOwners, boolean copyParticipants, boolean copyMemberVisibility, boolean copyWaitingList, boolean copyRelations) {
    // 1. create group, set waitingListEnabled, enableAutoCloseRanks like source business-group
    BusinessGroup newGroup = createBusinessGroup(null, targetName, targetDescription, targetMin, targetMax, sourceBusinessGroup.getWaitingListEnabled(), sourceBusinessGroup.getAutoCloseRanksEnabled(), null);
    // return immediately with null value to indicate an already take groupname
    if (newGroup == null) {
        return null;
    }
    // 2. copy tools
    if (copyCollabToolConfig) {
        CollaborationToolsFactory toolsF = CollaborationToolsFactory.getInstance();
        // get collab tools from original group and the new group
        CollaborationTools oldTools = toolsF.getOrCreateCollaborationTools(sourceBusinessGroup);
        CollaborationTools newTools = toolsF.getOrCreateCollaborationTools(newGroup);
        // copy the collab tools settings
        String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
        for (int i = 0; i < availableTools.length; i++) {
            String tool = availableTools[i];
            newTools.setToolEnabled(tool, oldTools.isToolEnabled(tool));
        }
        String oldNews = oldTools.lookupNews();
        newTools.saveNews(oldNews);
    }
    // 3. copy member visibility
    if (copyMemberVisibility) {
        newGroup.setOwnersVisibleIntern(sourceBusinessGroup.isOwnersVisibleIntern());
        newGroup.setOwnersVisiblePublic(sourceBusinessGroup.isOwnersVisiblePublic());
        newGroup.setParticipantsVisibleIntern(sourceBusinessGroup.isParticipantsVisibleIntern());
        newGroup.setParticipantsVisiblePublic(sourceBusinessGroup.isParticipantsVisiblePublic());
        newGroup.setWaitingListVisibleIntern(sourceBusinessGroup.isWaitingListVisibleIntern());
        newGroup.setWaitingListVisiblePublic(sourceBusinessGroup.isWaitingListVisiblePublic());
        newGroup.setDownloadMembersLists(sourceBusinessGroup.isDownloadMembersLists());
    }
    // 4. copy areas
    if (copyAreas) {
        List<BGArea> areas = areaManager.findBGAreasOfBusinessGroup(sourceBusinessGroup);
        for (BGArea area : areas) {
            // reference target group to source groups areas
            areaManager.addBGToBGArea(newGroup, area);
        }
    }
    // 5. copy owners
    if (copyOwners) {
        List<Identity> owners = businessGroupRelationDAO.getMembers(sourceBusinessGroup, GroupRoles.coach.name());
        if (owners.isEmpty()) {
            businessGroupRelationDAO.addRole(identity, newGroup, GroupRoles.coach.name());
        } else {
            for (Identity owner : owners) {
                businessGroupRelationDAO.addRole(owner, newGroup, GroupRoles.coach.name());
            }
        }
    } else {
        businessGroupRelationDAO.addRole(identity, newGroup, GroupRoles.coach.name());
    }
    // 6. copy participants
    if (copyParticipants) {
        List<Identity> participants = businessGroupRelationDAO.getMembers(sourceBusinessGroup, GroupRoles.participant.name());
        for (Identity participant : participants) {
            businessGroupRelationDAO.addRole(participant, newGroup, GroupRoles.participant.name());
        }
    }
    // 7. copy rights
    if (copyRights) {
        List<String> participantRights = rightManager.findBGRights(sourceBusinessGroup, BGRightsRole.participant);
        for (String sourceRight : participantRights) {
            rightManager.addBGRight(sourceRight, newGroup, BGRightsRole.participant);
        }
        List<String> tutorRights = rightManager.findBGRights(sourceBusinessGroup, BGRightsRole.tutor);
        for (String sourceRight : tutorRights) {
            rightManager.addBGRight(sourceRight, newGroup, BGRightsRole.tutor);
        }
    }
    // 8. copy waiting-lisz
    if (copyWaitingList) {
        List<Identity> waitingList = getMembers(sourceBusinessGroup, GroupRoles.waiting.name());
        for (Identity waiting : waitingList) {
            businessGroupRelationDAO.addRole(waiting, newGroup, GroupRoles.waiting.name());
        }
    }
    // 9. copy relations
    if (copyRelations) {
        List<RepositoryEntry> resources = businessGroupRelationDAO.findRepositoryEntries(Collections.singletonList(sourceBusinessGroup), 0, -1);
        addResourcesTo(Collections.singletonList(newGroup), resources);
    }
    return newGroup;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) BGArea(org.olat.group.area.BGArea) CollaborationTools(org.olat.collaboration.CollaborationTools) Identity(org.olat.core.id.Identity) CollaborationToolsFactory(org.olat.collaboration.CollaborationToolsFactory)

Example 48 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class AssessmentModeManagerTest method loadAssessmentMode_identityInArea_coach.

/**
 * Check an assessment linked to an area with one participant
 */
@Test
public void loadAssessmentMode_identityInArea_coach() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-12");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-13");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-14");
    BusinessGroup businessGroup = businessGroupService.createBusinessGroup(null, "as-mode-3", "", null, null, null, null, false, false, entry);
    businessGroupRelationDao.addRole(participant, businessGroup, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(coach, businessGroup, GroupRoles.coach.name());
    BGArea area = areaMgr.createAndPersistBGArea("area for people", "", entry.getOlatResource());
    areaMgr.addBGToBGArea(businessGroup, area);
    AssessmentMode mode = createMinimalAssessmentmode(entry);
    mode.setTargetAudience(AssessmentMode.Target.courseAndGroups);
    mode.setApplySettingsForCoach(true);
    mode = assessmentModeMgr.persist(mode);
    AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(mode, area);
    mode.getAreas().add(modeToArea);
    mode = assessmentModeMgr.merge(mode, true);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(mode);
    // check participant
    List<AssessmentMode> currentModes = assessmentModeMgr.getAssessmentModeFor(participant);
    Assert.assertNotNull(currentModes);
    Assert.assertEquals(1, currentModes.size());
    Assert.assertTrue(currentModes.contains(mode));
    // check coach
    List<AssessmentMode> currentCoachModes = assessmentModeMgr.getAssessmentModeFor(coach);
    Assert.assertNotNull(currentCoachModes);
    Assert.assertEquals(1, currentCoachModes.size());
    Assert.assertTrue(currentCoachModes.contains(mode));
    // check author
    List<AssessmentMode> currentAuthorModes = assessmentModeMgr.getAssessmentModeFor(author);
    Assert.assertNotNull(currentAuthorModes);
    Assert.assertTrue(currentAuthorModes.isEmpty());
}
Also used : AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) AssessmentMode(org.olat.course.assessment.AssessmentMode) BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 49 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class AssessmentModeManagerTest method loadAssessmentMode_identityInArea.

/**
 * Check an assessment linked to an area with one participant
 */
@Test
public void loadAssessmentMode_identityInArea() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-12");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
    Identity participant = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-13");
    Identity coach = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-14");
    BusinessGroup businessGroup = businessGroupService.createBusinessGroup(author, "as-mode-3", "", null, null, null, null, false, false, entry);
    businessGroupRelationDao.addRole(participant, businessGroup, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(coach, businessGroup, GroupRoles.coach.name());
    BGArea area = areaMgr.createAndPersistBGArea("area for people", "", entry.getOlatResource());
    areaMgr.addBGToBGArea(businessGroup, area);
    AssessmentMode mode = createMinimalAssessmentmode(entry);
    mode.setTargetAudience(AssessmentMode.Target.courseAndGroups);
    mode.setApplySettingsForCoach(false);
    mode = assessmentModeMgr.persist(mode);
    AssessmentModeToGroup modeToGroup = assessmentModeMgr.createAssessmentModeToGroup(mode, businessGroup);
    mode.getGroups().add(modeToGroup);
    mode = assessmentModeMgr.merge(mode, true);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(mode);
    // check participant
    List<AssessmentMode> currentModes = assessmentModeMgr.getAssessmentModeFor(participant);
    Assert.assertNotNull(currentModes);
    Assert.assertEquals(1, currentModes.size());
    Assert.assertTrue(currentModes.contains(mode));
    // check coach
    List<AssessmentMode> currentCoachModes = assessmentModeMgr.getAssessmentModeFor(coach);
    Assert.assertNotNull(currentCoachModes);
    Assert.assertTrue(currentCoachModes.isEmpty());
    // check author
    List<AssessmentMode> currentAuthorModes = assessmentModeMgr.getAssessmentModeFor(author);
    Assert.assertNotNull(currentAuthorModes);
    Assert.assertTrue(currentAuthorModes.isEmpty());
}
Also used : AssessmentMode(org.olat.course.assessment.AssessmentMode) BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) AssessmentModeToGroup(org.olat.course.assessment.AssessmentModeToGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 50 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class AssessmentModeManagerTest method createAssessmentModeToArea.

@Test
public void createAssessmentModeToArea() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("as-mode-1");
    RepositoryEntry entry = JunitTestHelper.deployBasicCourse(author);
    BusinessGroup businessGroup = businessGroupService.createBusinessGroup(author, "as_mode_1", "", null, null, null, null, false, false, null);
    BGArea area = areaMgr.createAndPersistBGArea("little area", "My little secret area", entry.getOlatResource());
    areaMgr.addBGToBGArea(businessGroup, area);
    AssessmentMode mode = createMinimalAssessmentmode(entry);
    mode = assessmentModeMgr.persist(mode);
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(mode);
    AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(mode, area);
    mode.getAreas().add(modeToArea);
    AssessmentMode savedMode = assessmentModeMgr.merge(mode, true);
    dbInstance.commitAndCloseSession();
    AssessmentMode reloadedMode = assessmentModeMgr.getAssessmentModeById(mode.getKey());
    Assert.assertEquals(mode, reloadedMode);
    Assert.assertEquals(savedMode, reloadedMode);
    Assert.assertNotNull(reloadedMode.getAreas());
    Assert.assertEquals(1, reloadedMode.getAreas().size());
    Assert.assertEquals(modeToArea, reloadedMode.getAreas().iterator().next());
    dbInstance.commitAndCloseSession();
}
Also used : AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) AssessmentMode(org.olat.course.assessment.AssessmentMode) BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) 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