Search in sources :

Example 71 with Subscriber

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

the class NotificationSubscriptionController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == subscriptionsTableCtr) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            Subscriber sub = subscriptionsTableModel.getObject(te.getRowId());
            if (actionid.equals("launch")) {
                // User want to go to the subscription source, e.g. the forum or the
                // folder
                NotificationUIFactory.launchSubscriptionResource(ureq, getWindowControl(), sub);
            } else if (actionid.equals("del")) {
                delYesNoC = activateYesNoDialog(ureq, null, translate("confirm.delete"), delYesNoC);
                delYesNoC.setUserObject(sub);
                return;
            }
        }
    } else if (source == delYesNoC) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // ok
            // Remove subscription and update data model
            Subscriber sub = (Subscriber) delYesNoC.getUserObject();
            NotificationsManager.getInstance().unsubscribe(sub);
            updateSubscriptionsDataModel();
            showInfo("info.notification.deleted");
            // Notify parent controller
            fireEvent(ureq, Event.CHANGED_EVENT);
        }
        // cleanup dialog
        delYesNoC.dispose();
        delYesNoC = null;
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) Subscriber(org.olat.core.commons.services.notifications.Subscriber)

Example 72 with Subscriber

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

the class NotificationsPortletRunController method reloadModel.

/**
 * @see org.olat.core.gui.control.generic.portal.AbstractPortletRunController#reloadModel(org.olat.core.gui.UserRequest, org.olat.core.gui.control.generic.portal.SortingCriteria)
 */
protected void reloadModel(SortingCriteria sortingCriteria) {
    if (sortingCriteria.getSortingType() == SortingCriteria.AUTO_SORTING) {
        Map<Subscriber, SubscriptionInfo> subscriptionMap = NotificationHelper.getSubscriptionMap(getIdentity(), getLocale(), true, compareDate);
        notificationsList = new ArrayList<Subscriber>();
        for (Iterator<Map.Entry<Subscriber, SubscriptionInfo>> it_subs = subscriptionMap.entrySet().iterator(); it_subs.hasNext(); ) {
            Map.Entry<Subscriber, SubscriptionInfo> sInfo = it_subs.next();
            Subscriber subscrer = sInfo.getKey();
            SubscriptionInfo infos = sInfo.getValue();
            if (infos.hasNews()) {
                notificationsList.add(subscrer);
            }
        }
        notificationsList = getSortedList(notificationsList, sortingCriteria);
        List<PortletEntry<Subscriber>> entries = convertNotificationToPortletEntryList(notificationsList);
        notificationListModel = new NotificationsPortletTableDataModel(entries, getLocale(), subscriptionMap);
        tableCtr.setTableDataModel(notificationListModel);
    } else {
        reloadModel(getPersistentManuallySortedItems());
    }
}
Also used : PortletEntry(org.olat.core.gui.control.generic.portal.PortletEntry) PortletEntry(org.olat.core.gui.control.generic.portal.PortletEntry) Subscriber(org.olat.core.commons.services.notifications.Subscriber) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Map(java.util.Map)

Example 73 with Subscriber

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

the class NotificationsPortletRunController method getAllPortletEntries.

private List<PortletEntry<Subscriber>> getAllPortletEntries() {
    notificationsList = man.getValidSubscribers(getIdentity());
    // calc subscriptioninfo for all subscriptions and, if only those with news are to be shown, remove the other ones
    for (Iterator<Subscriber> it_subs = notificationsList.iterator(); it_subs.hasNext(); ) {
        Subscriber subscriber = it_subs.next();
        Publisher pub = subscriber.getPublisher();
        NotificationsHandler notifHandler = man.getNotificationsHandler(pub);
        if (notifHandler == null) {
            it_subs.remove();
        } else {
            SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, getLocale(), compareDate);
            if (!subsInfo.hasNews()) {
                it_subs.remove();
            }
        }
    }
    return convertNotificationToPortletEntryList(notificationsList);
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 74 with Subscriber

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

the class NotificationsWebService method getSubscriber.

@GET
@Path("subscribers/{ressourceName}/{ressourceId}/{subIdentifier}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getSubscriber(@PathParam("ressourceName") String ressourceName, @PathParam("ressourceId") Long ressourceId, @PathParam("subIdentifier") String subIdentifier, @Context HttpServletRequest request) {
    if (!isAdmin(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    NotificationsManager notificationsMgr = NotificationsManager.getInstance();
    SubscriptionContext subsContext = new SubscriptionContext(ressourceName, ressourceId, subIdentifier);
    Publisher publisher = notificationsMgr.getPublisher(subsContext);
    if (publisher == null) {
        return Response.ok().status(Status.NO_CONTENT).build();
    }
    List<Subscriber> subscribers = notificationsMgr.getSubscribers(publisher);
    SubscriberVO[] subscriberVoes = new SubscriberVO[subscribers.size()];
    int count = 0;
    for (Subscriber subscriber : subscribers) {
        SubscriberVO subscriberVO = new SubscriberVO();
        subscriberVO.setPublisherKey(publisher.getKey());
        subscriberVO.setSubscriberKey(subscriber.getKey());
        subscriberVO.setIdentityKey(subscriber.getIdentity().getKey());
        subscriberVoes[count++] = subscriberVO;
    }
    return Response.ok(subscriberVoes).build();
}
Also used : SubscriberVO(org.olat.core.commons.services.notifications.restapi.vo.SubscriberVO) Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 75 with Subscriber

use of org.olat.core.commons.services.notifications.Subscriber 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)

Aggregations

Subscriber (org.olat.core.commons.services.notifications.Subscriber)82 Publisher (org.olat.core.commons.services.notifications.Publisher)42 Identity (org.olat.core.id.Identity)30 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)26 ArrayList (java.util.ArrayList)24 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)22 HashSet (java.util.HashSet)18 Test (org.junit.Test)18 PublisherData (org.olat.core.commons.services.notifications.PublisherData)18 Date (java.util.Date)16 GET (javax.ws.rs.GET)16 Produces (javax.ws.rs.Produces)16 ICourse (org.olat.course.ICourse)16 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)16 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)16 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)10 Roles (org.olat.core.id.Roles)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10 List (java.util.List)8 Locale (java.util.Locale)8