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;
}
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);
}
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());
}
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;
}
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;
}
Aggregations