Search in sources :

Example 36 with BusinessGroupService

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);
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) BusinessGroupModule(org.olat.group.BusinessGroupModule) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) Roles(org.olat.core.id.Roles) BaseSecurity(org.olat.basesecurity.BaseSecurity) BusinessGroupService(org.olat.group.BusinessGroupService) MailTemplate(org.olat.core.util.mail.MailTemplate) MailManager(org.olat.core.util.mail.MailManager) List(java.util.List) MailBundle(org.olat.core.util.mail.MailBundle)

Example 37 with BusinessGroupService

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);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) BusinessGroup(org.olat.group.BusinessGroup) VFSItem(org.olat.core.util.vfs.VFSItem) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BusinessGroupService(org.olat.group.BusinessGroupService) Identity(org.olat.core.id.Identity) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 38 with BusinessGroupService

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) XStream(com.thoughtworks.xstream.XStream) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) Identity(org.olat.core.id.Identity) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 39 with BusinessGroupService

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;
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams)

Example 40 with BusinessGroupService

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);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) EventBus(org.olat.core.util.event.EventBus) RepositoryEntry(org.olat.repository.RepositoryEntry)

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