Search in sources :

Example 16 with BusinessGroupService

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

the class ProjectGroupManagerImpl method deleteAccountManagerGroup.

public void deleteAccountManagerGroup(CoursePropertyManager cpm, CourseNode courseNode) {
    log.debug("deleteAccountManagerGroup start...");
    Property accountManagerGroupProperty = cpm.findCourseNodeProperty(courseNode, null, null, ProjectBrokerCourseNode.CONF_ACCOUNTMANAGER_GROUP_KEY);
    if (accountManagerGroupProperty != null) {
        Long groupKey = accountManagerGroupProperty.getLongValue();
        if (groupKey != null) {
            BusinessGroup accountManagerGroup = businessGroupService.loadBusinessGroup(groupKey);
            if (accountManagerGroup != null) {
                BusinessGroupService bgs = businessGroupService;
                bgs.deleteBusinessGroup(accountManagerGroup);
                log.audit("ProjectBroker: Deleted accountManagerGroup=" + accountManagerGroup);
            } else {
                log.debug("deleteAccountManagerGroup: accountManagerGroup=" + accountManagerGroup + " has already been deleted");
            }
        }
        cpm.deleteProperty(accountManagerGroupProperty);
        log.debug("deleteAccountManagerGroup: deleted accountManagerGroupProperty=" + accountManagerGroupProperty);
    } else {
        log.debug("deleteAccountManagerGroup: found no accountManagerGroup-key");
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) BusinessGroupService(org.olat.group.BusinessGroupService) Property(org.olat.properties.Property)

Example 17 with BusinessGroupService

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

the class ProjectGroupManagerImpl method deleteProjectGroupFor.

@Override
public void deleteProjectGroupFor(Project project) {
    BusinessGroupService bgs = businessGroupService;
    bgs.deleteBusinessGroup(project.getProjectGroup());
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService)

Example 18 with BusinessGroupService

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

the class UserFoldersWebService method getFolders.

/**
 * Retrieves a list of folders on a user base. All folders of groups
 * where the user is participant/tutor + all folders in course where
 * the user is a participant (owner, tutor or participant)
 * @response.representation.200.qname {http://www.example.com}folderVOes
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The folders
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_FOLDERVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param identityKey The key of the user (IdentityImpl)
 * @param httpRequest The HTTP request
 * @return The folders
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getFolders(@Context HttpServletRequest httpRequest) {
    Roles roles;
    Identity ureqIdentity = getIdentity(httpRequest);
    if (ureqIdentity == null) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!identity.getKey().equals(ureqIdentity.getKey())) {
        if (isAdmin(httpRequest)) {
            ureqIdentity = identity;
            roles = BaseSecurityManager.getInstance().getRoles(identity);
        } else {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    } else {
        roles = getRoles(httpRequest);
    }
    final Map<Long, Long> groupNotified = new HashMap<Long, Long>();
    final Map<Long, Collection<String>> courseNotified = new HashMap<Long, Collection<String>>();
    NotificationsManager man = NotificationsManager.getInstance();
    {
        // collect subscriptions
        List<String> notiTypes = Collections.singletonList("FolderModule");
        List<Subscriber> subs = man.getSubscribers(ureqIdentity, notiTypes);
        for (Subscriber sub : subs) {
            String resName = sub.getPublisher().getResName();
            if ("BusinessGroup".equals(resName)) {
                Long groupKey = sub.getPublisher().getResId();
                groupNotified.put(groupKey, sub.getPublisher().getResId());
            } else if ("CourseModule".equals(resName)) {
                Long courseKey = sub.getPublisher().getResId();
                if (!courseNotified.containsKey(courseKey)) {
                    courseNotified.put(courseKey, new ArrayList<String>());
                }
                courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
            }
        }
    }
    final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
    final IdentityEnvironment ienv = new IdentityEnvironment(ureqIdentity, roles);
    for (Map.Entry<Long, Collection<String>> e : courseNotified.entrySet()) {
        final Long courseKey = e.getKey();
        final Collection<String> nodeKeys = e.getValue();
        final ICourse course = CourseFactory.loadCourse(courseKey);
        new CourseTreeVisitor(course, ienv).visit(new Visitor() {

            @Override
            public void visit(INode node) {
                if (node instanceof BCCourseNode) {
                    BCCourseNode bcNode = (BCCourseNode) node;
                    if (nodeKeys.contains(bcNode.getIdent())) {
                        FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
                        folderVOs.add(folder);
                    }
                }
            }
        }, new VisibleTreeFilter());
    }
    /*
		RepositoryManager rm = RepositoryManager.getInstance();
		ACService acManager = CoreSpringFactory.getImpl(ACService.class);
		SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
		repoParams.setOnlyExplicitMember(true);
		List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
		for(RepositoryEntry entry:entries) {
			AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
			if(result.isAccessible()) {
				try {
					final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
					final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
					
					new CourseTreeVisitor(course,  ienv).visit(new Visitor() {
						@Override
						public void visit(INode node) {
							if(node instanceof BCCourseNode) {
								BCCourseNode bcNode = (BCCourseNode)node;
								FolderVO folder = BCWebService.createFolderVO(ienv, course, bcNode, courseNotified.get(course.getResourceableId()));
								folderVOs.add(folder);
							}
						}
					});
				} catch (Exception e) {
					log.error("", e);
				}
			}
		}*/
    // start found forums in groups
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams(ureqIdentity, true, true);
    params.addTools(CollaborationTools.TOOL_FOLDER);
    List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
    for (BusinessGroup group : groups) {
        CollaborationTools tools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(group);
        VFSContainer container = tools.getSecuredFolder(group, null, ureqIdentity, false);
        FolderVO folderVo = new FolderVO();
        folderVo.setName(group.getName());
        folderVo.setGroupKey(group.getKey());
        folderVo.setSubscribed(groupNotified.containsKey(group.getKey()));
        folderVo.setRead(container.getLocalSecurityCallback().canRead());
        folderVo.setList(container.getLocalSecurityCallback().canList());
        folderVo.setWrite(container.getLocalSecurityCallback().canWrite());
        folderVo.setDelete(container.getLocalSecurityCallback().canDelete());
        folderVOs.add(folderVo);
    }
    FolderVOes voes = new FolderVOes();
    voes.setFolders(folderVOs.toArray(new FolderVO[folderVOs.size()]));
    voes.setTotalCount(folderVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) FolderVOes(org.olat.restapi.support.vo.FolderVOes) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HashMap(java.util.HashMap) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) Subscriber(org.olat.core.commons.services.notifications.Subscriber) List(java.util.List) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) FolderVO(org.olat.restapi.support.vo.FolderVO) BusinessGroup(org.olat.group.BusinessGroup) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) VFSContainer(org.olat.core.util.vfs.VFSContainer) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BCCourseNode(org.olat.course.nodes.BCCourseNode) BusinessGroupService(org.olat.group.BusinessGroupService) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) CollaborationTools(org.olat.collaboration.CollaborationTools) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 19 with BusinessGroupService

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

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 20 with BusinessGroupService

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

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