Package org.eurekastreams.server.domain.stream.plugins

Examples of org.eurekastreams.server.domain.stream.plugins.Feed


     */
    @Test
    public void performActionWithSuccess() throws Exception
    {
        final FeedSubscriber feedSub = context.mock(FeedSubscriber.class);
        final Feed feed = context.mock(Feed.class);
        final HashMap<String, Serializable> conf = new HashMap<String, Serializable>();

        final HashMap<String, Serializable> values = new HashMap<String, Serializable>();
        values.put("EUREKA:TOS", Boolean.TRUE);
        values.put("EUREKA:PLUGINID", 1L);
View Full Code Here


     */
    @Test
    public void performActionWithSuccessWithGroupAndEdit() throws Exception
    {
        final FeedSubscriber feedSub = context.mock(FeedSubscriber.class);
        final Feed feed = context.mock(Feed.class);
        final HashMap<String, Serializable> conf = new HashMap<String, Serializable>();

        final HashMap<String, Serializable> values = new HashMap<String, Serializable>();
        values.put("EUREKA:TOS", Boolean.TRUE);
        values.put("EUREKA:PLUGINID", 1L);
View Full Code Here

     */
    @Test
    public void execute() throws Exception
    {
        final List<Feed> feeds = new LinkedList<Feed>();
        feeds.add(new Feed());

        final List<ActionRequest> requests = new LinkedList<ActionRequest>();


        context.checking(new Expectations()
View Full Code Here

     */
    @Test
    public void performAction() throws Exception
    {
        final PluginDefinition plugin = context.mock(PluginDefinition.class);
        final Feed feed = context.mock(Feed.class);
        final Feed feed2 = context.mock(Feed.class, "f2");
        final FeedSubscriber feedSub = context.mock(FeedSubscriber.class);
        final FeedSubscriber feedSub2 = context.mock(FeedSubscriber.class, "fs2");

        final List<FeedSubscriber> feedSubs = new ArrayList<FeedSubscriber>();
        feedSubs.add(feedSub);
View Full Code Here

    @Test
    public void testExecuteWithExisting()
    {
        GetFeedByUrlRequest request = new GetFeedByUrlRequest(1L, "http://www.google2.com");

        Feed feed = sut.execute(request);
        assertEquals("http://www.google2.com", feed.getUrl());
        assertEquals(1L, feed.getPlugin().getId());
        assertEquals(2L, feed.getId());
    }
View Full Code Here

    @Test
    public void testExecuteWithOutExisting()
    {
        GetFeedByUrlRequest request = new GetFeedByUrlRequest(2L, "http://www.google2.com");

        Feed feed = sut.execute(request);
        assertEquals("http://www.google2.com", feed.getUrl());
        assertEquals(2L, feed.getPlugin().getId());
       
        Feed persisted = findByIdMapper.execute(new FindByIdRequest("Feed", feed.getId()));
        assertEquals(persisted.getId(), feed.getId());
    }
View Full Code Here

        if (feeds.size() > 0)
        {
            return feeds.get(0);
        }

        Feed feed = new Feed();
        feed.setLastUpdated(new Date().getTime() / MS_IN_MIN);
        feed.setLastPostDate(new Date());
        feed.setUrl(inRequest.getUrl());
        feed.setTitle("Undefined");
        feed.setPlugin(getEntityManager().find(PluginDefinition.class, inRequest.getPluginId()));
        getEntityManager().persist(feed);

        return feed;
    }
View Full Code Here

    @Test
    public void testExecuteWithOutExisting2()
    {
        GetFeedByUrlRequest request = new GetFeedByUrlRequest(2L, "http://www.google8.com");

        Feed feed = sut.execute(request);
        assertEquals("http://www.google8.com", feed.getUrl());
        assertEquals(2L, feed.getPlugin().getId());
       
        Feed persisted = findByIdMapper.execute(new FindByIdRequest("Feed", feed.getId()));
        assertEquals(persisted.getId(), feed.getId());
    }
View Full Code Here

    public Serializable execute(final ActionContext inActionContext) throws ExecutionException
    {
        Boolean brokenFeed = true;
        String lastSeenGUID = "";
        RefreshFeedRequest request = (RefreshFeedRequest) inActionContext.getParams();
        Feed feed = feedFinder.execute(new FindByIdRequest("Feed", request.getFeedId()));
        Date lastPostDate = feed.getLastPostDate();
        Long updateFrequency = null;
        Boolean isOutOfOrder = false;

        log.info("Processor feed: " + feed.getUrl());
        for (String oooFeed : outOfOrderFeeds)
        {
            if (feed.getUrl().contains(oooFeed))
            {
                log.info("Feed marked out of order: " + feed.getUrl());
                isOutOfOrder = true;
                break;
            }
        }

        try
        {
            // fetch the feeds
            // Gives the fetcher the feed and a list of the requestors; the fetcher will decide if it can make a single
            // unauthenticated request or if it needs to make one request per requestor. A set is used to prevent
            // giving the fetcher any duplicates.
            Set<String> requestorAccounts = new HashSet<String>();
            for (FeedSubscriber feedSubscriber : feed.getFeedSubscribers())
            {
                requestorAccounts.add(feedSubscriber.getRequestor().getAccountId());
            }
            Map<String, SyndFeed> syndFeeds = feedFetcherFactory.getSyndicatedFeed(feed.getUrl(), requestorAccounts);

            FeedObjectActivityBuilder selectedObjectMapper = null;
            for (ObjectBuilderForSpecificUrl entry : specificUrlMappers)
            {
                if (entry.match(feed.getUrl()))
                {
                    selectedObjectMapper = entry.getBuilder();
                    break;
                }
            }

            // iterate through all feed instances returned by the fetcher
            List<Activity> insertedActivities = new LinkedList<Activity>();
            for (Map.Entry<String, SyndFeed> mapEntry : syndFeeds.entrySet())
            {
                SyndFeed syndFeed = mapEntry.getValue();
                List<FeedSubscriber> subscribers = getFeedSubscribers(mapEntry.getKey(), feed);

                // check for update frequency info
                if (updateFrequency == null)
                {
                    SyModule syMod = (SyModule) syndFeed.getModule(SyModule.URI);
                    if (syMod != null)
                    {
                        updateFrequency = getUpdateFrequency(syMod.getUpdatePeriod(), syMod.getUpdateFrequency());
                    }
                }

                if (syndFeed.getEntries().size() > 0)
                {
                    SyndEntryImpl entry = (SyndEntryImpl) syndFeed.getEntries().get(0);
                    lastSeenGUID = entry.getUri();
                }

                Boolean brokenOutOfOrder = false;

                if (isOutOfOrder && feed.getLastSeenGUID() != null)
                {
                    brokenOutOfOrder = true;
                    // iterate through each entry in the feed instance
                    for (Object entryObject : syndFeed.getEntries())
                    {
                        try
                        {
                            SyndEntryImpl entry = (SyndEntryImpl) entryObject;
                            if (feed.getLastSeenGUID().equals(entry.getUri()))
                            {
                                log.info("Found  matching GUID in out of order feed: " + lastSeenGUID);
                                brokenOutOfOrder = false;
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            log.warn("ATOM/RSS entry is not to spec. "
                                    + "Skipping entry and moving to the next one. Feed url: " + feed.getUrl(), ex);
                        }
                    }
                }

                if (!brokenOutOfOrder)
                {
                    // iterate through each entry in the feed instance
                    for (Object entryObject : syndFeed.getEntries())
                    {
                        try
                        {
                            SyndEntryImpl entry = (SyndEntryImpl) entryObject;

                            if (lastPostDate == null || entry.getPublishedDate().after(lastPostDate))
                            {
                                lastPostDate = entry.getPublishedDate();
                            }

                            Activity activity = getActivityFromATOMEntry(feed, entry, selectedObjectMapper);
                            // We were able to parse at least one good entry to completion, so the feed isn't broken.
                            brokenFeed = false;

                            if (isOutOfOrder && feed.getLastSeenGUID().equals(entry.getUri()))
                            {
                                log.info("Match found based on GUID: " + lastSeenGUID);
                                break;
                            }
                            else
                            {
                                log.info("No match found based on GUID: " + entry.getUri());
                            }

                            if (!isOutOfOrder && !entry.getPublishedDate().after(feed.getLastPostDate()))
                            {
                                log.info("Match found based on Date: " + feed.getLastPostDate());
                                break;
                            }
                            else
                            {
                                log.info("No match found based on Date: " + entry.getPublishedDate()
                                        + " Last Post Date: " + feed.getLastPostDate());
                            }

                            // create activities per subscriber
                            for (FeedSubscriber feedSubscriber : subscribers)
                            {
                                Activity activityForIndividual = (Activity) activity.clone();

                                if (feedSubscriber.getEntityType().equals(EntityType.PERSON))
                                {
                                    Person person = personFinder.execute(new FindByIdRequest("Person", feedSubscriber
                                            .getEntityId()));

                                    if (person.isAccountLocked())
                                    {
                                        log.info("Ignoring locked account: " + person.getAccountId());
                                    }
                                    else
                                    {
                                        activityForIndividual.setActorId(person.getAccountId());
                                        activityForIndividual.setRecipientStreamScope(person.getStreamScope());
                                        activityForIndividual.setIsDestinationStreamPublic(true);

                                        activityForIndividual.setActorType(feedSubscriber.getEntityType());
                                        insertedActivities.add(activityForIndividual);
                                    }
                                }
                                else if (feedSubscriber.getEntityType().equals(EntityType.GROUP))
                                {
                                    DomainGroup group = groupFinder.execute(new FindByIdRequest("DomainGroup",
                                            feedSubscriber.getEntityId()));

                                    activityForIndividual.setActorId(group.getShortName());
                                    activityForIndividual.setRecipientStreamScope(group.getStreamScope());
                                    activityForIndividual.setIsDestinationStreamPublic(group.isPublicGroup());

                                    activityForIndividual.setActorType(feedSubscriber.getEntityType());
                                    insertedActivities.add(activityForIndividual);
                                }
                            }

                        }
                        catch (Exception ex)
                        {
                            log.warn("ATOM/RSS entry is not to spec. "
                                    + "Skipping entry and moving to the next one. Feed url: " + feed.getUrl(), ex);
                        }
                    }
                }
            }

            // updateFeedMapper.execute(new PersistenceRequest<Feed>(feed));
            if (!insertedActivities.isEmpty())
            {
                ArrayList<Long> insertedActivityIds = new ArrayList<Long>();
                Collections.reverse(insertedActivities);
                for (Activity activity : insertedActivities)
                {
                    activityDBInserter.execute(new PersistenceRequest<Activity>(activity));
                    insertedActivityIds.add(activity.getId());
                }
                Collections.reverse(insertedActivityIds);

                // TODO: this is not performant; fix
                if (cache.get(CacheKeys.BUFFERED_ACTIVITIES) == null)
                {
                    cache.setList(CacheKeys.BUFFERED_ACTIVITIES, insertedActivityIds);
                }
                else
                {
                    cache.addToTopOfList(CacheKeys.BUFFERED_ACTIVITIES, insertedActivityIds);
                }
            }
        }
        catch (Exception ex)
        {
            log.error("Error retrieving feed: " + feed.getUrl(), ex);
        }
        finally
        {
            feed.setLastSeenGUID(lastSeenGUID);
            feed.setIsFeedBroken(brokenFeed);
            feed.setLastPostDate(lastPostDate);
            feed.setLastUpdated(new Date().getTime() / MS_IN_MIN);
            feed.setUpdateFrequency(updateFrequency);
            feed.setPending(false);
        }

        return null;
    }
View Full Code Here

        String title = (String) getTitleFromFeed.execute(getFeedContext);

        // Find or create the feed.
        GetFeedByUrlRequest request =
                new GetFeedByUrlRequest((Long) values.get("EUREKA:PLUGINID"), (String) values.get("EUREKA:FEEDURL"));
        Feed feed = getMapper.execute(request);
        feed.setTitle(title);

        // And now find or create the subscriber.
        FeedSubscriber feedSubscriber =
                getFeedSubscriberMapper.execute(new GetFeedSubscriberRequest(feed.getId(), getEntityId
                        .getEntityId(values), type, principal.getId()));

        // Add any non system key/value pairs to the feed subscribers conf settings.
        feedSubscriber.getConfSettings().clear();
View Full Code Here

TOP

Related Classes of org.eurekastreams.server.domain.stream.plugins.Feed

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.