Search in sources :

Example 36 with NotificationsManager

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

the class NotificationsWebService method getNotifications.

/**
 * Retrieves the notification of the logged in user.
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The notifications
 * @response.representation.200.example {@link org.olat.core.commons.services.notifications.restapi.vo.Examples#SAMPLE_INFOVOes}
 * @response.representation.404.doc The identity not found
 * @param date The date (optional)
 * @param type The type of notifications (User, Forum...) (optional)
 * @param httpRequest The HTTP request
 * @return an xml or json representation of a the user being search. The xml
 *         correspond to a <code>SubscriptionInfoVO</code>. <code>SubscriptionInfoVO</code>
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getNotifications(@QueryParam("date") String date, @QueryParam("type") String type, @Context HttpServletRequest httpRequest) {
    Identity identity = RestSecurityHelper.getIdentity(httpRequest);
    Locale locale = RestSecurityHelper.getLocale(httpRequest);
    Date compareDate;
    if (StringHelper.containsNonWhitespace(date)) {
        compareDate = parseDate(date, locale);
    } else {
        NotificationsManager man = NotificationsManager.getInstance();
        compareDate = man.getCompareDateFromInterval(man.getUserIntervalOrDefault(identity));
    }
    List<String> types = new ArrayList<String>(1);
    if (StringHelper.containsNonWhitespace(type)) {
        types.add(type);
    }
    Map<Subscriber, SubscriptionInfo> subsInfoMap = NotificationHelper.getSubscriptionMap(identity, locale, true, compareDate, types);
    List<SubscriptionInfoVO> voes = new ArrayList<SubscriptionInfoVO>();
    for (Map.Entry<Subscriber, SubscriptionInfo> entry : subsInfoMap.entrySet()) {
        SubscriptionInfo info = entry.getValue();
        if (info.hasNews()) {
            Subscriber subscriber = entry.getKey();
            voes.add(createSubscriptionInfoVO(subscriber.getPublisher(), info));
        }
    }
    SubscriptionInfoVO[] voesArr = new SubscriptionInfoVO[voes.size()];
    voes.toArray(voesArr);
    return Response.ok(voesArr).build();
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Date(java.util.Date) RestSecurityHelper.parseDate(org.olat.restapi.security.RestSecurityHelper.parseDate) SubscriptionInfoVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriptionInfoVO) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) Identity(org.olat.core.id.Identity) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with NotificationsManager

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

the class ModifyCourseEvent method clearCalenderSubscriptions.

/**
 * Checks all learning group calendars and the course calendar for publishers (of subscriptions)
 * and sets their state to "1" which indicates that the ressource is deleted.
 */
private static void clearCalenderSubscriptions(OLATResourceable res, ICourse course) {
    // set Publisher state to 1 (= ressource is deleted) for all calendars of the course
    CalendarManager calMan = CoreSpringFactory.getImpl(CalendarManager.class);
    CalendarNotificationManager notificationManager = CoreSpringFactory.getImpl(CalendarNotificationManager.class);
    NotificationsManager nfm = NotificationsManager.getInstance();
    if (course != null) {
        CourseGroupManager courseGroupManager = course.getCourseEnvironment().getCourseGroupManager();
        List<BusinessGroup> learningGroups = courseGroupManager.getAllBusinessGroups();
        // all learning and right group calendars
        for (BusinessGroup bg : learningGroups) {
            KalendarRenderWrapper calRenderWrapper = calMan.getGroupCalendar(bg);
            SubscriptionContext subsContext = notificationManager.getSubscriptionContext(calRenderWrapper);
            Publisher pub = nfm.getPublisher(subsContext);
            if (pub != null) {
                // int 0 is OK -> all other is not OK
                pub.setState(1);
            }
        }
    }
    // the course calendar
    try {
        /**
         * TODO:gs 2010-01-26
         * OLAT-4947: if we do not have an repo entry we get an exception here.
         * This is normal in the case of courseimport and click canceling.
         */
        KalendarRenderWrapper courseCalendar = calMan.getCalendarForDeletion(res);
        if (courseCalendar != null) {
            SubscriptionContext subContext = notificationManager.getSubscriptionContext(courseCalendar, res);
            OLATResourceable oresToDelete = OresHelper.createOLATResourceableInstance(subContext.getResName(), subContext.getResId());
            nfm.deletePublishersOf(oresToDelete);
        }
    } catch (AssertException e) {
    // if we have a broken course (e.g. canceled import or no repo entry somehow) skip calendar deletion...
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) PersistingCourseGroupManager(org.olat.course.groupsandrights.PersistingCourseGroupManager) ImportToCalendarManager(org.olat.commons.calendar.manager.ImportToCalendarManager) CalendarManager(org.olat.commons.calendar.CalendarManager) CalendarNotificationManager(org.olat.commons.calendar.CalendarNotificationManager) AssertException(org.olat.core.logging.AssertException) BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 38 with NotificationsManager

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

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

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

the class BCWebService method getFolders.

/**
 * Retrieves metadata of the course node
 * @response.representation.200.qname {http://www.example.com}folderVOes
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The course node metadatas
 * @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
 * @response.representation.404.doc The course or parentNode not found
 * @param courseId The course resourceable's id
 * @param nodeId The node's id
 * @param httpRequest The HTTP request
 * @return The persisted structure element (fully populated)
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getFolders(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
    final ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    } else if (!CourseWebService.isCourseAccessible(course, false, httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final UserRequest ureq = getUserRequest(httpRequest);
    RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
    ACService acManager = CoreSpringFactory.getImpl(ACService.class);
    AccessResult result = acManager.isAccessible(entry, ureq.getIdentity(), false);
    if (!result.isAccessible()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    final Set<String> subscribed = new HashSet<String>();
    NotificationsManager man = NotificationsManager.getInstance();
    List<String> notiTypes = Collections.singletonList("FolderModule");
    List<Subscriber> subs = man.getSubscribers(ureq.getIdentity(), notiTypes);
    for (Subscriber sub : subs) {
        Long courseKey = sub.getPublisher().getResId();
        if (courseId.equals(courseKey)) {
            subscribed.add(sub.getPublisher().getSubidentifier());
            break;
        }
    }
    final List<FolderVO> folderVOs = new ArrayList<FolderVO>();
    new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment()).visit(new Visitor() {

        @Override
        public void visit(INode node) {
            if (node instanceof BCCourseNode) {
                BCCourseNode bcNode = (BCCourseNode) node;
                FolderVO folder = createFolderVO(ureq.getUserSession().getIdentityEnvironment(), course, bcNode, subscribed);
                folderVOs.add(folder);
            }
        }
    }, new VisibleTreeFilter());
    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) FolderVO(org.olat.restapi.support.vo.FolderVO) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) BCCourseNode(org.olat.course.nodes.BCCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ACService(org.olat.resource.accesscontrol.ACService) AccessResult(org.olat.resource.accesscontrol.AccessResult) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with NotificationsManager

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

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)

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