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;
}
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);
}
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);
}
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();
}
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;
}
}
Aggregations