Search in sources :

Example 16 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort in project openolat by klemens.

the class AbstractBusinessGroupListController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (createButton == source) {
        doCreate(ureq, getWindowControl(), null);
    } else if (deleteButton == source) {
        confirmDelete(ureq, getSelectedItems());
    } else if (duplicateButton == source) {
        doCopy(ureq, getSelectedItems());
    } else if (configButton == source) {
        doConfiguration(ureq, getSelectedItems());
    } else if (emailButton == source) {
        doEmails(ureq, getSelectedItems());
    } else if (usersButton == source) {
        doUserManagement(ureq, getSelectedItems());
    } else if (mergeButton == source) {
        doMerge(ureq, getSelectedItems());
    } else if (selectButton == source) {
        doSelect(ureq, getSelectedItems());
    } else if (source instanceof FormLink) {
        FormLink link = (FormLink) source;
        String cmd = link.getCmd();
        if ("mark".equals(cmd)) {
            BusinessGroupRow row = (BusinessGroupRow) link.getUserObject();
            boolean marked = toogleMark(row);
            link.setIconLeftCSS(marked ? "o_icon o_icon_bookmark o_icon-lg" : "o_icon o_icon_bookmark_add o_icon-lg");
            link.getComponent().setDirty(true);
        } else if ("allresources".equals(cmd)) {
            BusinessGroupShort bg = (BusinessGroupShort) link.getUserObject();
            NewControllerFactory.getInstance().launch("[BusinessGroup:" + bg.getKey() + "][toolresources:0]", ureq, getWindowControl());
        } else if ("resource".equals(cmd)) {
            RepositoryEntryShort re = (RepositoryEntryShort) link.getUserObject();
            NewControllerFactory.getInstance().launch("[RepositoryEntry:" + re.getKey() + "]", ureq, getWindowControl());
        } else if (link.getUserObject() instanceof BusinessGroupRef) {
            BusinessGroupRef item = (BusinessGroupRef) link.getUserObject();
            Long businessGroupKey = item.getKey();
            BusinessGroup businessGroup = businessGroupService.loadBusinessGroup(businessGroupKey);
            if (businessGroup == null) {
                groupTableModel.removeBusinessGroup(businessGroupKey);
                tableEl.reset();
            } else if (TABLE_ACTION_ACCESS.equals(cmd)) {
                doAccess(ureq, businessGroup);
            } else if (TABLE_ACTION_LEAVE.equals(cmd)) {
                doConfirmLeaving(ureq, businessGroup);
            }
        }
    } else if (source == tableEl) {
        String cmd = event.getCommand();
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            if (se.getIndex() >= 0 && se.getIndex() < groupTableModel.getRowCount()) {
                BusinessGroupRef item = groupTableModel.getObject(se.getIndex());
                Long businessGroupKey = item.getKey();
                BusinessGroup businessGroup = businessGroupService.loadBusinessGroup(businessGroupKey);
                // prevent rs after a group is deleted by someone else
                if (businessGroup == null) {
                    groupTableModel.removeBusinessGroup(businessGroupKey);
                    tableEl.reset();
                } else if (TABLE_ACTION_LAUNCH.equals(cmd)) {
                    doLaunch(ureq, businessGroup);
                } else if (TABLE_ACTION_DELETE.equals(cmd)) {
                    confirmDelete(ureq, Collections.singletonList(item));
                } else if (TABLE_ACTION_LAUNCH.equals(cmd)) {
                    doLaunch(ureq, businessGroup);
                } else if (TABLE_ACTION_EDIT.equals(cmd)) {
                    doEdit(ureq, businessGroup);
                } else if (TABLE_ACTION_LEAVE.equals(cmd)) {
                    doConfirmLeaving(ureq, businessGroup);
                } else if (TABLE_ACTION_ACCESS.equals(cmd)) {
                    doAccess(ureq, businessGroup);
                } else if (TABLE_ACTION_SELECT.equals(cmd)) {
                    doSelect(ureq, businessGroup);
                }
            }
        } else if (event instanceof FlexiTableSearchEvent) {
            doSearch((FlexiTableSearchEvent) event);
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : BusinessGroupRef(org.olat.group.BusinessGroupRef) RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) BGCopyBusinessGroup(org.olat.group.ui.wizard.BGCopyBusinessGroup) BGConfigBusinessGroup(org.olat.group.ui.wizard.BGConfigBusinessGroup) BusinessGroup(org.olat.group.BusinessGroup) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) BusinessGroupSelectionEvent(org.olat.group.model.BusinessGroupSelectionEvent) FlexiTableSearchEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) BusinessGroupShort(org.olat.group.BusinessGroupShort) BusinessGroupRow(org.olat.group.model.BusinessGroupRow)

