Search in sources :

Example 21 with BusinessGroupService

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

the class BGMailHelper method createMailTemplate.

/**
 * Internal helper - does all the magic
 *
 * @param group
 * @param actor
 * @param subjectKey
 * @param bodyKey
 * @return
 */
private static MailTemplate createMailTemplate(BusinessGroupShort group, Identity actor, String subjectKey, String bodyKey) {
    // get some data about the actor and fetch the translated subject / body via i18n module
    String[] bodyArgs = null;
    String lang = null;
    if (actor != null) {
        lang = actor.getUser().getPreferences().getLanguage();
    }
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(lang);
    if (actor != null) {
        bodyArgs = new String[] { actor.getUser().getProperty(UserConstants.FIRSTNAME, null), actor.getUser().getProperty(UserConstants.LASTNAME, null), UserManager.getInstance().getUserDisplayEmail(actor, locale), // 2x for compatibility with old i18m properties
        UserManager.getInstance().getUserDisplayEmail(actor, locale) };
    }
    Translator trans = Util.createPackageTranslator(BGMailHelper.class, locale, Util.createPackageTranslator(BusinessGroupListController.class, locale));
    String subject = trans.translate(subjectKey);
    String body = trans.translate(bodyKey, bodyArgs);
    // build learning resources as list of url as string
    final BGMailTemplateInfos infos;
    if (group != null) {
        BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
        List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
        infos = getTemplateInfos(group, repoEntries);
        subject = subject.replace("$groupname", infos.getGroupName());
        body = body.replace("$groupname", infos.getGroupNameWithUrl());
        body = body.replace("$groupdescription", infos.getGroupDescription());
        if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
            body = body.replace("$courselist", infos.getCourseList());
        } else {
            body = body.replace("$courselist", trans.translate("notification.mail.no.ressource", null));
        }
    } else {
        infos = new BGMailTemplateInfos("", "", "", "");
    }
    // create a mail template which all these data
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity identity) {
            // Put user variables into velocity context
            User user = identity.getUser();
            context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
            context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
            // the email of the user, needs to stay named 'login'
            context.put("login", user.getProperty(UserConstants.EMAIL, null));
            // Put variables from greater context
            context.put("groupname", infos.getGroupNameWithUrl());
            context.put("groupdescription", infos.getGroupDescription());
            if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
                context.put("courselist", infos.getCourseList());
            } else {
                context.put("courselist", trans.translate("notification.mail.no.ressource", null));
            }
            context.put("courselistempty", trans.translate("notification.mail.no.ressource", null));
        }
    };
    return mailTempl;
}
Also used : Locale(java.util.Locale) User(org.olat.core.id.User) RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) VelocityContext(org.apache.velocity.VelocityContext) Translator(org.olat.core.gui.translator.Translator) BusinessGroupService(org.olat.group.BusinessGroupService) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) BusinessGroupListController(org.olat.group.ui.main.BusinessGroupListController)

Example 22 with BusinessGroupService

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

the class ProjectGroupManagerImpl method setProjectGroupMaxMembers.

@Override
public BusinessGroup setProjectGroupMaxMembers(Identity ureqIdentity, BusinessGroup projectGroup, int maxMembers) {
    BusinessGroupService bgs = businessGroupService;
    BusinessGroup reloadedBusinessGroup = bgs.loadBusinessGroup(projectGroup);
    log.debug("ProjectGroup.name=" + reloadedBusinessGroup.getName() + " setMaxParticipants=" + maxMembers);
    return bgs.updateBusinessGroup(ureqIdentity, reloadedBusinessGroup, reloadedBusinessGroup.getName(), reloadedBusinessGroup.getDescription(), reloadedBusinessGroup.getExternalId(), reloadedBusinessGroup.getManagedFlagsString(), reloadedBusinessGroup.getMinParticipants(), maxMembers);
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup)

Example 23 with BusinessGroupService

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

the class ProjectGroupManagerImpl method changeProjectGroupName.

/**
 * Change group-name and description. Check if new group-name does not already exist in the course-group-context.
 * If the goup-name already exist, it will be automatically try another one with suffix e.g. ' _2'
 * @see org.olat.course.nodes.projectbroker.service.ProjectGroupManager#changeProjectGroupName(org.olat.group.BusinessGroup, java.lang.String, java.lang.String)
 */
@Override
public BusinessGroup changeProjectGroupName(Identity ureqIdentity, BusinessGroup projectGroup, String groupName, String groupDescription, OLATResource courseResource) {
    BusinessGroupService bgs = businessGroupService;
    BusinessGroup reloadedBusinessGroup = bgs.loadBusinessGroup(projectGroup);
    return bgs.updateBusinessGroup(ureqIdentity, reloadedBusinessGroup, groupName, groupDescription, reloadedBusinessGroup.getExternalId(), reloadedBusinessGroup.getManagedFlagsString(), reloadedBusinessGroup.getMinParticipants(), reloadedBusinessGroup.getMaxParticipants());
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup)

