Ejemplo n.º 1
0
  public String deleteSub() {
    // delete a planet subscription
    log.debug("Deleting Planet Subscription ...");

    PlanetManager pmgr = PlanetFactory.getPlanet().getPlanetManager();
    try {
      if (!StringUtils.isEmpty(getSubid())) {
        Subscription sub = pmgr.getSubscriptionById(getSubid());
        if (sub == null) {
          setError("PlanetGroupForm.error.nullSubscription");
          return INPUT;
        } else {
          PlanetGroup group = getGroup();
          group.getSubscriptions().remove(sub);
          sub.getGroups().remove(group);
          pmgr.saveGroup(group);
          PlanetFactory.getPlanet().flush();
        }

        setSuccess("PlanetGroupForm.message.subscriptionDeleteSucceeded", sub.getTitle());
      } else {
        setError("PlanetGroupForm.error.subscriptionNull");
      }

      return INPUT;

    } catch (PlanetException ex) {
      log.error("Unable to lookup planet group", ex);
      setError("PlanetGroupForm.error.subscriptionDeleteFailed", getSubid());
      return INPUT;
    }
  }
Ejemplo n.º 2
0
  // Validation - sub url cannot be null, must be valid url
  public String addSub() {
    // add a planet subscription
    log.debug("Adding Planet Subscription ...");

    PlanetManager pMgr = PlanetFactory.getPlanet().getPlanetManager();
    try {
      PlanetGroup group = getGroup();
      if (group == null) {
        setError("PlanetSubscriptionForm.error.groupNull");
        return INPUT;
      }

      // check if this subscription already exists before adding it
      Subscription sub = pMgr.getSubscription(getAddSubUrl());
      if (sub == null) {
        // sub doesn't exist yet, so we need to fetch it
        FeedFetcher fetcher = PlanetFactory.getPlanet().getFeedFetcher();
        sub = fetcher.fetchSubscription(getAddSubUrl());

        // save new sub
        pMgr.saveSubscription(sub);
      }

      // add the sub to the group
      group.getSubscriptions().add(sub);
      sub.getGroups().add(group);
      pMgr.saveGroup(group);

      // flush changes
      PlanetFactory.getPlanet().flush();

      // clear field after success
      setAddSubUrl(null);

    } catch (PlanetException ex) {
      log.error("Error adding subscription", ex);
      setError("PlanetSubscriptionForm.error.saveFailed");
      return INPUT;
    }

    setSuccess("PlanetSubscriptionForm.message.saveSucceeded");
    return INPUT;
  }
Ejemplo n.º 3
0
  public void testEntryCRUD() throws Exception {

    PlanetManager mgr = WebloggerFactory.getWeblogger().getPlanetManager();
    Subscription sub = mgr.getSubscriptionById(testSub.getId());

    SubscriptionEntry testEntry = new SubscriptionEntry();
    testEntry.setPermalink("entryBasics");
    testEntry.setTitle("entryBasics");
    testEntry.setPubTime(new java.sql.Timestamp(System.currentTimeMillis()));
    testEntry.setSubscription(sub);

    // add
    mgr.saveEntry(testEntry);
    TestUtils.endSession(true);

    // verify
    SubscriptionEntry entry = null;
    entry = mgr.getEntryById(testEntry.getId());
    assertNotNull(entry);
    assertEquals("entryBasics", entry.getPermalink());

    // modify
    entry.setTitle("foo");
    mgr.saveEntry(entry);
    TestUtils.endSession(true);

    // verify
    entry = null;
    entry = mgr.getEntryById(testEntry.getId());
    assertNotNull(entry);
    assertEquals("foo", entry.getTitle());

    // remove
    mgr.deleteEntry(entry);
    TestUtils.endSession(true);

    // verify
    entry = null;
    entry = mgr.getEntryById(testEntry.getId());
    assertNull(entry);
  }
Ejemplo n.º 4
0
 protected void tearDown() throws Exception {
   TestUtils.teardownSubscription(testSub.getId());
 }
Ejemplo n.º 5
0
  /** @inheritDoc */
  public Subscription fetchSubscription(String feedURL, Date lastModified) throws FetcherException {

    if (feedURL == null) {
      throw new IllegalArgumentException("feed url cannot be null");
    }

    // setup Rome feed fetcher
    FeedFetcher feedFetcher = getRomeFetcher();

    // fetch the feed
    log.debug("Fetching feed: " + feedURL);
    SyndFeed feed;
    try {
      feed = feedFetcher.retrieveFeed(new URL(feedURL));
    } catch (Exception ex) {
      throw new FetcherException("Error fetching subscription - " + feedURL, ex);
    }

    log.debug("Feed pulled, extracting data into Subscription");

    // build planet subscription from fetched feed
    Subscription newSub = new Subscription();
    newSub.setFeedURL(feedURL);
    newSub.setSiteURL(feed.getLink());
    newSub.setTitle(feed.getTitle());
    newSub.setAuthor(feed.getAuthor());
    newSub.setLastUpdated(feed.getPublishedDate());

    // normalize any data that couldn't be properly extracted
    if (newSub.getSiteURL() == null) {
      // set the site url to the feed url then
      newSub.setSiteURL(newSub.getFeedURL());
    }
    if (newSub.getAuthor() == null) {
      // set the author to the title
      newSub.setAuthor(newSub.getTitle());
    }
    if (newSub.getLastUpdated() == null) {
      // no update time specified in feed, so try consulting feed info cache
      FeedFetcherCache feedCache = getRomeFetcherCache();
      try {
        SyndFeedInfo feedInfo = feedCache.getFeedInfo(new URL(newSub.getFeedURL()));
        if (feedInfo.getLastModified() != null) {
          long lastUpdatedLong = ((Long) feedInfo.getLastModified()).longValue();
          if (lastUpdatedLong != 0) {
            newSub.setLastUpdated(new Date(lastUpdatedLong));
          }
        }
      } catch (MalformedURLException ex) {
        // should never happen since we check this above
      }
    }

    // check if feed is unchanged and bail now if so
    if (lastModified != null
        && newSub.getLastUpdated() != null
        && !newSub.getLastUpdated().after(lastModified)) {
      return null;
    }

    if (log.isDebugEnabled()) {
      log.debug("Subscription is: " + newSub.toString());
    }

    // some kludge to deal with feeds w/ no entry dates
    // we assign arbitrary dates chronologically by entry starting either
    // from the current time or the last update time of the subscription
    Calendar cal = Calendar.getInstance();
    if (newSub.getLastUpdated() != null) {
      cal.setTime(newSub.getLastUpdated());
    } else {
      cal.setTime(new Date());
      cal.add(Calendar.DATE, -1);
    }

    // add entries
    List<SyndEntry> feedEntries = feed.getEntries();
    for (SyndEntry feedEntry : feedEntries) {
      SubscriptionEntry newEntry = buildEntry(feedEntry);

      // some kludge to handle feeds with no entry dates
      if (newEntry.getPubTime() == null) {
        log.debug("No published date, assigning fake date for " + feedURL);
        newEntry.setPubTime(new Timestamp(cal.getTimeInMillis()));
        cal.add(Calendar.DATE, -1);
      }

      if (newEntry != null) {
        newSub.addEntry(newEntry);
      }
    }

    log.debug(feedEntries.size() + " entries included");

    return newSub;
  }