Example 17 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort in project openolat by klemens.

the class GroupMemberViewComparator method compare.

@Override
public int compare(MemberView m1, MemberView m2) {
    List<BusinessGroupShort> g1 = m1.getGroups();
    List<BusinessGroupShort> g2 = m2.getGroups();
    if (g1 == null || g1.isEmpty()) {
        if (g2 == null || g2.isEmpty())
            return 0;
        return -1;
    }
    if (g2 == null || g2.isEmpty())
        return 1;
    int maxLevel = Math.max(g1.size(), g2.size());
    int compare = 0;
    for (int i = 0; i < maxLevel && compare == 0; i++) {
        BusinessGroupShort gs1 = i < g1.size() ? g1.get(i) : null;
        BusinessGroupShort gs2 = i < g2.size() ? g2.get(i) : null;
        compare = compareLevel(gs1, gs2);
    }
    return compare;
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 18 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort in project openolat by klemens.

the class COCourseNode method isConfigValid.

/**
 * @see org.olat.course.nodes.CourseNode#isConfigValid(org.olat.course.run.userview.UserCourseEnvironment)
 */
public StatusDescription[] isConfigValid(CourseEditorEnv cev) {
    oneClickStatusCache = null;
    // only here we know which translator to take for translating condition
    // error messages
    String translatorStr = Util.getPackageName(ConditionEditController.class);
    List<StatusDescription> condErrs = isConfigValidWithTranslator(cev, translatorStr, getConditionExpressions());
    List<StatusDescription> missingNames = new ArrayList<StatusDescription>();
    /*
         * check group and area names for existence
         */
    String nodeId = getIdent();
    ModuleConfiguration mc = getModuleConfiguration();
    @SuppressWarnings("unchecked") List<Long> areaKeys = (List<Long>) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA_IDS);
    if (areaKeys != null) {
        BGAreaManager areaManager = CoreSpringFactory.getImpl(BGAreaManager.class);
        List<BGArea> areas = areaManager.loadAreas(areaKeys);
        a_a: for (Long areaKey : areaKeys) {
            for (BGArea area : areas) {
                if (area.getKey().equals(areaKey)) {
                    continue a_a;
                }
            }
            StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", areaKey.toString() }, translatorStr);
            sd.setDescriptionForUnit(nodeId);
            missingNames.add(sd);
        }
    } else {
        String areaStr = (String) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_AREA);
        if (areaStr != null) {
            String[] areas = areaStr.split(",");
            for (int i = 0; i < areas.length; i++) {
                String trimmed = areas[i] != null ? areas[i].trim() : areas[i];
                if (!trimmed.equals("") && !cev.existsArea(trimmed)) {
                    StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", trimmed }, translatorStr);
                    sd.setDescriptionForUnit(nodeId);
                    missingNames.add(sd);
                }
            }
        }
    }
    @SuppressWarnings("unchecked") List<Long> groupKeys = (List<Long>) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP_ID);
    if (groupKeys != null) {
        BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        List<BusinessGroupShort> groups = bgs.loadShortBusinessGroups(groupKeys);
        a_a: for (Long activeGroupKey : groupKeys) {
            for (BusinessGroupShort group : groups) {
                if (group.getKey().equals(activeGroupKey)) {
                    continue a_a;
                }
            }
            StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", activeGroupKey.toString() }, translatorStr);
            sd.setDescriptionForUnit(nodeId);
            missingNames.add(sd);
        }
    } else {
        String groupStr = (String) mc.get(COEditController.CONFIG_KEY_EMAILTOCOACHES_GROUP);
        if (groupStr != null) {
            String[] groups = groupStr.split(",");
            for (int i = 0; i < groups.length; i++) {
                String trimmed = groups[i] != null ? groups[i].trim() : groups[i];
                if (!trimmed.equals("") && !cev.existsGroup(trimmed)) {
                    StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.notfound.name", "solution.checkgroupmanagement", new String[] { "NONE", trimmed }, translatorStr);
                    sd.setDescriptionForUnit(nodeId);
                    missingNames.add(sd);
                }
            }
        }
    }
    missingNames.addAll(condErrs);
    oneClickStatusCache = StatusDescriptionHelper.sort(missingNames);
    return oneClickStatusCache;
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) ArrayList(java.util.ArrayList) BGArea(org.olat.group.area.BGArea) BusinessGroupService(org.olat.group.BusinessGroupService) StatusDescription(org.olat.course.editor.StatusDescription) ArrayList(java.util.ArrayList) List(java.util.List) BusinessGroupShort(org.olat.group.BusinessGroupShort) BGAreaManager(org.olat.group.area.BGAreaManager)