Example 24 with BusinessGroupService

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

the class OpenOLATStatisticsWebService method getUserStatisticsVO.

private UserStatisticsVO getUserStatisticsVO() {
    UserStatisticsVO stats = new UserStatisticsVO();
    BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    // activeUserCount="88" // registered and activated identities, same as in GUI
    long countActiveUsers = securityManager.countIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, null, null, Constants.USERSTATUS_ACTIVE);
    stats.setActiveUserCount(countActiveUsers);
    // active last day
    Calendar lastDay = Calendar.getInstance();
    lastDay.add(Calendar.DATE, -1);
    long activeUserCountDay = securityManager.countUniqueUserLoginsSince(lastDay.getTime());
    stats.setActiveUserCountLastDay(activeUserCountDay);
    // active last week
    Calendar lastWeek = Calendar.getInstance();
    lastWeek.add(Calendar.DATE, -7);
    long activeUserCountWeek = securityManager.countUniqueUserLoginsSince(lastWeek.getTime());
    stats.setActiveUserCountLastWeek(activeUserCountWeek);
    // active last month
    Calendar lastMonth = Calendar.getInstance();
    lastMonth.add(Calendar.MONTH, -1);
    long activeUserCountMonth = securityManager.countUniqueUserLoginsSince(lastMonth.getTime());
    stats.setActiveUserCountLastMonth(activeUserCountMonth);
    // active last 6 month
    Calendar last6Month = Calendar.getInstance();
    last6Month.add(Calendar.MONTH, -6);
    long activeUserCount6Month = securityManager.countUniqueUserLoginsSince(last6Month.getTime());
    stats.setActiveUserCountLast6Month(activeUserCount6Month);
    // externalUserCount="12" // EP invite identities, later maybe also used in courses for MOOCS, external experts etc)
    long invitationsCount = CoreSpringFactory.getImpl(InvitationDAO.class).countInvitations();
    stats.setExternalUserCount(invitationsCount);
    // blockedUserCount="0" // identities in login blocked state
    long blockedUserCount = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_LOGIN_DENIED);
    stats.setBlockedUserCount(blockedUserCount);
    // deletedUserCount="943" // deleted identities
    long deletedUserCount = securityManager.countIdentitiesByPowerSearch(null, null, true, null, null, null, null, null, null, null, Identity.STATUS_DELETED);
    stats.setDeletedUserCount(deletedUserCount);
    // totalUserCount="1043" // Sum of all above
    long countUsers = securityManager.countIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, null, null, null);
    stats.setTotalUserCount(countUsers);
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    long countGroups = bgs.countBusinessGroups(null, null);
    stats.setTotalGroupCount(countGroups);
    return stats;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) Calendar(java.util.Calendar) InvitationDAO(org.olat.portfolio.manager.InvitationDAO) UserStatisticsVO(org.olat.restapi.system.vo.UserStatisticsVO) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 25 with BusinessGroupService

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

the class CourseAssessmentWebService method loadUsers.

private List<Identity> loadUsers(ICourse course) {
    List<Identity> identities = new ArrayList<Identity>();
    List<BusinessGroup> groups = course.getCourseEnvironment().getCourseGroupManager().getAllBusinessGroups();
    Set<Long> check = new HashSet<Long>();
    BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
    List<Identity> participants = businessGroupService.getMembers(groups, GroupRoles.participant.name());
    for (Identity participant : participants) {
        if (!check.contains(participant.getKey())) {
            identities.add(participant);
            check.add(participant.getKey());
        }
    }
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(course, false);
    if (re != null) {
        List<Identity> ids = repositoryService.getMembers(re, GroupRoles.participant.name());
        for (Identity id : ids) {
            if (!check.contains(id.getKey())) {
                identities.add(id);
                check.add(id.getKey());
            }
        }
    }
    return identities;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) RepositoryService(org.olat.repository.RepositoryService)

Aggregations

BusinessGroupService (org.olat.group.BusinessGroupService)102 BusinessGroup (org.olat.group.BusinessGroup)84 Identity (org.olat.core.id.Identity)58 Path (javax.ws.rs.Path)38 Produces (javax.ws.rs.Produces)30 GET (javax.ws.rs.GET)24 CollaborationTools (org.olat.collaboration.CollaborationTools)18 SearchBusinessGroupParams (org.olat.group.model.SearchBusinessGroupParams)18 ArrayList (java.util.ArrayList)16 GroupVO (org.olat.restapi.support.vo.GroupVO)16 RepositoryEntry (org.olat.repository.RepositoryEntry)14 List (java.util.List)12 UserRequest (org.olat.core.gui.UserRequest)12 ICourse (org.olat.course.ICourse)10 HashSet (java.util.HashSet)8 PUT (javax.ws.rs.PUT)8 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)8 Roles (org.olat.core.id.Roles)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6