public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    JournalFeed newJournalFeed = addJournalFeed();

    _persistence.clearCache();

    JournalFeedModelImpl existingJournalFeedModelImpl =
        (JournalFeedModelImpl) _persistence.findByPrimaryKey(newJournalFeed.getPrimaryKey());

    assertTrue(
        Validator.equals(
            existingJournalFeedModelImpl.getUuid(),
            existingJournalFeedModelImpl.getOriginalUuid()));
    assertEquals(
        existingJournalFeedModelImpl.getGroupId(),
        existingJournalFeedModelImpl.getOriginalGroupId());

    assertEquals(
        existingJournalFeedModelImpl.getGroupId(),
        existingJournalFeedModelImpl.getOriginalGroupId());
    assertTrue(
        Validator.equals(
            existingJournalFeedModelImpl.getFeedId(),
            existingJournalFeedModelImpl.getOriginalFeedId()));
  }
  public void testFindByPrimaryKeyExisting() throws Exception {
    JournalFeed newJournalFeed = addJournalFeed();

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

    assertEquals(existingJournalFeed, newJournalFeed);
  }
  public void testCreate() throws Exception {
    long pk = nextLong();

    JournalFeed journalFeed = _persistence.create(pk);

    assertNotNull(journalFeed);

    assertEquals(journalFeed.getPrimaryKey(), pk);
  }
  public void testRemove() throws Exception {
    JournalFeed newJournalFeed = addJournalFeed();

    _persistence.remove(newJournalFeed);

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

    assertNull(existingJournalFeed);
  }
  public void addFeedResources(
      JournalFeed feed, String[] groupPermissions, String[] guestPermissions)
      throws PortalException, SystemException {

    resourceLocalService.addModelResources(
        feed.getCompanyId(),
        feed.getGroupId(),
        feed.getUserId(),
        JournalFeed.class.getName(),
        feed.getId(),
        groupPermissions,
        guestPermissions);
  }
  public void addFeedResources(
      JournalFeed feed, boolean addGroupPermissions, boolean addGuestPermissions)
      throws PortalException, SystemException {

    resourceLocalService.addResources(
        feed.getCompanyId(),
        feed.getGroupId(),
        feed.getUserId(),
        JournalFeed.class.getName(),
        feed.getId(),
        false,
        addGroupPermissions,
        addGuestPermissions);
  }
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    JournalFeed newJournalFeed = addJournalFeed();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(JournalFeed.class, JournalFeed.class.getClassLoader());

    dynamicQuery.add(RestrictionsFactoryUtil.eq("id", newJournalFeed.getId()));

    List<JournalFeed> result = _persistence.findWithDynamicQuery(dynamicQuery);

    assertEquals(1, result.size());

    JournalFeed existingJournalFeed = result.get(0);

    assertEquals(existingJournalFeed, newJournalFeed);
  }