Example 19 with BusinessGroupShort

use of org.olat.group.BusinessGroupShort in project openolat by klemens.

the class CourseOverviewController method updateModel.

private void updateModel() {
    // course membership
    List<RepositoryEntryMembership> memberships = repositoryManager.getRepositoryEntryMembership(null, editedIdentity);
    // group membership
    List<BusinessGroupMembership> groupMemberships = businessGroupService.getBusinessGroupMembership(Collections.<Long>emptyList(), editedIdentity);
    Collection<Long> groupKeys = new ArrayList<Long>(groupMemberships.size());
    for (BusinessGroupMembership membership : groupMemberships) {
        groupKeys.add(membership.getGroupKey());
    }
    // relation to course
    List<BGRepositoryEntryRelation> relations = businessGroupService.findRelationToRepositoryEntries(groupKeys, 0, -1);
    Map<Long, List<Long>> groupKeyToRepoKeyMap = new HashMap<>();
    for (BGRepositoryEntryRelation relation : relations) {
        if (groupKeyToRepoKeyMap.containsKey(relation.getGroupKey())) {
            groupKeyToRepoKeyMap.get(relation.getGroupKey()).add(relation.getRepositoryEntryKey());
        } else {
            List<Long> repoEntryKeys = new ArrayList<>(2);
            repoEntryKeys.add(relation.getRepositoryEntryKey());
            groupKeyToRepoKeyMap.put(relation.getGroupKey(), repoEntryKeys);
        }
    }
    Map<Long, CourseMemberView> repoKeyToViewMap = new HashMap<Long, CourseMemberView>();
    for (RepositoryEntryMembership membership : memberships) {
        Long repoKey = membership.getRepoKey();
        CourseMemberView memberView;
        if (repoKeyToViewMap.containsKey(repoKey)) {
            memberView = repoKeyToViewMap.get(repoKey);
        } else {
            memberView = new CourseMemberView(repoKey);
            repoKeyToViewMap.put(repoKey, memberView);
        }
        memberView.setFirstTime(membership.getCreationDate());
        if (memberView.getLastTime() == null || (memberView.getLastTime() != null && membership.getLastModified() != null && membership.getLastModified().after(memberView.getLastTime()))) {
            memberView.setLastTime(membership.getLastModified());
        }
        // add the roles
        if (!memberView.getMembership().isRepoOwner()) {
            memberView.getMembership().setRepoOwner(membership.isOwner());
        }
        if (!memberView.getMembership().isRepoTutor()) {
            memberView.getMembership().setRepoTutor(membership.isCoach());
        }
        if (!memberView.getMembership().isRepoParticipant()) {
            memberView.getMembership().setRepoParticipant(membership.isParticipant());
        }
    }
    List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(groupKeys);
    Map<Long, BusinessGroupShort> groupKeyToGroupMap = new HashMap<Long, BusinessGroupShort>();
    for (BusinessGroupShort group : groups) {
        groupKeyToGroupMap.put(group.getKey(), group);
    }
    for (BusinessGroupMembership membership : groupMemberships) {
        List<Long> repoKeys;
        if (groupKeyToRepoKeyMap.containsKey(membership.getGroupKey())) {
            repoKeys = groupKeyToRepoKeyMap.get(membership.getGroupKey());
        } else {
            continue;
        }
        BusinessGroupShort group = groupKeyToGroupMap.get(membership.getGroupKey());
        if (group == null) {
            continue;
        }
        for (Long repoKey : repoKeys) {
            CourseMemberView memberView;
            if (repoKeyToViewMap.containsKey(repoKey)) {
                memberView = repoKeyToViewMap.get(repoKey);
            } else {
                memberView = new CourseMemberView(repoKey);
                repoKeyToViewMap.put(repoKey, memberView);
            }
            memberView.addGroup(group);
            memberView.setFirstTime(membership.getCreationDate());
            if (memberView.getLastTime() == null || (memberView.getLastTime() != null && membership.getLastModified() != null && membership.getLastModified().after(memberView.getLastTime()))) {
                memberView.setLastTime(membership.getLastModified());
            }
            switch(membership.getMembership()) {
                case owner:
                    memberView.getMembership().setGroupTutor(true);
                    break;
                case participant:
                    memberView.getMembership().setGroupParticipant(true);
                    break;
                case waiting:
                    memberView.getMembership().setGroupWaiting(true);
                    break;
            }
        }
    }
    List<RepositoryEntry> entries = repositoryManager.lookupRepositoryEntries(repoKeyToViewMap.keySet());
    Map<Long, RepositoryEntry> entryKeyToRepoEntryMap = new HashMap<Long, RepositoryEntry>();
    for (RepositoryEntry entry : entries) {
        entryKeyToRepoEntryMap.put(entry.getKey(), entry);
    }
    for (CourseMemberView memberView : repoKeyToViewMap.values()) {
        RepositoryEntry entry = entryKeyToRepoEntryMap.get(memberView.getRepoKey());
        if (entry != null) {
            memberView.setEntry(entry);
            boolean managedMembersRepo = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.membersmanagement);
            memberView.getMembership().setManagedMembersRepo(managedMembersRepo);
        }
    }
    List<CourseMemberView> views = new ArrayList<CourseMemberView>(repoKeyToViewMap.values());
    tableDataModel.setObjects(views);
    courseListCtr.modelChanged();
}
Also used : BusinessGroupMembership(org.olat.group.BusinessGroupMembership) RepositoryEntryMembership(org.olat.repository.model.RepositoryEntryMembership) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) List(java.util.List) ArrayList(java.util.ArrayList) BGRepositoryEntryRelation(org.olat.group.model.BGRepositoryEntryRelation) BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 20 with BusinessGroupShort

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

