Search in sources :

Example 6 with BusinessGroupShort

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

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 7 with BusinessGroupShort

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

the class ENEditGroupAreaFormController method getGroupKeysAndNames.

private KeysAndNames getGroupKeysAndNames(List<Long> keys) {
    StringBuilder sb = new StringBuilder();
    KeysAndNames keysAndNames = new KeysAndNames();
    keysAndNames.getKeys().addAll(keys);
    List<BusinessGroupShort> groups = businessGroupService.loadShortBusinessGroups(keys);
    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> ");
        sb.append(StringHelper.escapeHtml(group.getName()));
        keysAndNames.getNames().add(group.getName());
    }
    keysAndNames.setDecoratedNames(sb.toString());
    return keysAndNames;
}
Also used : BusinessGroupShort(org.olat.group.BusinessGroupShort)

Example 8 with BusinessGroupShort

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

the class BusinessGroupDAOTest method loadShortBusinessGroupsByKeys.

@Test
public void loadShortBusinessGroupsByKeys() {
    BusinessGroup group1 = businessGroupDao.createAndPersist(null, "shorty-1", "shorty-1-desc", 0, 10, true, true, false, false, false);
    BusinessGroup group2 = businessGroupDao.createAndPersist(null, "shorty-2", "shorty-2-desc", 0, 10, true, true, false, false, false);
    dbInstance.commitAndCloseSession();
    // check if the method is robust against empty list fo keys
    List<BusinessGroupShort> groups1 = businessGroupDao.loadShort(Collections.<Long>emptyList());
    Assert.assertNotNull(groups1);
    Assert.assertEquals(0, groups1.size());
    // check load 1 group
    List<BusinessGroupShort> groups2 = businessGroupDao.loadShort(Collections.singletonList(group1.getKey()));
    Assert.assertNotNull(groups2);
    Assert.assertEquals(1, groups2.size());
    Assert.assertEquals(group1.getKey(), groups2.get(0).getKey());
    Assert.assertEquals(group1.getName(), groups2.get(0).getName());
    // check load 2 groups
    List<Long> groupKeys = new ArrayList<Long>(2);
    groupKeys.add(group1.getKey());
    groupKeys.add(group2.getKey());
    List<BusinessGroupShort> groups3 = businessGroupDao.loadShort(groupKeys);
    Assert.assertNotNull(groups3);
    Assert.assertEquals(2, groups3.size());
    List<Long> groupShortKeys3 = new ArrayList<Long>(3);
    for (BusinessGroupShort group : groups3) {
        groupShortKeys3.add(group.getKey());
    }
    Assert.assertTrue(groupShortKeys3.contains(group1.getKey()));
    Assert.assertTrue(groupShortKeys3.contains(group2.getKey()));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) BusinessGroupShort(org.olat.group.BusinessGroupShort) Test(org.junit.Test)

Example 9 with BusinessGroupShort

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

the class AbstractMemberListController method doGraduate.

protected void doGraduate(List<MemberView> members) {
    if (businessGroup != null) {
        List<Long> identityKeys = getMemberKeys(members);
        List<Identity> identitiesToGraduate = securityManager.loadIdentityByKeys(identityKeys);
        businessGroupService.moveIdentityFromWaitingListToParticipant(getIdentity(), identitiesToGraduate, businessGroup, null);
    } else {
        Map<Long, BusinessGroup> groupsMap = new HashMap<>();
        Map<BusinessGroup, List<Identity>> graduatesMap = new HashMap<>();
        for (MemberView member : members) {
            List<BusinessGroupShort> groups = member.getGroups();
            if (groups != null && groups.size() > 0) {
                Identity memberIdentity = securityManager.loadIdentityByKey(member.getIdentityKey());
                for (BusinessGroupShort group : groups) {
                    if (businessGroupService.hasRoles(memberIdentity, group, GroupRoles.waiting.name())) {
                        BusinessGroup fullGroup = groupsMap.get(group.getKey());
                        if (fullGroup == null) {
                            fullGroup = businessGroupService.loadBusinessGroup(group.getKey());
                            groupsMap.put(group.getKey(), fullGroup);
                        }
                        List<Identity> identitiesToGraduate = graduatesMap.get(fullGroup);
                        if (identitiesToGraduate == null) {
                            identitiesToGraduate = new ArrayList<>();
                            graduatesMap.put(fullGroup, identitiesToGraduate);
                        }
                        identitiesToGraduate.add(memberIdentity);
                    }
                }
            }
        }
        for (Map.Entry<BusinessGroup, List<Identity>> entry : graduatesMap.entrySet()) {
            BusinessGroup fullGroup = entry.getKey();
            List<Identity> identitiesToGraduate = entry.getValue();
            businessGroupService.moveIdentityFromWaitingListToParticipant(getIdentity(), identitiesToGraduate, fullGroup, null);
        }
    }
    reloadModel();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) HashMap(java.util.HashMap) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BusinessGroupShort(org.olat.group.BusinessGroupShort) Map(java.util.Map) HashMap(java.util.HashMap)

Example 10 with BusinessGroupShort

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

the class BusinessGroupRelationDAO method findShortRepositoryEntries.

public List<RepositoryEntryShort> findShortRepositoryEntries(Collection<BusinessGroupShort> groups, int firstResult, int maxResults) {
    if (groups == null || groups.isEmpty()) {
        return Collections.emptyList();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select new org.olat.group.model.BGRepositoryEntryShortImpl(v.key, v.displayname) from ").append(RepositoryEntry.class.getName()).append(" as v ").append(" inner join v.olatResource as ores ").append(" inner join v.groups as relGroup").append(" where exists (").append("   select bgi from businessgroup as bgi where bgi.baseGroup=relGroup.group and bgi.key in (:groupKeys)").append(" )");
    TypedQuery<RepositoryEntryShort> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), RepositoryEntryShort.class);
    query.setFirstResult(firstResult);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    List<Long> groupKeys = new ArrayList<Long>();
    for (BusinessGroupShort group : groups) {
        groupKeys.add(group.getKey());
    }
    query.setParameter("groupKeys", groupKeys);
    query.setHint("org.hibernate.cacheable", Boolean.TRUE);
    return query.getResultList();
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) 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