Search in sources :

Example 91 with Publisher

use of org.olat.core.commons.services.notifications.Publisher 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 92 with Publisher

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

the class InfoSubscriptionManagerImpl method getInfoSubscribers.

@Override
public List<Identity> getInfoSubscribers(OLATResourceable resource, String subPath) {
    SubscriptionContext context = getInfoSubscriptionContext(resource, subPath);
    Publisher publisher = notificationsManager.getPublisher(context);
    if (publisher == null) {
        return Collections.emptyList();
    }
    return notificationsManager.getSubscriberIdentities(publisher);
}
Also used : SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 93 with Publisher

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

the class NotificationsManagerImpl method getPublisher.

/**
 * @param subsContext
 * @return the publisher belonging to the given context or null
 */
@Override
public Publisher getPublisher(SubscriptionContext subsContext) {
    StringBuilder q = new StringBuilder();
    q.append("select pub from notipublisher pub ").append(" where pub.resName=:resName and pub.resId = :resId");
    if (StringHelper.containsNonWhitespace(subsContext.getSubidentifier())) {
        q.append(" and pub.subidentifier=:subidentifier");
    } else {
        q.append(" and (pub.subidentifier='' or pub.subidentifier is null)");
    }
    TypedQuery<Publisher> query = dbInstance.getCurrentEntityManager().createQuery(q.toString(), Publisher.class).setParameter("resName", subsContext.getResName()).setParameter("resId", subsContext.getResId());
    if (StringHelper.containsNonWhitespace(subsContext.getSubidentifier())) {
        query.setParameter("subidentifier", subsContext.getSubidentifier());
    }
    List<Publisher> res = query.getResultList();
    if (res.isEmpty())
        return null;
    if (res.size() != 1)
        throw new AssertException("only one subscriber per person and publisher!!");
    return res.get(0);
}
Also used : AssertException(org.olat.core.logging.AssertException) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 94 with Publisher

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

the class NotificationsManagerImpl method unsubscribe.

/**
 * @param identity
 * @param subscriptionContext
 */
@Override
public void unsubscribe(Identity identity, SubscriptionContext subscriptionContext) {
    Publisher p = getPublisherForUpdate(subscriptionContext);
    if (p != null) {
        Subscriber s = getSubscriber(identity, p);
        if (s != null) {
            deleteSubscriber(s);
        } else {
            logWarn("could not unsubscribe " + identity.getName() + " from publisher:" + p.getResName() + "," + p.getResId() + "," + p.getSubidentifier(), null);
        }
    }
    dbInstance.commit();
}
Also used : Subscriber(org.olat.core.commons.services.notifications.Subscriber) Publisher(org.olat.core.commons.services.notifications.Publisher)

Example 95 with Publisher

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

Aggregations

Publisher (org.olat.core.commons.services.notifications.Publisher)150 Identity (org.olat.core.id.Identity)62 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)60 PublisherData (org.olat.core.commons.services.notifications.PublisherData)44 SubscriptionInfo (org.olat.core.commons.services.notifications.SubscriptionInfo)44 Date (java.util.Date)42 Test (org.junit.Test)42 Subscriber (org.olat.core.commons.services.notifications.Subscriber)42 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)38 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Translator (org.olat.core.gui.translator.Translator)30 TitleItem (org.olat.core.commons.services.notifications.model.TitleItem)28 OLATResourceable (org.olat.core.id.OLATResourceable)18 ICourse (org.olat.course.ICourse)18 BusinessGroup (org.olat.group.BusinessGroup)16 ArrayList (java.util.ArrayList)14 NotificationsManager (org.olat.core.commons.services.notifications.NotificationsManager)14 NotificationsHandler (org.olat.core.commons.services.notifications.NotificationsHandler)12 AssertException (org.olat.core.logging.AssertException)12 CourseNode (org.olat.course.nodes.CourseNode)8