Search in sources :

Example 26 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.

the class BCCourseNodeEditForm method updatePublisher.

private void updatePublisher(VFSContainer container) {
    File realFile = VFSManager.getRealFile(container);
    String relPath = new File(FolderConfig.getCanonicalRoot()).toPath().relativize(realFile.toPath()).toString();
    NotificationsManager notifManager = NotificationsManager.getInstance();
    SubscriptionContext nodefolderSubContext = CourseModule.createSubscriptionContext(course.getCourseEnvironment(), node);
    Publisher publisher = notifManager.getPublisher(nodefolderSubContext);
    if (publisher != null) {
        String businessPath = getWindowControl().getBusinessControl().getAsString();
        String data = "/" + relPath;
        PublisherData pdata = new PublisherData(OresHelper.calculateTypeName(BCCourseNode.class), data, businessPath);
        notifManager.updatePublisherData(nodefolderSubContext, pdata);
    }
}
Also used : BCCourseNode(org.olat.course.nodes.BCCourseNode) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) File(java.io.File) PublisherData(org.olat.core.commons.services.notifications.PublisherData)

Example 27 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project OpenOLAT by OpenOLAT.

the class InfoCourseNode method cleanupOnDelete.

@Override
public /**
 * is called when deleting this node, clean up info-messages and subscriptions!
 */
void cleanupOnDelete(ICourse course) {
    super.cleanupOnDelete(course);
    // delete infoMessages and subscriptions (OLAT-6171)
    String resSubpath = getIdent();
    InfoMessageFrontendManager infoService = CoreSpringFactory.getImpl(InfoMessageFrontendManager.class);
    List<InfoMessage> messages = infoService.loadInfoMessageByResource(course, resSubpath, null, null, null, 0, 0);
    for (InfoMessage im : messages) {
        infoService.deleteInfoMessage(im);
    }
    final SubscriptionContext subscriptionContext = CourseModule.createTechnicalSubscriptionContext(course.getCourseEnvironment(), this);
    NotificationsManager notifManagar = NotificationsManager.getInstance();
    notifManagar.delete(subscriptionContext);
    super.cleanupOnDelete(course);
}
Also used : InfoMessageFrontendManager(org.olat.commons.info.InfoMessageFrontendManager) InfoMessage(org.olat.commons.info.InfoMessage) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 28 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.

the class CoursesInfosWebService method collectSubscriptions.

private void collectSubscriptions(Identity identity, Set<Long> forumNotified, Map<Long, Set<String>> courseNotified) {
    NotificationsManager man = NotificationsManager.getInstance();
    {
        // collect subscriptions
        List<String> notiTypes = new ArrayList<String>();
        notiTypes.add("FolderModule");
        notiTypes.add("Forum");
        List<Subscriber> subs = man.getSubscribers(identity, notiTypes);
        for (Subscriber sub : subs) {
            String publisherType = sub.getPublisher().getType();
            String resName = sub.getPublisher().getResName();
            if ("CourseModule".equals(resName)) {
                if ("FolderModule".equals(publisherType)) {
                    Long courseKey = sub.getPublisher().getResId();
                    if (!courseNotified.containsKey(courseKey)) {
                        courseNotified.put(courseKey, new HashSet<String>());
                    }
                    courseNotified.get(courseKey).add(sub.getPublisher().getSubidentifier());
                } else if ("Forum".equals(publisherType)) {
                    Long forumKey = Long.parseLong(sub.getPublisher().getData());
                    forumNotified.add(forumKey);
                }
            }
        }
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 29 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.

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 30 with NotificationsManager

use of org.olat.core.commons.services.notifications.NotificationsManager in project openolat by klemens.

the class OLATUpgrade_7_0_1 method migrateNotificationPublishers.

private void migrateNotificationPublishers(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
    if (!uhd.getBooleanDataValue(TASK_CHECK_NOTIFICATIONS)) {
        log.audit("+-----------------------------------------------------------------------------+");
        log.audit("+... Check the businesspath for the publishers (notifications)             ...+");
        log.audit("+-----------------------------------------------------------------------------+");
        int counter = 0;
        NotificationsManager notificationMgr = NotificationsManager.getInstance();
        List<Publisher> allPublishers = notificationMgr.getAllPublisher();
        if (log.isDebug())
            log.info("Found " + allPublishers.size() + " publishers to check.");
        for (Publisher publisher : allPublishers) {
            if (publisher != null && StringHelper.containsNonWhitespace(publisher.getBusinessPath()) && (publisher.getBusinessPath().startsWith("[Identity") || publisher.getBusinessPath().startsWith("ROOT[Identity"))) {
                try {
                    String businessPath = publisher.getBusinessPath();
                    int startIndex = businessPath.indexOf("[Identity");
                    int stopIndex = businessPath.indexOf("]", startIndex);
                    int wide = stopIndex - startIndex;
                    if (wide > 30) {
                        // Identity:326394598 cannot be too wide
                        continue;
                    } else if (stopIndex + 1 >= businessPath.length()) {
                        // only identity
                        continue;
                    }
                    String correctPath = businessPath.substring(stopIndex + 1);
                    publisher.setBusinessPath(correctPath);
                    DBFactory.getInstance().updateObject(publisher);
                } catch (ObjectDeletedException e) {
                    log.warn("Publisher was already deleted, no update possible! Publisher key: " + publisher.getKey());
                } catch (Exception e) {
                    log.warn("Publisher was already deleted, no update possible! Publisher key: " + publisher.getKey());
                }
                counter++;
            }
            if (counter > 0 && counter % 100 == 0) {
                log.audit("Another 100 publishers done");
                DBFactory.getInstance().intermediateCommit();
            }
        }
        DBFactory.getInstance().intermediateCommit();
        log.audit("**** Checked " + counter + " publishers. ****");
        uhd.setBooleanDataValue(TASK_CHECK_NOTIFICATIONS, true);
        upgradeManager.setUpgradesHistory(uhd, VERSION);
    }
}
Also used : NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ObjectDeletedException(org.hibernate.ObjectDeletedException) Publisher(org.olat.core.commons.services.notifications.Publisher) ObjectDeletedException(org.hibernate.ObjectDeletedException)

Aggregations

NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)42 Subscriber (org.olat.core.commons.services.notifications.Subscriber)24 ArrayList (java.util.ArrayList)18 GET (javax.ws.rs.GET)18 Produces (javax.ws.rs.Produces)18 HashSet (java.util.HashSet)12 Publisher (org.olat.core.commons.services.notifications.Publisher)12 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)12 ICourse (org.olat.course.ICourse)12 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)12 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)12 Path (javax.ws.rs.Path)10 UserRequest (org.olat.core.gui.UserRequest)8 Identity (org.olat.core.id.Identity)8 INode (org.olat.core.util.nodes.INode)8 Visitor (org.olat.core.util.tree.Visitor)8 BCCourseNode (org.olat.course.nodes.BCCourseNode)8 RestSecurityHelper.getUserRequest (org.olat.restapi.security.RestSecurityHelper.getUserRequest)8 List (java.util.List)6 Map (java.util.Map)6