Search in sources :

Example 1 with CombinedFeed

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();
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Test(org.junit.Test)

Example 2 with CombinedFeed

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());
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) FeedEntry(org.glassfish.jersey.examples.feedcombiner.model.FeedEntry) URL(java.net.URL) Date(java.util.Date) Collection(java.util.Collection) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) LoggerFactory(org.slf4j.LoggerFactory) InMemoryDataStore(org.glassfish.jersey.examples.feedcombiner.store.InMemoryDataStore) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) CombinedFeedBuilder.of(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed.CombinedFeedBuilder.of) FeedEntry(org.glassfish.jersey.examples.feedcombiner.model.FeedEntry) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) Objects(java.util.Objects) Collection(java.util.Collection)

Example 3 with CombinedFeed

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;
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed)

Example 4 with 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<>();
}
Also used : Serializable(java.io.Serializable) CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed) ArrayList(java.util.ArrayList) ReadWriteLockDataStore(org.glassfish.jersey.examples.feedcombiner.store.ReadWriteLockDataStore)

Example 5 with CombinedFeed

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();
}
Also used : CombinedFeed(org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed)

Aggregations

CombinedFeed (org.glassfish.jersey.examples.feedcombiner.model.CombinedFeed)25 Test (org.junit.Test)19 Serializable (java.io.Serializable)7 Response (javax.ws.rs.core.Response)5 JerseyTest (org.glassfish.jersey.test.JerseyTest)5 IOException (java.io.IOException)2 URL (java.net.URL)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 FeedEntry (org.glassfish.jersey.examples.feedcombiner.model.FeedEntry)2 ReadWriteLockDataStore (org.glassfish.jersey.examples.feedcombiner.store.ReadWriteLockDataStore)2 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1