Ejemplo n.º 8
0
  protected String processURL(
      JournalFeed feed, String url, ThemeDisplay themeDisplay, SyndEntry syndEntry) {

    url =
        StringUtil.replace(
            url,
            new String[] {"@group_id@", "@image_path@", "@main_path@"},
            new String[] {
              String.valueOf(feed.getGroupId()),
              themeDisplay.getPathImage(),
              themeDisplay.getPathMain()
            });

    List<SyndEnclosure> syndEnclosures =
        JournalRSSUtil.getDLEnclosures(themeDisplay.getURLPortal(), url);

    syndEnclosures.addAll(JournalRSSUtil.getIGEnclosures(themeDisplay.getURLPortal(), url));

    syndEntry.setEnclosures(syndEnclosures);

    List<SyndLink> syndLinks = JournalRSSUtil.getDLLinks(themeDisplay.getURLPortal(), url);

    syndLinks.addAll(JournalRSSUtil.getIGLinks(themeDisplay.getURLPortal(), url));

    syndEntry.setLinks(syndLinks);

    return url;
  }
  public void deleteFeed(JournalFeed feed) throws PortalException, SystemException {

    // Expando

    expandoValueLocalService.deleteValues(JournalFeed.class.getName(), feed.getId());

    // Resources

    resourceLocalService.deleteResource(
        feed.getCompanyId(),
        JournalFeed.class.getName(),
        ResourceConstants.SCOPE_INDIVIDUAL,
        feed.getId());

    // Feed

    journalFeedPersistence.remove(feed);
  }
  public void testDynamicQueryByProjectionExisting() throws Exception {
    JournalFeed newJournalFeed = addJournalFeed();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(JournalFeed.class, JournalFeed.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("id"));

    Object newId = newJournalFeed.getId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("id", new Object[] {newId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    assertEquals(1, result.size());

    Object existingId = result.get(0);

    assertEquals(existingId, newId);
  }
Ejemplo n.º 11
0
  protected String getEntryURL(
      ResourceRequest resourceRequest,
      JournalFeed feed,
      JournalArticle article,
      Layout layout,
      ThemeDisplay themeDisplay)
      throws Exception {

    List<Long> hitLayoutIds =
        JournalContentSearchLocalServiceUtil.getLayoutIds(
            layout.getGroupId(), layout.isPrivateLayout(), article.getArticleId());

    if (hitLayoutIds.size() > 0) {
      Long hitLayoutId = hitLayoutIds.get(0);

      Layout hitLayout =
          LayoutLocalServiceUtil.getLayout(
              layout.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue());

      return PortalUtil.getLayoutFriendlyURL(hitLayout, themeDisplay);
    } else {
      long plid =
          PortalUtil.getPlidFromFriendlyURL(feed.getCompanyId(), feed.getTargetLayoutFriendlyUrl());

      String portletId = PortletKeys.JOURNAL_CONTENT;

      if (Validator.isNotNull(feed.getTargetPortletId())) {
        portletId = feed.getTargetPortletId();
      }

      PortletURL entryURL =
          new PortletURLImpl(resourceRequest, portletId, plid, PortletRequest.RENDER_PHASE);

      entryURL.setParameter("struts_action", "/journal_content/view");
      entryURL.setParameter("groupId", String.valueOf(article.getGroupId()));
      entryURL.setParameter("articleId", article.getArticleId());

      return entryURL.toString();
    }
  }
Ejemplo n.º 12
0
  @Override
  protected byte[] getRSS(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    JournalFeed feed = null;

    long id = ParamUtil.getLong(resourceRequest, "id");

    long groupId = ParamUtil.getLong(resourceRequest, "groupId");
    String feedId = ParamUtil.getString(resourceRequest, "feedId");

    if (id > 0) {
      feed = JournalFeedLocalServiceUtil.getFeed(id);
    } else {
      feed = JournalFeedLocalServiceUtil.getFeed(groupId, feedId);
    }

    String languageId = LanguageUtil.getLanguageId(resourceRequest);

    long plid =
        PortalUtil.getPlidFromFriendlyURL(
            themeDisplay.getCompanyId(), feed.getTargetLayoutFriendlyUrl());

    Layout layout = themeDisplay.getLayout();

    if (plid > 0) {
      try {
        layout = LayoutLocalServiceUtil.getLayout(plid);
      } catch (NoSuchLayoutException nsle) {
      }
    }

    String rss =
        exportToRSS(resourceRequest, resourceResponse, feed, languageId, layout, themeDisplay);

    return rss.getBytes(StringPool.UTF8);
  }
  protected JournalFeed addJournalFeed() throws Exception {
    long pk = nextLong();

    JournalFeed journalFeed = _persistence.create(pk);

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

    _persistence.update(journalFeed, false);

    return journalFeed;
  }
  @Override
  public JournalFeed updateFeed(
      long groupId,
      String feedId,
      String name,
      String description,
      String type,
      String structureId,
      String templateId,
      String rendererTemplateId,
      int delta,
      String orderByCol,
      String orderByType,
      String targetLayoutFriendlyUrl,
      String targetPortletId,
      String contentField,
      String feedFormat,
      double feedVersion,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Feed

    JournalFeed feed = journalFeedPersistence.findByG_F(groupId, feedId);

    validate(
        feed.getCompanyId(), groupId, name, structureId, targetLayoutFriendlyUrl, contentField);

    feed.setModifiedDate(serviceContext.getModifiedDate(null));
    feed.setName(name);
    feed.setDescription(description);
    feed.setType(type);
    feed.setStructureId(structureId);
    feed.setTemplateId(templateId);
    feed.setRendererTemplateId(rendererTemplateId);
    feed.setDelta(delta);
    feed.setOrderByCol(orderByCol);
    feed.setOrderByType(orderByType);
    feed.setTargetLayoutFriendlyUrl(targetLayoutFriendlyUrl);
    feed.setTargetPortletId(targetPortletId);
    feed.setContentField(contentField);

    if (Validator.isNull(feedFormat)) {
      feed.setFeedFormat(RSSUtil.FORMAT_DEFAULT);
      feed.setFeedVersion(RSSUtil.VERSION_DEFAULT);
    } else {
      feed.setFeedFormat(feedFormat);
      feed.setFeedVersion(feedVersion);
    }

    feed.setExpandoBridgeAttributes(serviceContext);

    journalFeedPersistence.update(feed);

    return feed;
  }
Ejemplo n.º 15
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);
    }
  }
