* org.rssowl.core.persist.IConditionalGet, boolean,
* org.eclipse.core.runtime.IProgressMonitor)
*/
public final void handleFeedReload(IBookMark bookMark, IFeed interpretedFeed, IConditionalGet conditionalGet, boolean deleteConditionalGet, final IProgressMonitor monitor) {
fWriteLock.lock();
MergeResult mergeResult = null;
try {
/* Resolve reloaded Feed */
IFeed feed = bookMark.getFeedLinkReference().resolve();
/* Feed could have been deleted meanwhile! */
if (feed == null)
return;
/* Return early on cancellation */
if (monitor.isCanceled() || Owl.isShuttingDown())
return;
/* Copy over Properties to reloaded Feed to keep them */
Map<String, Serializable> feedProperties = feed.getProperties();
if (feedProperties != null) {
feedProperties.entrySet();
for (Map.Entry<String, Serializable> entry : feedProperties.entrySet())
interpretedFeed.setProperty(entry.getKey(), entry.getValue());
}
/* Return early on cancellation */
if (monitor.isCanceled() || Owl.isShuttingDown())
return;
/* Merge with existing */
mergeResult = feed.mergeAndCleanUp(interpretedFeed);
final List<INews> newNewsAdded = getNewNewsAdded(feed);
/* Return early on cancellation */
if (monitor.isCanceled() || Owl.isShuttingDown())
return;
/* Update Date of last added news in Bookmark */
if (!newNewsAdded.isEmpty()) {
Date mostRecentDate = DateUtils.getRecentDate(newNewsAdded);
Date previousMostRecentDate = bookMark.getMostRecentNewsDate();
if (previousMostRecentDate == null || mostRecentDate.after(previousMostRecentDate)) {
bookMark.setMostRecentNewsDate(mostRecentDate);
fDb.store(bookMark);
}
}
/* Return early on cancellation */
if (monitor.isCanceled() || Owl.isShuttingDown())
return;
/* Update state of added news if equivalent news already exists */
SafeRunner.run(new LoggingSafeRunnable() {
public void run() throws Exception { //See Bug 1216 (NPE in ModelSearchImpl.getCurrentSearcher)
updateStateOfUnsavedNewNews(newNewsAdded, monitor);
}
});
/* Return early on cancellation */
if (monitor.isCanceled() || Owl.isShuttingDown())
return;
/* Retention Policy */
final List<INews> deletedNews = RetentionStrategy.process(bookMark, feed);
for (INews news : deletedNews)
mergeResult.addUpdatedObject(news);
/* Return early on cancellation */
if (monitor.isCanceled() || Owl.isShuttingDown())
return;
/* Set ID to News and handle Description entity */
IDGenerator generator = Owl.getPersistenceService().getIDGenerator();
for (INews news : newNewsAdded) {
/* Return early on cancellation */
if (monitor.isCanceled() || Owl.isShuttingDown())
return;
long id;
if (generator instanceof DB4OIDGenerator)
id = ((DB4OIDGenerator) generator).getNext(false);
else
id = generator.getNext();
news.setId(id);
String description = ((News) news).getTransientDescription();
if (description != null) {
mergeResult.addUpdatedObject(new Description(news, description));
}
}
/* Return early on cancellation */
if (monitor.isCanceled() || Owl.isShuttingDown())