2013-04-26 18:53:48 +02:00
|
|
|
package com.commafeed.backend.feeds;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
|
|
import javax.ejb.Asynchronous;
|
|
|
|
|
import javax.ejb.Stateless;
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
2013-05-20 14:06:09 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
2013-04-26 18:53:48 +02:00
|
|
|
|
|
|
|
|
import com.commafeed.backend.dao.FeedDAO;
|
|
|
|
|
import com.commafeed.backend.model.Feed;
|
|
|
|
|
import com.commafeed.backend.model.FeedEntry;
|
2013-05-21 17:00:37 +02:00
|
|
|
import com.commafeed.backend.model.FeedEntryContent;
|
2013-05-20 14:06:09 +02:00
|
|
|
import com.commafeed.backend.model.FeedPushInfo;
|
|
|
|
|
import com.commafeed.backend.pubsubhubbub.SubscriptionHandler;
|
2013-05-21 07:09:48 +02:00
|
|
|
import com.commafeed.backend.services.ApplicationSettingsService;
|
2013-04-26 18:53:48 +02:00
|
|
|
import com.commafeed.backend.services.FeedUpdateService;
|
|
|
|
|
|
|
|
|
|
@Stateless
|
|
|
|
|
public class FeedRefreshUpdater {
|
|
|
|
|
|
2013-05-20 14:06:09 +02:00
|
|
|
protected static Logger log = LoggerFactory
|
|
|
|
|
.getLogger(FeedRefreshUpdater.class);
|
|
|
|
|
|
2013-04-26 18:53:48 +02:00
|
|
|
@Inject
|
|
|
|
|
FeedUpdateService feedUpdateService;
|
|
|
|
|
|
2013-05-20 14:06:09 +02:00
|
|
|
@Inject
|
|
|
|
|
SubscriptionHandler handler;
|
|
|
|
|
|
2013-04-26 18:53:48 +02:00
|
|
|
@Inject
|
|
|
|
|
FeedDAO feedDAO;
|
|
|
|
|
|
2013-05-21 07:09:48 +02:00
|
|
|
@Inject
|
|
|
|
|
ApplicationSettingsService applicationSettingsService;
|
|
|
|
|
|
2013-04-26 18:53:48 +02:00
|
|
|
@Asynchronous
|
|
|
|
|
public void updateEntries(Feed feed, Collection<FeedEntry> entries) {
|
|
|
|
|
if (CollectionUtils.isNotEmpty(entries)) {
|
2013-05-21 17:00:37 +02:00
|
|
|
for (FeedEntry entry : entries) {
|
|
|
|
|
handleEntry(feed, entry);
|
|
|
|
|
}
|
2013-04-26 18:53:48 +02:00
|
|
|
feedUpdateService.updateEntries(feed, entries);
|
|
|
|
|
}
|
|
|
|
|
feedDAO.update(feed);
|
2013-05-21 07:09:48 +02:00
|
|
|
if (applicationSettingsService.get().isPubsubhubbub()) {
|
|
|
|
|
handlePubSub(feed);
|
|
|
|
|
}
|
2013-05-20 14:06:09 +02:00
|
|
|
}
|
|
|
|
|
|
2013-05-21 17:00:37 +02:00
|
|
|
private void handleEntry(Feed feed, FeedEntry entry) {
|
|
|
|
|
String baseUri = feed.getLink();
|
|
|
|
|
FeedEntryContent content = entry.getContent();
|
|
|
|
|
|
|
|
|
|
content.setContent(FeedUtils.handleContent(content.getContent(),
|
|
|
|
|
baseUri));
|
|
|
|
|
String title = FeedUtils.handleContent(content.getTitle(), baseUri);
|
|
|
|
|
if (title != null) {
|
|
|
|
|
content.setTitle(title.substring(0, Math.min(2048, title.length())));
|
|
|
|
|
}
|
|
|
|
|
String author = entry.getAuthor();
|
|
|
|
|
if (author != null) {
|
|
|
|
|
entry.setAuthor(author.substring(0, Math.min(128, author.length())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 12:41:57 +02:00
|
|
|
private void handlePubSub(final Feed feed) {
|
2013-05-20 14:06:09 +02:00
|
|
|
FeedPushInfo info = feed.getPushInfo();
|
|
|
|
|
if (info != null && info.isActive() == false) {
|
2013-05-21 12:41:57 +02:00
|
|
|
new Thread() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
handler.subscribe(feed);
|
|
|
|
|
}
|
|
|
|
|
}.start();
|
2013-05-20 14:06:09 +02:00
|
|
|
}
|
2013-04-26 18:53:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|