Search in sources :

Example 26 with SubscriptionInfo

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

the class NotificationSubscriptionAndNewsFormatter method getTitle.

private String getTitle(Subscriber sub, String mimeType) {
    SubscriptionInfo subsInfo = subsInfoMap.get(sub);
    if (subsInfo == null)
        return "";
    String title = subsInfo.getTitle(mimeType);
    return title;
}
Also used : SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo)

Example 27 with SubscriptionInfo

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

the class InfoMessageNotificationHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    // can't be loaded when already deleted
    if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
        try {
            final Long resId = subscriber.getPublisher().getResId();
            final String resName = subscriber.getPublisher().getResName();
            String resSubPath = subscriber.getPublisher().getSubidentifier();
            String displayName, notificationtitle;
            if ("BusinessGroup".equals(resName)) {
                BusinessGroupService groupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
                BusinessGroup group = groupService.loadBusinessGroup(resId);
                displayName = group.getName();
                notificationtitle = "notification.title.group";
            } else {
                RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(resName, resId), false);
                if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return NotificationsManager.getInstance().getNoSubscriptionInfo();
                }
                displayName = re.getDisplayname();
                notificationtitle = "notification.title";
            }
            Translator translator = Util.createPackageTranslator(this.getClass(), locale);
            String title = translator.translate(notificationtitle, new String[] { displayName });
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, CSS_CLASS_ICON), null);
            OLATResourceable ores = OresHelper.createOLATResourceableInstance(resName, resId);
            List<InfoMessage> infos = infoMessageManager.loadInfoMessageByResource(ores, resSubPath, null, compareDate, null, 0, 0);
            for (InfoMessage info : infos) {
                Identity ident = info.getAuthor();
                String desc = translator.translate("notifications.entry", new String[] { info.getTitle(), NotificationHelper.getFormatedName(ident) });
                String tooltip = info.getMessage();
                String infoBusinessPath = info.getBusinessPath() + "[InfoMessage:" + info.getKey() + "]";
                String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(infoBusinessPath);
                Date dateInfo = info.getModificationDate() == null ? info.getCreationDate() : info.getModificationDate();
                SubscriptionListItem subListItem = new SubscriptionListItem(desc, tooltip, urlToSend, infoBusinessPath, dateInfo, CSS_CLASS_ICON);
                si.addSubscriptionListItem(subListItem);
            }
        } catch (Exception e) {
            log.error("Unexpected exception", e);
            si = NotificationsManager.getInstance().getNoSubscriptionInfo();
        }
    } else {
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
    return si;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) OLATResourceable(org.olat.core.id.OLATResourceable) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) BusinessGroupService(org.olat.group.BusinessGroupService) Translator(org.olat.core.gui.translator.Translator) InfoMessage(org.olat.commons.info.InfoMessage) Identity(org.olat.core.id.Identity)

Example 28 with SubscriptionInfo

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

the class InfoMessagePortletRunController method reloadModel.

@Override
protected void reloadModel(SortingCriteria criteria) {
    List<SubscriptionInfo> infos = NotificationsManager.getInstance().getSubscriptionInfos(getIdentity(), "InfoMessage");
    List<InfoSubscriptionItem> items = new ArrayList<InfoSubscriptionItem>();
    for (SubscriptionInfo info : infos) {
        for (SubscriptionListItem item : info.getSubscriptionListItems()) {
            items.add(new InfoSubscriptionItem(info, item));
        }
    }
    items = getSortedList(items, criteria);
    List<PortletEntry<InfoSubscriptionItem>> entries = convertToPortletEntryList(items);
    InfosTableModel model = new InfosTableModel(entries);
    tableController.setTableDataModel(model);
}
Also used : PortletEntry(org.olat.core.gui.control.generic.portal.PortletEntry) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) ArrayList(java.util.ArrayList) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo)

Example 29 with SubscriptionInfo

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

the class NotificationsManagerImpl method createSubscriptionItem.

/**
 * @param subscriber
 * @param locale
 * @param mimeType
 * @param latestEmailed needs to be given! SubscriptionInfo is collected from then until latestNews of publisher
 * @return null if the publisher is not valid anymore (deleted), or if there are no news
 */
@Override
public SubscriptionItem createSubscriptionItem(Subscriber subscriber, Locale locale, String mimeTypeTitle, String mimeTypeContent, Date latestEmailed) {
    if (latestEmailed == null)
        throw new AssertException("compareDate may not be null, use a date from history");
    try {
        boolean debug = isLogDebugEnabled();
        SubscriptionItem si = null;
        Publisher pub = subscriber.getPublisher();
        NotificationsHandler notifHandler = getNotificationsHandler(pub);
        if (debug)
            logDebug("create subscription with handler: " + notifHandler.getClass().getName());
        // do not create subscription item when deleted
        if (isPublisherValid(pub) && notifHandler != null) {
            if (debug)
                logDebug("NotifHandler: " + notifHandler.getClass().getName() + " compareDate: " + latestEmailed.toString() + " now: " + new Date().toString(), null);
            SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, locale, latestEmailed);
            if (subsInfo.hasNews()) {
                si = createSubscriptionItem(subsInfo, subscriber, locale, mimeTypeTitle, mimeTypeContent);
            }
        }
        return si;
    } catch (Exception e) {
        log.error("Cannot generate a subscription item.", e);
        return null;
    }
}
Also used : SubscriptionItem(org.olat.core.commons.services.notifications.SubscriptionItem) AssertException(org.olat.core.logging.AssertException) NotificationsHandler(org.olat.core.commons.services.notifications.NotificationsHandler) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) NoSubscriptionInfo(org.olat.core.commons.services.notifications.model.NoSubscriptionInfo) Publisher(org.olat.core.commons.services.notifications.Publisher) Date(java.util.Date) AssertException(org.olat.core.logging.AssertException)

Example 30 with SubscriptionInfo

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

Aggregations

SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)56 Publisher (org.olat.core.commons.services.notifications.Publisher)44 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)38 Date (java.util.Date)36 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)28 Identity (org.olat.core.id.Identity)24 RepositoryEntry (org.olat.repository.RepositoryEntry)18 ArrayList (java.util.ArrayList)10 Subscriber (org.olat.core.commons.services.notifications.Subscriber)10 OLATResourceable (org.olat.core.id.OLATResourceable)10 ICourse (org.olat.course.ICourse)10 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)8 Locale (java.util.Locale)6 FileInfo (org.olat.core.commons.modules.bc.FileInfo)6 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)6 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)6 SubscriptionItem (org.olat.core.commons.services.notifications.SubscriptionItem)6 NoSubscriptionInfo (org.olat.core.commons.services.notifications.model.NoSubscriptionInfo)6 AssertException (org.olat.core.logging.AssertException)6