Skip to content
Snippets Groups Projects
Commit 70876046 authored by uhensler's avatar uhensler
Browse files

OO-2849: Handle notifications for external blogs and podcasts

parent d58ab513
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ import org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl;
import org.olat.core.commons.persistence.PersistenceHelper;
import org.olat.core.commons.services.commentAndRating.CommentAndRatingService;
import org.olat.core.commons.services.image.Size;
import org.olat.core.commons.services.notifications.NotificationsManager;
import org.olat.core.gui.components.form.flexible.elements.FileElement;
import org.olat.core.gui.media.MediaResource;
import org.olat.core.id.Identity;
......@@ -121,6 +122,8 @@ public class FeedManagerImpl extends FeedManager {
private FeedFileStorge feedFileStorage;
@Autowired
private ExternalFeedFetcher externalFeedFetcher;
@Autowired
private NotificationsManager notificationsManager;
/**
* spring only
......@@ -202,7 +205,7 @@ public class FeedManagerImpl extends FeedManager {
feed = enrichFeedByRepositoryEntryInfromation(feed);
// Update the external feed and the items
if (feed != null && feed.isExternal() && StringHelper.containsNonWhitespace(feed.getExternalFeedUrl()) ) {
if (feed != null && feed.isExternal() && StringHelper.containsNonWhitespace(feed.getExternalFeedUrl())) {
Calendar cal = Calendar.getInstance();
cal.setTime(feed.getLastModified());
long lastModifiedMillis = cal.getTimeInMillis();
......@@ -212,8 +215,10 @@ public class FeedManagerImpl extends FeedManager {
// time to update or first load after creation of the feed
saveExternalItems(feed);
saveExternalFeed(feed);
notificationsManager.markPublisherNews(ores.getResourceableTypeName(),
feed.getResourceableId().toString(), null, false);
}
feed.setLastModified(new Date());
feedDAO.updateFeed(feed);
}
......@@ -504,25 +509,32 @@ public class FeedManagerImpl extends FeedManager {
for (Item externalItem : externalItems) {
Item reloaded = itemDAO.loadItemByGuid(feed.getKey(), externalItem.getGuid());
if (reloaded == null) {
externalItem.setCreationDate(new Date());
Date now = new Date();
externalItem.setCreationDate(now);
// Init the last modified
if (externalItem.getLastModified() == null) {
externalItem.setLastModified(now);
}
// published date should never be null because it triggers notifications
if (externalItem.getPublishDate() == null) {
externalItem.setPublishDate(now);
}
itemDAO.createItem(feed, externalItem);
} else {
// Do not overwrite initial values
if (externalItem.getLastModified() != null) {
reloaded.setLastModified(externalItem.getLastModified());
}
if (externalItem.getPublishDate() != null) {
reloaded.setPublishDate(externalItem.getPublishDate());
}
reloaded.setAuthor(externalItem.getAuthor());
reloaded.setExternalLink(externalItem.getExternalLink());
reloaded.setPublishDate(externalItem.getPublishDate());
reloaded.setTitle(externalItem.getTitle());
reloaded.setDescription(externalItem.getDescription());
reloaded.setContent(externalItem.getContent());
reloaded.setEnclosure(externalItem.getEnclosure());
// last modified should not be null
Date lastModified = externalItem.getLastModified();
if (lastModified != null) {
reloaded.setLastModified(lastModified);
} else {
reloaded.setLastModified(new Date());
}
itemDAO.updateItem(reloaded);
}
}
......
......@@ -129,7 +129,12 @@ public abstract class FeedNotificationsHandler implements NotificationsHandler {
items.add(new SubscriptionListItem(desc, urlToSend, businessPath, publishDate, iconCssClass));
}
if(item.getModifierKey() != null) {
// Internal items are modified when the modifier key is present.
// External items are modified when the creation date is unequal the
// last modified date and the published date is after the last
// modified date.
if (item.getModifierKey() != null
|| (item.getFeed().isExternal() && !item.getCreationDate().equals(item.getLastModified()) && item.getPublishDate().before(item.getLastModified()))) {
Date modDate = item.getLastModified();
if(compareDate.before(modDate)) {
String desc;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment