use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.
the class FeedDataStoreManagerTest method testSaveSuccess.
@Test
@SuppressWarnings({ "unchecked", "ConstantConditions" })
public void testSaveSuccess() {
long refreshPeriod = 60;
CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder("1", "http://localhost").refreshPeriod(refreshPeriod).build();
expect(scheduler.scheduleAtFixedRate(anyObject(Runnable.class), eq(0L), eq(60L), eq(TimeUnit.SECONDS))).andReturn(scheduledFuture);
expect(taskFactory.get(feed)).andReturn(new FeedDownloadTask(null, null, null));
replayAll();
testedClass.save(feed);
verifyAll();
}
use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed 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.CombinedFeed in project jersey by jersey.
the class CombinedFeedService method save.
@Override
public CombinedFeed save(CombinedFeed insertedFeed) {
String entityId = idGenerator.getId();
CombinedFeed.CombinedFeedBuilder feedBuilder = of(insertedFeed).id(entityId).feedEntries(null);
if (insertedFeed.getRefreshPeriod() == 0) {
feedBuilder.refreshPeriod(Long.parseLong(defaultRefreshPeriod));
}
CombinedFeed combinedFeed = feedBuilder.build();
datastore.put(entityId, combinedFeed);
return combinedFeed;
}
use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.
the class CombinedFeedService method getAll.
@Override
public List<CombinedFeed> getAll() {
//TODO ugly, for purposes of CRUD controller
if (datastore instanceof ReadWriteLockDataStore) {
ReadWriteLockDataStore rwDatastore = (ReadWriteLockDataStore) datastore;
Collection<Serializable> entities = rwDatastore.getAll();
return entities.parallelStream().filter(entity -> entity instanceof CombinedFeed).map(CombinedFeed.class::cast).collect(Collectors.toList());
}
return new ArrayList<>();
}
use of org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed in project jersey by jersey.
the class CombinedFeedResourceTest method callGetEntries.
private Response callGetEntries(MediaType mediaType) {
String entityID = "1";
CombinedFeed feedWithEntries = CombinedFeed.CombinedFeedBuilder.of(combinedFeed(entityID)).feedEntries(feedEntries()).build();
datastore.put(entityID, feedWithEntries);
return target.path(entityID).path("entries").request(mediaType).get();
}
Aggregations