smarter feed entry storing (fixes #10)

This commit is contained in:
Athou
2013-04-07 12:01:50 +02:00
parent 0e80d4ec56
commit 642661a926
7 changed files with 80 additions and 43 deletions

View File

@@ -9,6 +9,7 @@ import javax.inject.Inject;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import com.commafeed.backend.model.Feed;
@@ -39,17 +40,30 @@ public class FeedEntryService extends GenericDAO<FeedEntry> {
List<FeedEntry> existingEntries = getByGuids(guids);
for (FeedEntry entry : entries) {
boolean found = false;
FeedEntry foundEntry = null;
for (FeedEntry existingEntry : existingEntries) {
if (StringUtils
.equals(entry.getGuid(), existingEntry.getGuid())) {
found = true;
foundEntry = existingEntry;
break;
}
}
if (!found) {
entry.setFeed(feed);
if (foundEntry == null) {
entry.getFeeds().add(feed);
save(entry);
} else {
boolean foundFeed = false;
for (Feed existingFeed : foundEntry.getFeeds()) {
if (ObjectUtils.equals(existingFeed.getId(), feed.getId())) {
foundFeed = true;
break;
}
}
if (!foundFeed) {
foundEntry.getFeeds().add(feed);
update(foundEntry);
}
}
}