use of org.olat.core.commons.services.notifications.NotificationsHandler in project openolat by klemens.
the class NotificationsManagerImpl method getSubscriptionInfos.
@Override
public List<SubscriptionInfo> getSubscriptionInfos(Identity identity, String publisherType) {
StringBuilder sb = new StringBuilder();
sb.append("select sub from notisub sub").append(" inner join fetch sub.publisher as pub").append(" where sub.identity=:identity and pub.type=:type and pub.state=:aState");
List<Subscriber> subscribers = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Subscriber.class).setParameter("aState", PUB_STATE_OK).setParameter("type", publisherType).setParameter("identity", identity).getResultList();
if (subscribers.isEmpty()) {
return Collections.emptyList();
}
Locale locale = new Locale(identity.getUser().getPreferences().getLanguage());
Date compareDate = getDefaultCompareDate();
List<SubscriptionInfo> sis = new ArrayList<SubscriptionInfo>();
for (Subscriber subscriber : subscribers) {
Publisher pub = subscriber.getPublisher();
NotificationsHandler notifHandler = getNotificationsHandler(pub);
// do not create subscription item when deleted
if (isPublisherValid(pub)) {
SubscriptionInfo subsInfo = notifHandler.createSubscriptionInfo(subscriber, locale, compareDate);
if (subsInfo.hasNews()) {
sis.add(subsInfo);
}
}
}
return sis;
}
use of org.olat.core.commons.services.notifications.NotificationsHandler in project OpenOLAT by OpenOLAT.
the class NotificationSubscriptionTableDataModel method getValueAt.
/**
* @see org.olat.core.gui.components.table.DefaultTableDataModel#getValueAt(int,
* int)
*/
@Override
public Object getValueAt(int row, int col) {
Subscriber sub = getObject(row);
Publisher pub = sub.getPublisher();
switch(col) {
case 0:
return sub.getKey();
case 1:
String innerType = pub.getType();
return NewControllerFactory.translateResourceableTypeName(innerType, getLocale());
case 2:
String containerType = pub.getResName();
return NewControllerFactory.translateResourceableTypeName(containerType, getLocale());
case 3:
NotificationsHandler handler = NotificationsManager.getInstance().getNotificationsHandler(pub);
if (handler == null) {
return "";
}
String title = handler.createTitleInfo(sub, getLocale());
if (title == null) {
return "";
}
return title;
case 4:
return sub.getCreationDate();
case 5:
return sub.getLatestEmailed();
default:
return "ERROR";
}
}
use of org.olat.core.commons.services.notifications.NotificationsHandler in project OpenOLAT by OpenOLAT.
the class NotificationsManagerImpl method getNotificationsHandler.
/**
* @return the handler for the type
*/
public NotificationsHandler getNotificationsHandler(Publisher publisher) {
String type = publisher.getType();
if (notificationHandlers == null) {
synchronized (lockObject) {
if (notificationHandlers == null) {
// check again in synchronized-block, only one may create list
notificationHandlers = new HashMap<String, NotificationsHandler>();
Map<String, NotificationsHandler> notificationsHandlerMap = CoreSpringFactory.getBeansOfType(NotificationsHandler.class);
Collection<NotificationsHandler> notificationsHandlerValues = notificationsHandlerMap.values();
for (NotificationsHandler notificationsHandler : notificationsHandlerValues) {
log.debug("initNotificationUpgrades notificationsHandler=" + notificationsHandler);
notificationHandlers.put(notificationsHandler.getType(), notificationsHandler);
}
}
}
}
return notificationHandlers.get(type);
}
use of org.olat.core.commons.services.notifications.NotificationsHandler 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.NotificationsHandler in project OpenOLAT by OpenOLAT.
the class NotificationsManagerImpl method getFormatedTitle.
/**
* format the type-title and title-details
* @param subscriber
* @param locale
* @param mimeType
* @return
*/
private String getFormatedTitle(SubscriptionInfo subsInfo, Subscriber subscriber, Locale locale, String mimeType) {
Publisher pub = subscriber.getPublisher();
StringBuilder titleSb = new StringBuilder();
String title = subsInfo.getTitle(mimeType);
if (StringHelper.containsNonWhitespace(title)) {
titleSb.append(title);
} else {
NotificationsHandler notifHandler = getNotificationsHandler(pub);
String titleInfo = notifHandler.createTitleInfo(subscriber, locale);
if (StringHelper.containsNonWhitespace(titleInfo)) {
titleSb.append(titleInfo);
}
}
return titleSb.toString();
}
Aggregations