use of org.glassfish.jersey.examples.feedcombiner.model.FeedEntry in project jersey by jersey.
the class FeedDownloadTask method run.
@Override
public void run() {
CombinedFeed fetchedCombinedFeed = datastore.get(combinedFeedID, CombinedFeed.class);
if (fetchedCombinedFeed == null) {
LOG.warn("There is no CombinedFeed for the ID: " + combinedFeedID);
return;
}
List<FeedEntry> entries = fetchedCombinedFeed.getUrls().stream().map(feedDownloader).flatMap(Collection::stream).map(entryMapper).filter(Objects::nonNull).sorted((e1, e2) -> e2.getPublishDate().compareTo(e1.getPublishDate())).collect(Collectors.toList());
CombinedFeed combinedFeed = of(fetchedCombinedFeed).feedEntries(entries).build();
datastore.put(combinedFeedID, combinedFeed);
LOG.debug("New entries for the CombinedFeed were downloaded [combined-feed={}, entries-count={}]", combinedFeed.getId(), entries.size());
}
use of org.glassfish.jersey.examples.feedcombiner.model.FeedEntry in project jersey by jersey.
the class FeedEntriesAtomBodyWriter method writeTo.
@Override
public void writeTo(List<FeedEntry> entries, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
List<SyndEntry> syndEntries = entries.parallelStream().map(entry -> {
SyndContent description = new SyndContentImpl();
description.setType(MediaType.TEXT_PLAIN);
description.setValue(entry.getDescription());
SyndEntry syndEntry = new SyndEntryImpl();
syndEntry.setTitle(entry.getTitle());
syndEntry.setLink(entry.getLink());
syndEntry.setPublishedDate(entry.getPublishDate());
syndEntry.setDescription(description);
return syndEntry;
}).collect(Collectors.toList());
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("atom_1.0");
feed.setTitle("Combined Feed");
feed.setDescription("Combined Feed created by a feed-combiner application");
feed.setPublishedDate(new Date());
feed.setEntries(syndEntries);
writeSyndFeed(entityStream, feed);
}
use of org.glassfish.jersey.examples.feedcombiner.model.FeedEntry in project jersey by jersey.
the class FeedDownloadTaskTest method testSuccess.
@Test
public void testSuccess() throws Exception {
URL url = new URL("http://localhost");
String id = "1";
CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, singletonList(url)).refreshPeriod(5L).build();
expect(datastore.get(feedId, CombinedFeed.class)).andReturn(feed);
expect(downloader.apply(url)).andReturn(syndEntries());
Capture<CombinedFeed> feedCapture = EasyMock.newCapture();
expect(datastore.put(eq(id), capture(feedCapture))).andReturn(null);
replayAll();
testedClass.run();
verifyAll();
CombinedFeed capturedFeed = feedCapture.getValue();
assertEquals(2, capturedFeed.getFeedEntries().size());
for (FeedEntry entry : capturedFeed.getFeedEntries()) {
if (TITLES[0].equals(entry.getTitle())) {
assertEquals(feedEntries().get(0), entry);
} else {
assertEquals(feedEntries().get(1), entry);
}
}
}
use of org.glassfish.jersey.examples.feedcombiner.model.FeedEntry in project jersey by jersey.
the class CombinedFeedResourceTest method testGetEntriesJSON.
@Test
public void testGetEntriesJSON() {
Response response = callGetEntries(APPLICATION_JSON_TYPE);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
List<FeedEntry> restoredEntities = response.readEntity(new GenericType<List<FeedEntry>>() {
});
assertEquals(feedEntries(), restoredEntities);
}
Aggregations