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());
  }
Esempio n. 2
0
  protected String processContent(
      JournalFeed feed,
      JournalArticle article,
      String languageId,
      ThemeDisplay themeDisplay,
      SyndEntry syndEntry,
      SyndContent syndContent)
      throws Exception {

    String content = article.getDescription(languageId);

    String contentField = feed.getContentField();

    if (contentField.equals(JournalFeedConstants.RENDERED_WEB_CONTENT)) {
      String rendererTemplateId = article.getTemplateId();

      if (Validator.isNotNull(feed.getRendererTemplateId())) {
        rendererTemplateId = feed.getRendererTemplateId();
      }

      JournalArticleDisplay articleDisplay =
          JournalContentUtil.getDisplay(
              feed.getGroupId(),
              article.getArticleId(),
              rendererTemplateId,
              null,
              languageId,
              themeDisplay,
              1,
              _XML_REQUUEST);

      if (articleDisplay != null) {
        content = articleDisplay.getContent();
      }
    } else if (!contentField.equals(JournalFeedConstants.WEB_CONTENT_DESCRIPTION)) {

      Document document = SAXReaderUtil.read(article.getContentByLocale(languageId));

      contentField = HtmlUtil.escapeXPathAttribute(contentField);

      XPath xPathSelector =
          SAXReaderUtil.createXPath("//dynamic-element[@name=" + contentField + "]");

      List<Node> results = xPathSelector.selectNodes(document);

      if (results.size() == 0) {
        return content;
      }

      Element element = (Element) results.get(0);

      String elType = element.attributeValue("type");

      if (elType.equals("document_library")) {
        String url = element.elementText("dynamic-content");

        url = processURL(feed, url, themeDisplay, syndEntry);
      } else if (elType.equals("image") || elType.equals("image_gallery")) {
        String url = element.elementText("dynamic-content");

        url = processURL(feed, url, themeDisplay, syndEntry);

        content =
            content + "<br /><br /><img alt='' src='" + themeDisplay.getURLPortal() + url + "' />";
      } else if (elType.equals("text_box")) {
        syndContent.setType("text");

        content = element.elementText("dynamic-content");
      } else {
        content = element.elementText("dynamic-content");
      }
    }

    return content;
  }