use of org.olat.core.commons.services.notifications.SubscriptionInfo in project OpenOLAT by OpenOLAT.
the class ForumNotificationsHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
@Override
public SubscriptionInfo createSubscriptionInfo(final Subscriber subscriber, Locale locale, Date compareDate) {
try {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
String businessControlString = "";
Long forumKey = Long.valueOf(0);
try {
forumKey = Long.parseLong(p.getData());
} catch (NumberFormatException e) {
logError("Could not parse forum key!", e);
NotificationsManager.getInstance().deactivate(p);
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
if ("CourseModule".equals(p.getResName())) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
final List<Message> mInfos = ForumManager.getInstance().getNewMessageInfo(forumKey, compareDate);
final Translator translator = Util.createPackageTranslator(ForumNotificationsHandler.class, locale);
businessControlString = p.getBusinessPath() + "[Message:";
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItem(p, translator), null);
for (Message mInfo : mInfos) {
String title = mInfo.getTitle();
Identity creator = mInfo.getCreator();
Identity modifier = mInfo.getModifier();
Date modDate = mInfo.getLastModified();
String name;
if (modifier != null) {
if (modifier.equals(creator) && StringHelper.containsNonWhitespace(mInfo.getPseudonym())) {
name = mInfo.getPseudonym();
} else {
name = NotificationHelper.getFormatedName(modifier);
}
} else if (StringHelper.containsNonWhitespace(mInfo.getPseudonym())) {
name = mInfo.getPseudonym();
} else if (mInfo.isGuest()) {
name = translator.translate("anonymous.poster");
} else {
name = NotificationHelper.getFormatedName(creator);
}
final String descKey = "notifications.entry" + (mInfo.getCreationDate().equals(mInfo.getLastModified()) ? "" : ".modified");
final String desc = translator.translate(descKey, new String[] { title, name });
String urlToSend = null;
String businessPath = null;
if (p.getBusinessPath() != null) {
businessPath = businessControlString + mInfo.getKey().toString() + "]";
urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
}
SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, ForumHelper.CSS_ICON_CLASS_MESSAGE);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Error while creating forum's notifications from publisher with key:" + subscriber.getKey(), e);
checkPublisher(subscriber.getPublisher());
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project OpenOLAT by OpenOLAT.
the class AbstractTaskNotificationHandler method createSubscriptionInfo.
/**
* @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
* java.util.Locale, java.util.Date)
*/
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
String folderRoot = p.getData();
if (isLogDebugEnabled()) {
logDebug("folderRoot=", folderRoot);
}
final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot, compareDate);
final Translator translator = Util.createPackageTranslator(AbstractTaskNotificationHandler.class, locale);
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(OresHelper.createOLATResourceableInstance("CourseModule", p.getResId()), false);
if (re == null) {
if (!checkPublisher(p)) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} else if (re.getRepositoryEntryStatus().isClosed()) {
return NotificationsManager.getInstance().getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(translator.translate(getNotificationHeaderKey(), new String[] { displayName }), getCssClassIcon()), null);
SubscriptionListItem subListItem;
for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
FileInfo fi = it_infos.next();
MetaInfo metaInfo = fi.getMetaInfo();
String filePath = fi.getRelPath();
if (isLogDebugEnabled())
logDebug("filePath=", filePath);
String fullUserName = getUserNameFromFilePath(metaInfo, filePath);
Date modDate = fi.getLastModified();
String desc = translator.translate(getNotificationEntryKey(), new String[] { filePath, fullUserName });
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = null;
if (metaInfo != null) {
iconCssClass = metaInfo.getIconCssClass();
}
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
si.addSubscriptionListItem(subListItem);
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
getLogger().error("Cannot create task notifications for subscriber: " + subscriber.getKey(), e);
checkPublisher(p);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo in project openolat by klemens.
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;
}
use of org.olat.core.commons.services.notifications.SubscriptionInfo 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.SubscriptionInfo in project openolat by klemens.
the class NewUsersNotificationHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
SubscriptionInfo si;
Translator translator = Util.createPackageTranslator(this.getClass(), locale);
// there could be news for me, investigate deeper
try {
if (NotificationsManager.getInstance().isPublisherValid(p) && compareDate.before(latestNews)) {
List<Identity> identities = UsersSubscriptionManager.getInstance().getNewIdentityCreated(compareDate);
if (identities.isEmpty()) {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
} else {
translator = Util.createPackageTranslator(this.getClass(), locale);
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(getItemTitle(identities, translator), CSSHelper.CSS_CLASS_GROUP), null);
SubscriptionListItem subListItem;
for (Identity newUser : identities) {
String desc = translator.translate("notifications.entry", new String[] { NotificationHelper.getFormatedName(newUser) });
String businessPath = "[Identity:" + newUser.getKey() + "]";
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
Date modDate = newUser.getCreationDate();
subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSSHelper.CSS_CLASS_USER);
si.addSubscriptionListItem(subListItem);
}
}
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Error creating new identity's notifications for subscriber: " + subscriber.getKey(), e);
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
}
Aggregations