Ejemplo n.º 16
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;
  }
  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());
  }
  @Override
  public JournalFeed addFeed(
      long userId,
      long groupId,
      String feedId,
      boolean autoFeedId,
      String name,
      String description,
      String type,
      String structureId,
      String templateId,
      String rendererTemplateId,
      int delta,
      String orderByCol,
      String orderByType,
      String targetLayoutFriendlyUrl,
      String targetPortletId,
      String contentField,
      String feedFormat,
      double feedVersion,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Feed

    User user = userPersistence.findByPrimaryKey(userId);
    feedId = StringUtil.toUpperCase(feedId.trim());
    Date now = new Date();

    validate(
        user.getCompanyId(),
        groupId,
        feedId,
        autoFeedId,
        name,
        structureId,
        targetLayoutFriendlyUrl,
        contentField);

    if (autoFeedId) {
      feedId = String.valueOf(counterLocalService.increment());
    }

    long id = counterLocalService.increment();

    JournalFeed feed = journalFeedPersistence.create(id);

    feed.setUuid(serviceContext.getUuid());
    feed.setGroupId(groupId);
    feed.setCompanyId(user.getCompanyId());
    feed.setUserId(user.getUserId());
    feed.setUserName(user.getFullName());
    feed.setCreateDate(serviceContext.getCreateDate(now));
    feed.setModifiedDate(serviceContext.getModifiedDate(now));
    feed.setFeedId(feedId);
    feed.setName(name);
    feed.setDescription(description);
    feed.setType(type);
    feed.setStructureId(structureId);
    feed.setTemplateId(templateId);
    feed.setRendererTemplateId(rendererTemplateId);
    feed.setDelta(delta);
    feed.setOrderByCol(orderByCol);
    feed.setOrderByType(orderByType);
    feed.setTargetLayoutFriendlyUrl(targetLayoutFriendlyUrl);
    feed.setTargetPortletId(targetPortletId);
    feed.setContentField(contentField);

    if (Validator.isNull(feedFormat)) {
      feed.setFeedFormat(RSSUtil.FORMAT_DEFAULT);
      feed.setFeedVersion(RSSUtil.VERSION_DEFAULT);
    } else {
      feed.setFeedFormat(feedFormat);
      feed.setFeedVersion(feedVersion);
    }

    feed.setExpandoBridgeAttributes(serviceContext);

    journalFeedPersistence.update(feed);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

      addFeedResources(
          feed, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addFeedResources(
          feed, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return feed;
  }