use of org.olat.group.BusinessGroupService in project openolat by klemens.
the class BusinessGroupMailing method sendEmail.
protected static void sendEmail(Identity ureqIdentity, Identity identity, BusinessGroupShort group, MailType type, MailPackage mailing) {
if (mailing != null && !mailing.isSendEmail()) {
return;
}
if (mailing == null) {
BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
BusinessGroupModule groupModule = CoreSpringFactory.getImpl(BusinessGroupModule.class);
Roles ureqRoles = securityManager.getRoles(ureqIdentity);
if (!groupModule.isMandatoryEnrolmentEmail(ureqRoles)) {
return;
}
}
MailTemplate template = mailing == null ? null : mailing.getTemplate();
if (mailing == null || mailing.getTemplate() == null) {
// booking by myself
if (type != null && type == MailType.addParticipant && ureqIdentity != null && ureqIdentity.equals(identity)) {
template = BGMailHelper.createAddMyselfMailTemplate(group, ureqIdentity);
} else {
template = getDefaultTemplate(type, group, ureqIdentity);
}
} else if (group != null && template.getContext() != null && needTemplateEnhancement(template)) {
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
template = new MailTemplateDelegate(template, group, repoEntries);
}
MailContext context = mailing == null ? null : mailing.getContext();
if (context == null) {
context = new MailContextImpl(null, null, "[BusinessGroup:" + group.getKey() + "]");
}
MailerResult result = new MailerResult();
String metaId = mailing != null ? mailing.getUuid() : null;
MailManager mailService = CoreSpringFactory.getImpl(MailManager.class);
MailBundle bundle = mailService.makeMailBundle(context, identity, template, ureqIdentity, metaId, result);
if (bundle != null) {
mailService.sendMessage(bundle);
}
if (mailing != null) {
mailing.appendResult(result);
}
}
use of org.olat.group.BusinessGroupService in project openolat by klemens.
the class ProjectBrokerCourseNode method postCopy.
/**
* Do re-arrange the projects in a new project broker after the copy happened
*/
@Override
public void postCopy(CourseEnvironmentMapper envMapper, Processing processType, ICourse course, ICourse sourceCourse) {
super.postCopy(envMapper, processType, course, null);
if (processType.equals(Processing.runstructure)) {
// initialize the managers and services
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
CoursePropertyManager oldCpm = sourceCourse.getCourseEnvironment().getCoursePropertyManager();
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
// create new Project broker and get the old one
Long projectBrokerId = projectBrokerManager.createAndSaveProjectBroker().getKey();
projectBrokerManager.saveProjectBrokerId(projectBrokerId, course.getCourseEnvironment().getCoursePropertyManager(), this);
// find the group for account manager and remap the account group
CourseNode sourceCourseNode = sourceCourse.getRunStructure().getNode(getIdent());
Long sourceAccountGroupKey = projectGroupManager.getAccountManagerGroupKey(oldCpm, sourceCourseNode);
if (sourceAccountGroupKey != null) {
Long copiedGroupKey = envMapper.toGroupKeyFromOriginalKey(sourceAccountGroupKey);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
projectGroupManager.saveAccountManagerGroupKey(copiedGroupKey, cpm, this);
}
Long oldBrokerId = projectBrokerManager.getProjectBrokerId(oldCpm, this);
List<Project> projectsFromGroup = projectBrokerManager.getProjectListBy(oldBrokerId);
// loop create and configure the new Projects
for (Project project : projectsFromGroup) {
Long originalGroupKey = project.getProjectGroup().getKey();
Long copiedGroupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
Identity author = envMapper.getAuthor();
BusinessGroup projectGroup = bgs.loadBusinessGroup(copiedGroupKey);
if (projectGroup == null) {
projectGroup = projectGroupManager.createProjectGroupFor(projectBrokerId, author, project.getTitle(), project.getDescription(), course.getResourceableId());
}
if (author != null) {
bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
}
Project newProject = projectBrokerManager.createAndSaveProjectFor(project.getTitle(), project.getDescription(), projectBrokerId, projectGroup);
// copy all project configurations
newProject.setMailNotificationEnabled(project.isMailNotificationEnabled());
newProject.setMaxMembers(project.getMaxMembers());
for (int i = 0; i < project.getCustomFieldSize(); i++) {
newProject.setCustomFieldValue(i, project.getCustomFieldValue(i));
}
projectGroupManager.setDeselectionAllowed(newProject, project.getProjectGroup().isAllowToLeave());
projectBrokerManager.updateProject(newProject);
// attachment file
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, sourceCourse.getCourseEnvironment(), this), null);
VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
if (item instanceof VFSLeaf) {
projectBrokerManager.saveAttachedFile(newProject, project.getAttachmentFileName(), (VFSLeaf) item, course.getCourseEnvironment(), this);
newProject.setAttachedFileName(project.getAttachmentFileName());
projectBrokerManager.updateProject(newProject);
}
}
}
}
use of org.olat.group.BusinessGroupService in project openolat by klemens.
the class ProjectBrokerCourseNode method importProject.
private void importProject(File projectDir, File projectFile, ProjectBroker projectBroker, ICourse course, CourseEnvironmentMapper envMapper) {
XStream xstream = XStreamHelper.createXStreamInstance();
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
// read the projectConfiguration from the importDirectory
try {
@SuppressWarnings("unchecked") Map<String, Object> projectConfig = (HashMap<String, Object>) XStreamHelper.readObject(xstream, projectFile);
String projectTitle = (String) projectConfig.get("title");
Long originalGroupKey = null;
if (projectConfig.containsKey("businessGroupKey")) {
originalGroupKey = (Long) projectConfig.get("businessGroupKey");
} else {
for (BusinessGroupReference ref : envMapper.getGroups()) {
if (ref.getName().endsWith(projectTitle)) {
originalGroupKey = ref.getOriginalKey();
}
}
}
BusinessGroup projectGroup = null;
if (originalGroupKey != null) {
Long groupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
projectGroup = bgs.loadBusinessGroup(groupKey);
}
if (projectGroup == null) {
projectGroup = projectGroupManager.createProjectGroupFor(projectBroker.getKey(), envMapper.getAuthor(), projectTitle, (String) projectConfig.get("description"), course.getResourceableId());
}
if (envMapper.getAuthor() != null) {
Identity author = envMapper.getAuthor();
bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
}
Project project = projectBrokerManager.createAndSaveProjectFor(projectTitle, (String) projectConfig.get("description"), projectBrokerManager.getProjectBrokerId(cpm, this), projectGroup);
projectGroupManager.setDeselectionAllowed(project, (boolean) projectConfig.get("allowDeselection"));
project.setMailNotificationEnabled((boolean) projectConfig.get("mailNotificationEnabled"));
project.setMaxMembers((int) projectConfig.get("maxMembers"));
project.setAttachedFileName(projectConfig.get("attachmentFileName").toString());
for (int i = 0; i < (int) projectConfig.get("customeFieldSize"); i++) {
project.setCustomFieldValue(i, projectConfig.get("customFieldValue" + i).toString());
}
projectBrokerManager.updateProject(project);
// get the attachment directory within the project
// directory
// .getParentFile().listFiles(attachmentFilter);
File attachmentDir = new File(projectDir, "attachment");
if (attachmentDir.exists()) {
File[] attachment = attachmentDir.listFiles();
if (attachment.length > 0) {
VFSLeaf attachmentLeaf = new LocalFileImpl(attachment[0]);
projectBrokerManager.saveAttachedFile(project, projectConfig.get("attachmentFileName").toString(), attachmentLeaf, course.getCourseEnvironment(), this);
}
}
} catch (Exception e) {
// handle/log error in case of FileIO exception or cast
// exception if import input is not correct
log.error("Error while importing a project into projectbroker", e);
}
}
use of org.olat.group.BusinessGroupService in project openolat by klemens.
the class GoToMeetingCourseNode method isCoach.
private final boolean isCoach(RepositoryEntry re, Identity identity) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
SearchBusinessGroupParams params = new SearchBusinessGroupParams(identity, true, false);
int count = bgs.countBusinessGroups(params, re);
return count > 0;
}
use of org.olat.group.BusinessGroupService in project openolat by klemens.
the class BusinessGroupModifiedEvent method fireModifiedGroupEvents.
/**
* Fires event to all listeners of this business group and the listeners of
* the ressources associated with the group context of this group
*
* @param command The event identifyer, one of CONFIGURATION_MODIFIED_EVENT,
* IDENTITY_ADDED_EVENT or IDENTITY_REMOVED_EVENT
* @param group The group affected by the modification
* @param identity The identity affected by the modification
*/
public static void fireModifiedGroupEvents(String command, BusinessGroup group, Identity identity) {
BusinessGroupModifiedEvent modifiedEvent = new BusinessGroupModifiedEvent(command, group, identity);
EventBus eventBus = CoordinatorManager.getInstance().getCoordinator().getEventBus();
// 1) notify listeners of group events
eventBus.fireEventToListenersOf(modifiedEvent, group);
eventBus.fireEventToListenersOf(modifiedEvent, OresHelper.lookupType(BusinessGroup.class));
// 2) notify listeners of learning resources of this group
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<RepositoryEntry> repoEntries = bgs.findRepositoryEntries(Collections.singletonList(group), 0, -1);
for (RepositoryEntry entry : repoEntries) {
eventBus.fireEventToListenersOf(modifiedEvent, entry);
}
}
Aggregations