Search in sources :

Example 6 with Subscriber

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

the class NotificationsManagerImpl method markPublisherNews.

/**
 * call this method to indicate that there is news for the given
 * subscriptionContext
 *
 * @param subscriptionContext
 * @param ignoreNewsFor
 */
@Override
public void markPublisherNews(final SubscriptionContext subscriptionContext, Identity ignoreNewsFor, boolean sendEvents) {
    // to make sure: ignore if no subscriptionContext
    if (subscriptionContext == null)
        return;
    Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
    if (toUpdate == null) {
        return;
    }
    toUpdate.setLatestNewsDate(new Date());
    Publisher publisher = dbInstance.getCurrentEntityManager().merge(toUpdate);
    // commit the select for update
    dbInstance.commit();
    // user
    if (ignoreNewsFor != null) {
        markSubscriberRead(ignoreNewsFor, publisher);
    }
    if (sendEvents) {
        // commit all things on the database
        dbInstance.commit();
        // channel-notify all interested listeners (e.g. the pnotificationsportletruncontroller)
        // 1. find all subscribers which can be affected
        List<Subscriber> subscribers = getValidSubscribersOf(publisher);
        Set<Long> subsKeys = new HashSet<Long>();
        // 2. collect all keys of the affected subscribers
        for (Subscriber subscriber : subscribers) {
            subsKeys.add(subscriber.getKey());
        }
        // fire the event
        MultiUserEvent mue = EventFactory.createAffectedEvent(subsKeys);
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(mue, oresMyself);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Publisher(org.olat.core.commons.services.notifications.Publisher) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) Date(java.util.Date) HashSet(java.util.HashSet)

Example 7 with Subscriber

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

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 8 with Subscriber

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

the class NotificationSubscriptionController method updateSubscriptionsDataModel.

/**
 * Update the table model
 *
 * @param ureq
 */
void updateSubscriptionsDataModel() {
    // Load subscriptions from DB. Don't use the ureq.getIdentity() but the
    // subscriberIdentity instead to make this controller also be usable in the
    // admin environment (admins might change notifications for a user)
    NotificationsManager man = NotificationsManager.getInstance();
    List<Subscriber> subs = man.getSubscribers(subscriberIdentity);
    for (Iterator<Subscriber> subIt = subs.iterator(); subIt.hasNext(); ) {
        Subscriber sub = subIt.next();
        if (!man.isPublisherValid(sub.getPublisher())) {
            subIt.remove();
        }
    }
    subscriptionsTableModel.setObjects(subs);
    // Tell table about model change or set table model if not already set
    if (subscriptionsTableCtr.getTableDataModel() == null) {
        subscriptionsTableCtr.setTableDataModel(subscriptionsTableModel);
    } else {
        subscriptionsTableCtr.modelChanged(true);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager)

Example 9 with Subscriber

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

the class NotificationNewsController method updateNewsDataModel.

/**
 * Update the new data model and refresh the GUI
 */
protected List<Subscriber> updateNewsDataModel() {
    if (compareDate == null) {
        // compare date is mandatory
        return Collections.emptyList();
    }
    List<String> notiTypes = new ArrayList<>();
    if (StringHelper.containsNonWhitespace(newsType) && !newsType.equals("all")) {
        notiTypes.add(newsType);
    }
    NotificationsManager man = NotificationsManager.getInstance();
    List<Subscriber> subs = man.getSubscribers(subscriberIdentity, notiTypes);
    newsVC.contextPut("subs", subs);
    subsInfoMap = NotificationHelper.getSubscriptionMap(getLocale(), true, compareDate, subs);
    NotificationSubscriptionAndNewsFormatter subsFormatter = new NotificationSubscriptionAndNewsFormatter(getTranslator(), subsInfoMap);
    newsVC.contextPut("subsFormatter", subsFormatter);
    return subs;
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) ArrayList(java.util.ArrayList)

Example 10 with Subscriber

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

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)

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