Search in sources :

Example 26 with BGArea

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

the class ENEditGroupAreaFormController method getAreaKeysAndNames.

private KeysAndNames getAreaKeysAndNames(List<Long> keys) {
    StringBuilder sb = new StringBuilder();
    List<BGArea> areas = areaManager.loadAreas(keys);
    KeysAndNames keysAndNames = new KeysAndNames();
    keysAndNames.getKeys().addAll(keys);
    for (BGArea area : areas) {
        if (sb.length() > 0)
            sb.append("&nbsp;&nbsp;");
        sb.append("<i class='o_icon o_icon-fw o_icon_courseareas'>&nbsp;</i> ");
        sb.append(StringHelper.escapeHtml(area.getName()));
        keysAndNames.getNames().add(area.getName());
    }
    keysAndNames.setDecoratedNames(sb.toString());
    return keysAndNames;
}
Also used : BGArea(org.olat.group.area.BGArea)

Example 27 with BGArea

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

the class OLATUpgrade_8_2_0 method getCourseEnvironmentMapper.

private CourseEnvironmentMapper getCourseEnvironmentMapper(RepositoryEntry courseResource) {
    CourseEnvironmentMapper envMapper = new CourseEnvironmentMapper();
    List<BusinessGroup> groups = businessGroupService.findBusinessGroups(null, courseResource, 0, -1);
    for (BusinessGroup group : groups) {
        envMapper.getGroups().add(new BusinessGroupReference(group));
    }
    List<BGArea> areas = areaManager.findBGAreasInContext(courseResource.getOlatResource());
    for (BGArea area : areas) {
        envMapper.getAreas().add(new BGAreaReference(area));
    }
    return envMapper;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) BGArea(org.olat.group.area.BGArea) BGAreaReference(org.olat.group.model.BGAreaReference) CourseEnvironmentMapper(org.olat.course.export.CourseEnvironmentMapper)

Example 28 with BGArea

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

the class NewAreaController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == this.areaCreateController) {
        if (event == Event.DONE_EVENT) {
            String areaDesc = this.areaCreateController.getAreaDescription();
            Set<String> allNames = new HashSet<String>();
            if (this.bulkMode) {
                allNames = this.areaCreateController.getGroupNames();
            } else {
                allNames.add(this.areaCreateController.getAreaName());
            }
            // create bulkgroups only if there is no name which already exists.
            newAreas = new HashSet<BGArea>();
            newAreaNames = new HashSet<String>();
            for (String areaName : allNames) {
                BGArea newArea = areaManager.createAndPersistBGArea(areaName, areaDesc, resource);
                newAreas.add(newArea);
                newAreaNames.add(areaName);
            }
            // do loggin if ual given
            for (BGArea area : newAreas) {
                ThreadLocalUserActivityLogger.log(GroupLoggingAction.AREA_CREATED, getClass(), LoggingResourceable.wrap(area));
            }
            // workflow successfully finished
            // so far no events on the systembus to inform about new groups in BGContext
            fireEvent(ureq, Event.DONE_EVENT);
        } else if (event == Event.CANCELLED_EVENT) {
            // workflow cancelled
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    }
}
Also used : BGArea(org.olat.group.area.BGArea) HashSet(java.util.HashSet)

Example 29 with BGArea

use of org.olat.group.area.BGArea 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 30 with BGArea

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

the class BusinessGroupImportExport method exportGroup.

private Group exportGroup(File fExportFile, BusinessGroup group, String groupName, boolean runtimeDatas, boolean backwardsCompatible) {
    Group newGroup = new Group();
    newGroup.key = backwardsCompatible ? null : group.getKey();
    newGroup.name = StringHelper.containsNonWhitespace(groupName) ? groupName : group.getName();
    if (group.getMinParticipants() != null) {
        newGroup.minParticipants = group.getMinParticipants();
    }
    if (group.getMaxParticipants() != null) {
        newGroup.maxParticipants = group.getMaxParticipants();
    }
    if (group.getWaitingListEnabled() != null) {
        newGroup.waitingList = group.getWaitingListEnabled();
    }
    if (group.getAutoCloseRanksEnabled() != null) {
        newGroup.autoCloseRanks = group.getAutoCloseRanksEnabled();
    }
    if (StringHelper.containsNonWhitespace(group.getDescription())) {
        newGroup.description = Collections.singletonList(group.getDescription());
    }
    // collab tools
    String[] availableTools = CollaborationToolsFactory.getInstance().getAvailableTools().clone();
    CollabTools toolsConfig = new CollabTools();
    CollaborationTools ct = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
    for (int i = 0; i < availableTools.length; i++) {
        try {
            Field field = toolsConfig.getClass().getField(availableTools[i]);
            field.setBoolean(toolsConfig, ct.isToolEnabled(availableTools[i]));
        } catch (NoSuchFieldException e) {
        // no field to fill (hasOpenMeetings is not set for backwards compatibility)
        } catch (Exception e) {
            log.error("", e);
        }
    }
    newGroup.tools = toolsConfig;
    Long calendarAccess = ct.lookupCalendarAccess();
    if (calendarAccess != null) {
        newGroup.calendarAccess = calendarAccess;
    }
    // fxdiff VCRP-8: collaboration tools folder access control
    Long folderAccess = ct.lookupFolderAccess();
    if (folderAccess != null) {
        newGroup.folderAccess = folderAccess;
    }
    String info = ct.lookupNews();
    if (info != null && !info.trim().equals("")) {
        newGroup.info = info.trim();
    }
    log.debug("fExportFile.getParent()=" + fExportFile.getParent());
    if (runtimeDatas) {
        ct.archive(fExportFile.getParent());
    }
    // export membership
    List<BGArea> bgAreas = areaManager.findBGAreasOfBusinessGroup(group);
    newGroup.areaRelations = new ArrayList<String>();
    for (BGArea areaRelation : bgAreas) {
        newGroup.areaRelations.add(areaRelation.getName());
    }
    // export properties
    boolean showOwners = group.isOwnersVisibleIntern();
    boolean showParticipants = group.isParticipantsVisibleIntern();
    boolean showWaitingList = group.isWaitingListVisibleIntern();
    newGroup.showOwners = showOwners;
    newGroup.showParticipants = showParticipants;
    newGroup.showWaitingList = showWaitingList;
    return newGroup;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) Field(java.lang.reflect.Field) BGArea(org.olat.group.area.BGArea) CollaborationTools(org.olat.collaboration.CollaborationTools)

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