public void testUpdateExisting() throws Exception {
    long pk = nextLong();

    JournalFeed newJournalFeed = _persistence.create(pk);

    newJournalFeed.setUuid(randomString());
    newJournalFeed.setGroupId(nextLong());
    newJournalFeed.setCompanyId(nextLong());
    newJournalFeed.setUserId(nextLong());
    newJournalFeed.setUserName(randomString());
    newJournalFeed.setCreateDate(nextDate());
    newJournalFeed.setModifiedDate(nextDate());
    newJournalFeed.setFeedId(randomString());
    newJournalFeed.setName(randomString());
    newJournalFeed.setDescription(randomString());
    newJournalFeed.setType(randomString());
    newJournalFeed.setStructureId(randomString());
    newJournalFeed.setTemplateId(randomString());
    newJournalFeed.setRendererTemplateId(randomString());
    newJournalFeed.setDelta(nextInt());
    newJournalFeed.setOrderByCol(randomString());
    newJournalFeed.setOrderByType(randomString());
    newJournalFeed.setTargetLayoutFriendlyUrl(randomString());
    newJournalFeed.setTargetPortletId(randomString());
    newJournalFeed.setContentField(randomString());
    newJournalFeed.setFeedType(randomString());
    newJournalFeed.setFeedVersion(nextDouble());

    _persistence.update(newJournalFeed, false);

    JournalFeed existingJournalFeed = _persistence.findByPrimaryKey(newJournalFeed.getPrimaryKey());

    assertEquals(existingJournalFeed.getUuid(), newJournalFeed.getUuid());
    assertEquals(existingJournalFeed.getId(), newJournalFeed.getId());
    assertEquals(existingJournalFeed.getGroupId(), newJournalFeed.getGroupId());
    assertEquals(existingJournalFeed.getCompanyId(), newJournalFeed.getCompanyId());
    assertEquals(existingJournalFeed.getUserId(), newJournalFeed.getUserId());
    assertEquals(existingJournalFeed.getUserName(), newJournalFeed.getUserName());
    assertEquals(
        Time.getShortTimestamp(existingJournalFeed.getCreateDate()),
        Time.getShortTimestamp(newJournalFeed.getCreateDate()));
    assertEquals(
        Time.getShortTimestamp(existingJournalFeed.getModifiedDate()),
        Time.getShortTimestamp(newJournalFeed.getModifiedDate()));
    assertEquals(existingJournalFeed.getFeedId(), newJournalFeed.getFeedId());
    assertEquals(existingJournalFeed.getName(), newJournalFeed.getName());
    assertEquals(existingJournalFeed.getDescription(), newJournalFeed.getDescription());
    assertEquals(existingJournalFeed.getType(), newJournalFeed.getType());
    assertEquals(existingJournalFeed.getStructureId(), newJournalFeed.getStructureId());
    assertEquals(existingJournalFeed.getTemplateId(), newJournalFeed.getTemplateId());
    assertEquals(
        existingJournalFeed.getRendererTemplateId(), newJournalFeed.getRendererTemplateId());
    assertEquals(existingJournalFeed.getDelta(), newJournalFeed.getDelta());
    assertEquals(existingJournalFeed.getOrderByCol(), newJournalFeed.getOrderByCol());
    assertEquals(existingJournalFeed.getOrderByType(), newJournalFeed.getOrderByType());
    assertEquals(
        existingJournalFeed.getTargetLayoutFriendlyUrl(),
        newJournalFeed.getTargetLayoutFriendlyUrl());
    assertEquals(existingJournalFeed.getTargetPortletId(), newJournalFeed.getTargetPortletId());
    assertEquals(existingJournalFeed.getContentField(), newJournalFeed.getContentField());
    assertEquals(existingJournalFeed.getFeedType(), newJournalFeed.getFeedType());
    assertEquals(existingJournalFeed.getFeedVersion(), newJournalFeed.getFeedVersion());
  }
Пример #2
0
  protected String exportToRSS(
      ResourceRequest resourceRequest,
      ResourceResponse resourceResponse,
      JournalFeed feed,
      String languageId,
      Layout layout,
      ThemeDisplay themeDisplay)
      throws Exception {

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(feed.getDescription());

    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();

    syndFeed.setEntries(syndEntries);

    List<JournalArticle> articles = JournalRSSUtil.getArticles(feed);

    if (_log.isDebugEnabled()) {
      _log.debug("Syndicating " + articles.size() + " articles");
    }

    for (JournalArticle article : articles) {
      SyndEntry syndEntry = new SyndEntryImpl();

      String author = PortalUtil.getUserName(article);

      syndEntry.setAuthor(author);

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      String value = article.getDescription(languageId);

      try {
        value = processContent(feed, article, languageId, themeDisplay, syndEntry, syndContent);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(e, e);
        }
      }

      syndContent.setValue(value);

      syndEntry.setDescription(syndContent);

      String link = getEntryURL(resourceRequest, feed, article, layout, themeDisplay);

      syndEntry.setLink(link);

      syndEntry.setPublishedDate(article.getDisplayDate());
      syndEntry.setTitle(article.getTitle(languageId));
      syndEntry.setUpdatedDate(article.getModifiedDate());
      syndEntry.setUri(link);

      syndEntries.add(syndEntry);
    }

    syndFeed.setFeedType(feed.getFeedType() + "_" + feed.getFeedVersion());

    List<SyndLink> syndLinks = new ArrayList<SyndLink>();

    syndFeed.setLinks(syndLinks);

    SyndLink selfSyndLink = new SyndLinkImpl();

    syndLinks.add(selfSyndLink);

    ResourceURL feedURL = resourceResponse.createResourceURL();

    feedURL.setCacheability(ResourceURL.FULL);
    feedURL.setParameter("struts_action", "/journal/rss");
    feedURL.setParameter("groupId", String.valueOf(feed.getGroupId()));
    feedURL.setParameter("feedId", String.valueOf(feed.getFeedId()));

    String link = feedURL.toString();

    selfSyndLink.setHref(link);

    selfSyndLink.setRel("self");

    syndFeed.setTitle(feed.getName());
    syndFeed.setPublishedDate(new Date());
    syndFeed.setUri(feedURL.toString());

    try {
      return RSSUtil.export(syndFeed);
    } catch (FeedException fe) {
      throw new SystemException(fe);
    }
  }