the class ConditionConfigEasyController method validateGroupFields.

/**
 * @param retVal
 * @return
 */
private boolean validateGroupFields() {
    boolean retVal = true;
    if (groupSwitch.getSelectedKeys().size() == 1) {
        List<Long> activeGroupSelection = null;
        List<Long> activeAreaSelection = null;
        groupChooseSubContainer.clearError();
        if (!isEmpty(easyGroupList)) {
            // check whether groups exist
            activeGroupSelection = getKeys(easyGroupList);
            Set<Long> missingGroups = new HashSet<Long>();
            List<BusinessGroupShort> existingGroups = businessGroupService.loadShortBusinessGroups(activeGroupSelection);
            a_a: for (Long activeGroupKey : activeGroupSelection) {
                for (BusinessGroupShort group : existingGroups) {
                    if (group.getKey().equals(activeGroupKey)) {
                        continue a_a;
                    }
                }
                missingGroups.add(activeGroupKey);
            }
            if (missingGroups.size() > 0) {
                retVal = false;
                String labelKey = missingGroups.size() == 1 ? "error.notfound.name" : "error.notfound.names";
                String csvMissGrps = toString(missingGroups);
                String[] params = new String[] { "-", csvMissGrps };
                // create error with link to fix it
                String vc_errorPage = velocity_root + "/erroritem.html";
                FormLayoutContainer errorGroupItemLayout = FormLayoutContainer.createCustomFormLayout("errorgroupitem", getTranslator(), vc_errorPage);
                groupChooseSubContainer.setErrorComponent(errorGroupItemLayout, this.flc);
                // FIXING LINK ONLY IF A DEFAULTCONTEXT EXISTS
                fixGroupError = new FormLinkImpl("error.fix", "create");
                // link
                fixGroupError.setCustomEnabledLinkCSS("btn btn-default");
                errorGroupItemLayout.add(fixGroupError);
                fixGroupError.setErrorKey(labelKey, params);
                fixGroupError.showError(true);
                fixGroupError.showLabel(false);
                // String[].lenght > 1 -> show bulkmode creation group
                if (missingGroups.size() > 1) {
                    fixGroupError.setUserObject(new String[] { csvMissGrps, "dummy" });
                } else {
                    fixGroupError.setUserObject(new String[] { csvMissGrps });
                }
                groupChooseSubContainer.showError(true);
            } else {
                // no more errors
                groupChooseSubContainer.clearError();
            }
        }
        areaChooseSubContainer.clearError();
        if (!isEmpty(easyAreaList)) {
            // check whether areas exist
            activeAreaSelection = getKeys(easyAreaList);
            List<Long> missingAreas = new ArrayList<Long>();
            List<BGArea> cnt = areaManager.loadAreas(activeAreaSelection);
            a_a: for (Long activeAreaKey : activeAreaSelection) {
                for (BGArea element : cnt) {
                    if (element.getKey().equals(activeAreaKey)) {
                        continue a_a;
                    }
                }
                missingAreas.add(activeAreaKey);
            }
            if (missingAreas.size() > 0) {
                retVal = false;
                String labelKey = missingAreas.size() == 1 ? "error.notfound.name" : "error.notfound.names";
                String csvMissAreas = toString(missingAreas);
                String[] params = new String[] { "-", csvMissAreas };
                // create error with link to fix it
                String vc_errorPage = velocity_root + "/erroritem.html";
                FormLayoutContainer errorAreaItemLayout = FormLayoutContainer.createCustomFormLayout("errorareaitem", getTranslator(), vc_errorPage);
                areaChooseSubContainer.setErrorComponent(errorAreaItemLayout, this.flc);
                // FXINGIN LINK ONLY IF DEFAULT CONTEXT EXISTS
                // erstellen
                fixAreaError = new FormLinkImpl("error.fix", "create");
                // link
                fixAreaError.setCustomEnabledLinkCSS("btn btn-default");
                errorAreaItemLayout.add(fixAreaError);
                fixAreaError.setErrorKey(labelKey, params);
                fixAreaError.showError(true);
                fixAreaError.showLabel(false);
                // String[].lenght > 1 -> show bulkmode creation group
                if (missingAreas.size() > 1) {
                    fixAreaError.setUserObject(new String[] { csvMissAreas, "dummy" });
                } else {
                    fixAreaError.setUserObject(new String[] { csvMissAreas });
                }
                areaChooseSubContainer.showError(true);
            } else {
                areaChooseSubContainer.clearError();
            }
        }
        boolean easyGroupOK = (!isEmpty(easyGroupList) && activeGroupSelection != null && !activeGroupSelection.isEmpty());
        boolean easyAreaOK = (!isEmpty(easyAreaList) && activeAreaSelection != null && !activeAreaSelection.isEmpty());
        if (easyGroupOK || easyAreaOK) {
            // clear general error
            groupSubContainer.clearError();
        } else {
            // error concerns both fields -> set it as switch error
            groupSubContainer.setErrorKey("form.easy.error.group", null);
            retVal = false;
        }
    }
    return retVal;
}
Also used : ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) BGArea(org.olat.group.area.BGArea) BusinessGroupShort(org.olat.group.BusinessGroupShort) HashSet(java.util.HashSet)

Aggregations

BusinessGroupShort (org.olat.group.BusinessGroupShort)34 ArrayList (java.util.ArrayList)18 BusinessGroup (org.olat.group.BusinessGroup)10 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 BGArea (org.olat.group.area.BGArea)6 RepositoryEntry (org.olat.repository.RepositoryEntry)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)4 Identity (org.olat.core.id.Identity)4 BusinessGroupMembership (org.olat.group.BusinessGroupMembership)4 RepositoryEntryShort (org.olat.repository.RepositoryEntryShort)4 RepositoryEntryMembership (org.olat.repository.model.RepositoryEntryMembership)4 Date (java.util.Date)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Test (org.junit.Test)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 FlexiTableSearchEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)2