Search in sources :

Example 26 with BusinessGroupShort

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

the class CourseOverviewController method doLeave.

/**
 * The method check the managed flags
 * @param ureq
 * @param views
 */
private void doLeave(UserRequest ureq, Collection<CourseMemberView> views) {
    List<Long> groupKeys = new ArrayList<Long>();
    List<RepositoryEntry> repoEntryToLeave = new ArrayList<RepositoryEntry>();
    for (CourseMemberView view : views) {
        for (BusinessGroupShort group : view.getGroups()) {
            if (!BusinessGroupManagedFlag.isManaged(group.getManagedFlags(), BusinessGroupManagedFlag.membersmanagement)) {
                groupKeys.add(group.getKey());
            }
        }
        RepositoryEntry re = repositoryManager.lookupRepositoryEntry(view.getRepoKey());
        if (!RepositoryEntryManagedFlag.isManaged(re, RepositoryEntryManagedFlag.membersmanagement)) {
            repoEntryToLeave.add(re);
            if (view.getMembership().isRepoOwner()) {
                int numOfOwners = repositoryService.countMembers(re, GroupRoles.owner.name());
                if (numOfOwners == 1) {
                    showError("error.atleastone", view.getDisplayName());
                    // break the process
                    return;
                }
            }
        }
    }
    List<BusinessGroup> groupsToLeave = businessGroupService.loadBusinessGroups(groupKeys);
    List<BusinessGroup> groupsToDelete = new ArrayList<BusinessGroup>(1);
    for (BusinessGroup group : groupsToLeave) {
        int numOfOwners = businessGroupService.countMembers(group, GroupRoles.coach.name());
        int numOfParticipants = businessGroupService.countMembers(group, GroupRoles.participant.name());
        if ((numOfOwners == 1 && numOfParticipants == 0) || (numOfOwners == 0 && numOfParticipants == 1)) {
            groupsToDelete.add(group);
        }
    }
    removeFromCourseDlg = new CourseLeaveDialogBoxController(ureq, getWindowControl(), editedIdentity, repoEntryToLeave, groupsToLeave, groupsToDelete);
    listenTo(removeFromCourseDlg);
    cmc = new CloseableModalController(getWindowControl(), translate("close"), removeFromCourseDlg.getInitialComponent(), true, translate("unsubscribe.title"));
    cmc.activate();
    listenTo(cmc);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 27 with BusinessGroupShort

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

the class BusinessGroupNameColumnDescriptor method compareTo.

@Override
public int compareTo(int rowa, int rowb) {
    Object a = table.getTableDataModel().getValueAt(rowa, dataColumn);
    Object b = table.getTableDataModel().getValueAt(rowb, dataColumn);
    if (a instanceof BusinessGroupShort && b instanceof BusinessGroupShort) {
        BusinessGroupShort g1 = (BusinessGroupShort) a;
        BusinessGroupShort g2 = (BusinessGroupShort) b;
        return super.compareString(g1.getName(), g2.getName());
    }
    return super.compareTo(rowa, rowb);
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 28 with BusinessGroupShort

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

the class MailBoxExtension method getName.

@Override
public String getName(String businessPath, Locale locale) {
    if (!StringHelper.containsNonWhitespace(businessPath))
        return null;
    try {
        List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromString(businessPath);
        Collections.reverse(entries);
        for (ContextEntry entry : entries) {
            String resourceTypeName = entry.getOLATResourceable().getResourceableTypeName();
            Long resourceId = entry.getOLATResourceable().getResourceableId();
            if ("BusinessGroup".equals(resourceTypeName)) {
                List<Long> ids = Collections.singletonList(resourceId);
                List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(ids);
                if (groups == null || groups.isEmpty()) {
                    return null;
                }
                return groups.get(0).getName();
            } else if ("RepositoryEntry".equals(resourceTypeName)) {
                return repositoryManager.lookupDisplayName(resourceId);
            }
        }
    } catch (Exception e) {
        log.error("", e);
    }
    return null;
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 29 with BusinessGroupShort

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

the class ENEditGroupAreaFormController method validateGroupFields.

private boolean validateGroupFields() {
    boolean retVal = true;
    List<Long> activeGroupSelection = null;
    List<Long> activeAreaSelection = null;
    easyAreaList.clearError();
    easyGroupList.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);
            easyGroupList.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 });
            }
            easyGroupList.showError(true);
        }
    }
    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);
            easyAreaList.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 });
            }
            easyAreaList.showError(true);
        }
    }
    boolean easyGroupOK = activeGroupSelection != null && activeGroupSelection.size() > 0;
    boolean easyAreaOK = activeAreaSelection != null && activeAreaSelection.size() > 0;
    if (!easyGroupOK && !easyAreaOK) {
        // error concerns both fields -> set it as switch error
        easyGroupList.setErrorKey("form.noGroupsOrAreas", null);
        retVal = false;
    }
    // raise error if someone removed all groups and areas from form
    if (!retVal && !easyGroupOK && !easyAreaOK) {
        easyGroupList.setErrorKey("form.noGroupsOrAreas", null);
    }
    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)

Example 30 with BusinessGroupShort

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

the class GTAWorkflowEditController method getGroupNames.

private String getGroupNames(List<Long> groupKeyList) {
    StringBuilder sb = new StringBuilder(64);
    List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(groupKeyList);
    for (BusinessGroupShort group : groups) {
        if (sb.length() > 0)
            sb.append("&nbsp;&nbsp;");
        sb.append("<i class='o_icon o_icon-fw o_icon_group'>&nbsp;</i> ").append(StringHelper.escapeHtml(group.getName()));
    }
    return sb.toString();
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort)

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