Search in sources :

Example 1 with BusinessGroupEnvironment

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

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 2 with BusinessGroupEnvironment

use of org.olat.group.model.BusinessGroupEnvironment 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 3 with BusinessGroupEnvironment

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

the class PersistingCourseGroupManager method importCourseBusinessGroups.

/**
 * @see org.olat.course.groupsandrights.CourseGroupManager#importCourseBusinessGroups(java.io.File)
 */
@Override
public CourseEnvironmentMapper importCourseBusinessGroups(File fImportDirectory) {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    OLATResource resource = getCourseResource();
    RepositoryEntry courseRe = RepositoryManager.getInstance().lookupRepositoryEntry(resource, true);
    File fGroupXML1 = new File(fImportDirectory, LEARNINGGROUPEXPORT_XML);
    if (fGroupXML1.exists()) {
        BusinessGroupEnvironment env = businessGroupService.importGroups(courseRe, fGroupXML1);
        envMapper.addBusinessGroupEnvironment(env);
    }
    File fGroupXML2 = new File(fImportDirectory, RIGHTGROUPEXPORT_XML);
    if (fGroupXML2.exists()) {
        BusinessGroupEnvironment env = businessGroupService.importGroups(courseRe, fGroupXML2);
        envMapper.addBusinessGroupEnvironment(env);
    }
    return envMapper;
}
Also used : BusinessGroupEnvironment(org.olat.group.model.BusinessGroupEnvironment) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Example 4 with BusinessGroupEnvironment

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

the class PersistingCourseGroupManager method exportCourseBusinessGroups.

/**
 * @see org.olat.course.groupsandrights.CourseGroupManager#exportCourseBusinessGroups(java.io.File)
 */
@Override
public void exportCourseBusinessGroups(File fExportDirectory, CourseEnvironmentMapper courseEnv, boolean runtimeDatas, boolean backwardsCompatible) {
    File fExportFile = new File(fExportDirectory, LEARNINGGROUPEXPORT_XML);
    List<BGArea> areas = getAllAreas();
    List<BusinessGroup> groups = getAllBusinessGroups();
    BusinessGroupEnvironment bgEnv = new BusinessGroupEnvironment();
    bgEnv.getGroups().addAll(courseEnv.getGroups());
    bgEnv.getAreas().addAll(courseEnv.getAreas());
    businessGroupService.exportGroups(groups, areas, fExportFile, bgEnv, runtimeDatas, backwardsCompatible);
}
Also used : BusinessGroupEnvironment(org.olat.group.model.BusinessGroupEnvironment) BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) File(java.io.File)

Example 5 with BusinessGroupEnvironment

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

the class PersistingCourseGroupManager method importCourseBusinessGroups.

/**
 * @see org.olat.course.groupsandrights.CourseGroupManager#importCourseBusinessGroups(java.io.File)
 */
@Override
public CourseEnvironmentMapper importCourseBusinessGroups(File fImportDirectory) {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    OLATResource resource = getCourseResource();
    RepositoryEntry courseRe = RepositoryManager.getInstance().lookupRepositoryEntry(resource, true);
    File fGroupXML1 = new File(fImportDirectory, LEARNINGGROUPEXPORT_XML);
    if (fGroupXML1.exists()) {
        BusinessGroupEnvironment env = businessGroupService.importGroups(courseRe, fGroupXML1);
        envMapper.addBusinessGroupEnvironment(env);
    }
    File fGroupXML2 = new File(fImportDirectory, RIGHTGROUPEXPORT_XML);
    if (fGroupXML2.exists()) {
        BusinessGroupEnvironment env = businessGroupService.importGroups(courseRe, fGroupXML2);
        envMapper.addBusinessGroupEnvironment(env);
    }
    return envMapper;
}
Also used : BusinessGroupEnvironment(org.olat.group.model.BusinessGroupEnvironment) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Aggregations

BusinessGroupEnvironment (org.olat.group.model.BusinessGroupEnvironment)6 File (java.io.File)4 BusinessGroup (org.olat.group.BusinessGroup)4 BGArea (org.olat.group.area.BGArea)4 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 HashSet (java.util.HashSet)2 CollaborationTools (org.olat.collaboration.CollaborationTools)2 AssertException (org.olat.core.logging.AssertException)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 CourseEnvironmentMapper (org.olat.course.export.CourseEnvironmentMapper)2 BGAreaReference (org.olat.group.model.BGAreaReference)2 BusinessGroupReference (org.olat.group.model.BusinessGroupReference)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 OLATResource (org.olat.resource.OLATResource)2