Search in sources :

Example 56 with Subscriber

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

the class NotificationsManagerImpl method markSubscriberRead.

private Subscriber markSubscriberRead(Identity identity, Publisher p) {
    Subscriber sub = getSubscriber(identity, p);
    if (sub != null) {
        sub.setLastModified(new Date());
        sub = dbInstance.getCurrentEntityManager().merge(sub);
    }
    return sub;
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Date(java.util.Date)

Example 57 with Subscriber

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

the class NotificationsManagerImpl method subscribe.

@Override
public void subscribe(List<Identity> identities, SubscriptionContext subscriptionContext, PublisherData publisherData) {
    if (identities == null || identities.isEmpty())
        return;
    Publisher toUpdate = getPublisherForUpdate(subscriptionContext);
    if (toUpdate == null) {
        // create the publisher
        findOrCreatePublisher(subscriptionContext, publisherData);
        // lock the publisher
        toUpdate = getPublisherForUpdate(subscriptionContext);
    }
    for (Identity identity : identities) {
        Subscriber s = getSubscriber(identity, toUpdate);
        if (s == null) {
            // no subscriber -> create.
            // s.latestReadDate >= p.latestNewsDate == no news for subscriber when no
            // news after subscription time
            doCreateAndPersistSubscriber(toUpdate, identity);
        }
    }
    dbInstance.commit();
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Publisher(org.olat.core.commons.services.notifications.Publisher) Identity(org.olat.core.id.Identity)

Example 58 with Subscriber

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

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

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

the class DateChooserController method setSubscribers.

public void setSubscribers(List<Subscriber> subscribers) {
    String selectedKey = typeSelection.isOneSelected() ? typeSelection.getSelectedKey() : null;
    Set<String> types = new HashSet<String>();
    for (Subscriber subscriber : subscribers) {
        String type = subscriber.getPublisher().getType();
        types.add(type);
    }
    typeKeys = new String[types.size() + 1];
    typeValues = new String[types.size() + 1];
    typeKeys[0] = "all";
    typeValues[0] = translate("news.type.all");
    int count = 1;
    for (String type : types) {
        String typeName = NewControllerFactory.translateResourceableTypeName(type, getLocale());
        typeKeys[count] = type;
        typeValues[count++] = typeName;
    }
    typeSelection.setKeysAndValues(typeKeys, typeValues, null);
    if (selectedKey != null) {
        // select the current key but check if it still exists
        for (String typeKey : typeKeys) {
            if (typeKey.equals(selectedKey)) {
                typeSelection.select(selectedKey, true);
                break;
            }
        }
    }
    if (!typeSelection.isOneSelected()) {
        typeSelection.select("all", true);
    }
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) HashSet(java.util.HashSet)

Example 60 with Subscriber

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

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)

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