use of org.olat.core.commons.services.notifications.SubscriptionItem in project OpenOLAT by OpenOLAT.
the class NotificationNewsController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.Component,
* org.olat.core.gui.control.Event)
*/
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == emailLink) {
// send email to user with the currently visible date
NotificationsManager man = NotificationsManager.getInstance();
List<SubscriptionItem> infoList = new ArrayList<>();
List<Subscriber> subsList = new ArrayList<>();
for (Subscriber subscriber : subsInfoMap.keySet()) {
subsList.add(subscriber);
SubscriptionItem item = man.createSubscriptionItem(subscriber, getLocale(), SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML, compareDate);
if (item != null) {
infoList.add(item);
}
}
if (man.sendMailToUserAndUpdateSubscriber(subscriberIdentity, infoList, getTranslator(), subsList)) {
showInfo("email.ok");
} else {
showError("email.nok");
}
}
}
use of org.olat.core.commons.services.notifications.SubscriptionItem 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;
}
}
use of org.olat.core.commons.services.notifications.SubscriptionItem in project openolat by klemens.
the class NotificationSubscriptionAndNewsFormatter method getSubscriptionItem.
public SubscriptionItem getSubscriptionItem(Subscriber sub) {
SubscriptionInfo subsInfo = subsInfoMap.get(sub);
NotificationsManager notiMgr = NotificationsManager.getInstance();
SubscriptionItem subscrItem = notiMgr.createSubscriptionItem(subsInfo, sub, translator.getLocale(), SubscriptionInfo.MIME_HTML, SubscriptionInfo.MIME_HTML);
return subscrItem;
}
use of org.olat.core.commons.services.notifications.SubscriptionItem in project openolat by klemens.
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;
}
}
use of org.olat.core.commons.services.notifications.SubscriptionItem in project openolat by klemens.
the class NotificationsManagerImpl method sendEmail.
private boolean sendEmail(Identity to, Translator translator, List<SubscriptionItem> subItems) {
String title = translator.translate("rss.title", new String[] { NotificationHelper.getFormatedName(to) });
StringBuilder htmlText = new StringBuilder();
htmlText.append("<style>");
htmlText.append(".o_m_sub h4 {margin: 0 0 10px 0;}");
htmlText.append(".o_m_sub ul {padding: 0 0 5px 20px; margin: 0;}");
htmlText.append(".o_m_sub ul li {padding: 0; margin: 1px 0;}");
htmlText.append(".o_m_go {padding: 5px 0 0 0}");
htmlText.append(".o_date {font-size: 90%; color: #888}");
htmlText.append(".o_m_footer {background: #FAFAFA; border: 1px solid #eee; border-radius: 5px; padding: 0 0.5em 0.5em 0.5em; margin: 1em 0 1em 0;' class='o_m_h'}");
htmlText.append("</style>");
for (Iterator<SubscriptionItem> it_subs = subItems.iterator(); it_subs.hasNext(); ) {
SubscriptionItem subitem = it_subs.next();
// o_m_wrap class for overriding styles in master mail template
htmlText.append("<div class='o_m_wrap'>");
// add background here for gmail as they ignore classes.
htmlText.append("<div class='o_m_sub' style='background: #FAFAFA; padding: 5px 5px; margin: 10px 0;'>");
// 1: title
htmlText.append(subitem.getTitle());
htmlText.append("\n");
// 2: content
String desc = subitem.getDescription();
if (StringHelper.containsNonWhitespace(desc)) {
htmlText.append(desc);
}
// 3: goto-link
String link = subitem.getLink();
if (StringHelper.containsNonWhitespace(link)) {
htmlText.append("<div class='o_m_go'><a href=\"").append(link).append("\">");
SubscriptionInfo subscriptionInfo = subitem.getSubsInfo();
if (subscriptionInfo != null) {
String innerType = subscriptionInfo.getType();
String typeName = NewControllerFactory.translateResourceableTypeName(innerType, translator.getLocale());
String open = translator.translate("resource.open", new String[] { typeName });
htmlText.append(open);
htmlText.append(" »</a></div>");
}
}
htmlText.append("\n");
htmlText.append("</div></div>");
}
String basePath = Settings.getServerContextPathURI() + "/auth/HomeSite/" + to.getKey() + "/";
htmlText.append("<div class='o_m_footer'>");
htmlText.append(translator.translate("footer.notifications", new String[] { basePath + "mysettings/0", basePath += "notifications/0", basePath + "/tab/1" }));
htmlText.append("</div>");
MailerResult result = null;
try {
MailBundle bundle = new MailBundle();
bundle.setToId(to);
bundle.setContent(title, htmlText.toString());
result = CoreSpringFactory.getImpl(MailManager.class).sendExternMessage(bundle, null, true);
} catch (Exception e) {
// FXOLAT-294 :: sending the mail will throw nullpointer exception if To-Identity has no
// valid email-address!, catch it...
}
if (result == null || result.getReturnCode() > 0) {
if (result != null)
log.warn("Could not send email to identity " + to.getName() + ". (returncode=" + result.getReturnCode() + ", to=" + to + ")");
else
log.warn("Could not send email to identity " + to.getName() + ". (returncode = null) , to=" + to + ")");
return false;
} else {
return true;
}
}
Aggregations