@Test public void withSpecificMapper() throws Exception { final FeedObjectActivityBuilder flickrObjectMapper = context.mock(FeedObjectActivityBuilder.class); final SyndEntryImpl entry1 = context.mock(SyndEntryImpl.class, "e1"); final List<SyndEntryImpl> entryList = Collections.singletonList(entry1); setupNoSyMod(); setupFetchAnonymous(); context.checking(new Expectations() { { oneOf(flickrMapper).match(FEED_URL); will(returnValue(true)); oneOf(flickrMapper).getBuilder(); will(returnValue(flickrObjectMapper)); allowing(entry1).getPublishedDate(); will(returnValue(new Date(3))); allowing(entry1).getUpdatedDate(); will(returnValue(new Date(3))); allowing(entry1).getUri(); will(returnValue("uri")); oneOf(flickrObjectMapper).build(with(equal(feed)), with(equal(entry1)), with(any(Activity.class))); allowing(personOwner).isAccountLocked(); will(returnValue(false)); allowing(personOwner).getAccountId(); allowing(personOwner).getId(); allowing(personOwner).getStreamScope(); allowing(groupOwner).getStreamScope(); allowing(groupOwner).isPublicGroup(); allowing(groupOwner).getShortName(); will(returnValue(false)); allowing(atomFeed1).getEntries(); will(returnValue(entryList)); } }); sut.execute(ac); context.assertIsSatisfied(); }
@Override 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 { 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; } } 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); 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; 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) { 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); 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()); } 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); } } } } 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); 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; }
RefreshFeedExecution implements ExecutionStrategy<ActionContext> { @Override 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 { 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; } } 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); 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; 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) { 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); 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()); } 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); } } } } 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); 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; } }
RefreshFeedExecution implements ExecutionStrategy<ActionContext> { @Override 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 { 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; } } 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); 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; 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) { 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); 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()); } 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); } } } } 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); 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; } RefreshFeedExecution(final HashMap<BaseObjectType, FeedObjectActivityBuilder> inStandardFeedMappers,
            final List<ObjectBuilderForSpecificUrl> inSpecificUrlMappers,
            final InsertMapper<Activity> inActivityDBInserter, final Cache inCache,
            final FeedFactory inFeedFetcherFactory, final FindByIdMapper<Person> inPersonFinder,
            final FindByIdMapper<DomainGroup> inGroupFinder, final FindByIdMapper<Feed> inFeedFinder,
            final GadgetMetaDataFetcher inMetaDataFetcher, final UpdateMapper<Feed> inUpdateFeedMapper,
            final List<String> inOutOfOrderFeeds); }
RefreshFeedExecution implements ExecutionStrategy<ActionContext> { @Override 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 { 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; } } 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); 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; 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) { 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); 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()); } 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); } } } } 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); 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; } RefreshFeedExecution(final HashMap<BaseObjectType, FeedObjectActivityBuilder> inStandardFeedMappers,
            final List<ObjectBuilderForSpecificUrl> inSpecificUrlMappers,
            final InsertMapper<Activity> inActivityDBInserter, final Cache inCache,
            final FeedFactory inFeedFetcherFactory, final FindByIdMapper<Person> inPersonFinder,
            final FindByIdMapper<DomainGroup> inGroupFinder, final FindByIdMapper<Feed> inFeedFinder,
            final GadgetMetaDataFetcher inMetaDataFetcher, final UpdateMapper<Feed> inUpdateFeedMapper,
            final List<String> inOutOfOrderFeeds); @Override Serializable execute(final ActionContext inActionContext); }
RefreshFeedExecution implements ExecutionStrategy<ActionContext> { @Override 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 { 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; } } 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); 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; 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) { 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); 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()); } 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); } } } } 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); 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; } RefreshFeedExecution(final HashMap<BaseObjectType, FeedObjectActivityBuilder> inStandardFeedMappers,
            final List<ObjectBuilderForSpecificUrl> inSpecificUrlMappers,
            final InsertMapper<Activity> inActivityDBInserter, final Cache inCache,
            final FeedFactory inFeedFetcherFactory, final FindByIdMapper<Person> inPersonFinder,
            final FindByIdMapper<DomainGroup> inGroupFinder, final FindByIdMapper<Feed> inFeedFinder,
            final GadgetMetaDataFetcher inMetaDataFetcher, final UpdateMapper<Feed> inUpdateFeedMapper,
            final List<String> inOutOfOrderFeeds); @Override Serializable execute(final ActionContext inActionContext);  }