コード例 #1
0
  @Test
  public void testRestoreRedirectPageWithParentPageFromTrash() throws Exception {

    int initialBaseModelsCount = getNotInTrashBaseModelsCount(_node);
    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());

    WikiPage[] pages =
        WikiTestUtil.addRenamedParentPageWithChildPageAndGrandchildPage(
            group.getGroupId(), _node.getNodeId());

    WikiPage parentPage = pages[0];
    WikiPage redirectPage = pages[1];
    WikiPage childPage = pages[2];
    WikiPage grandchildPage = pages[3];

    moveBaseModelToTrash(redirectPage.getPrimaryKey());

    restoreTrashEntry(redirectPage);

    parentPage = WikiPageLocalServiceUtil.getPageByPageId(parentPage.getPageId());
    redirectPage = WikiPageLocalServiceUtil.getPageByPageId(redirectPage.getPageId());
    childPage = WikiPageLocalServiceUtil.getPageByPageId(childPage.getPageId());
    grandchildPage = WikiPageLocalServiceUtil.getPageByPageId(grandchildPage.getPageId());

    Assert.assertFalse(parentPage.isInTrash());
    Assert.assertFalse(redirectPage.isInTrashExplicitly());
    Assert.assertEquals(parentPage.getTitle(), redirectPage.getRedirectTitle());
    Assert.assertFalse(childPage.isInTrash());
    Assert.assertEquals(parentPage.getTitle(), childPage.getParentTitle());
    Assert.assertFalse(grandchildPage.isInTrash());
    Assert.assertEquals(childPage.getTitle(), grandchildPage.getParentTitle());
    Assert.assertEquals(initialBaseModelsCount + 4, getNotInTrashBaseModelsCount(_node));
    Assert.assertEquals(initialTrashEntriesCount, getTrashEntriesCount(group.getGroupId()));
  }
コード例 #2
0
  @Test
  public void testRestoreExplicitlyTrashedParentPageWithRedirectPageFromTrash() throws Exception {

    WikiPage[] pages =
        WikiTestUtil.addRenamedTrashedParentPage(
            group.getGroupId(), _node.getNodeId(), false, true);

    WikiPage parentPage = pages[0];
    WikiPage childPage = pages[1];
    WikiPage redirectPage = pages[2];

    restoreTrashEntry(parentPage);

    parentPage = WikiPageLocalServiceUtil.getPageByPageId(parentPage.getPageId());
    childPage = WikiPageLocalServiceUtil.getPageByPageId(childPage.getPageId());
    redirectPage = WikiPageLocalServiceUtil.getPageByPageId(redirectPage.getPageId());

    Assert.assertFalse(parentPage.isInTrash());
    Assert.assertFalse(childPage.isInTrash());
    Assert.assertEquals(childPage.getParentTitle(), parentPage.getTitle());
    Assert.assertTrue(redirectPage.isInTrashExplicitly());
    Assert.assertEquals(redirectPage.getRedirectTitle(), parentPage.getTitle());

    restoreTrashEntry(redirectPage);
  }
コード例 #3
0
  @Test
  public void testMoveInitialParentPageToTrash() throws Exception {
    int initialBaseModelsCount = getNotInTrashBaseModelsCount(_node);
    int initialTrashEntriesCount = getTrashEntriesCount(group.getGroupId());

    WikiPage[] pages =
        WikiTestUtil.addPageWithChangedParentPage(group.getGroupId(), _node.getNodeId());

    WikiPage page = pages[0];
    WikiPage finalParentPage = pages[1];
    WikiPage initialParentPage = pages[2];

    WikiPageLocalServiceUtil.movePageToTrash(TestPropsValues.getUserId(), initialParentPage);

    page = WikiPageLocalServiceUtil.getPageByPageId(page.getPageId());
    finalParentPage = WikiPageLocalServiceUtil.getPageByPageId(finalParentPage.getPageId());
    initialParentPage = WikiPageLocalServiceUtil.getPageByPageId(initialParentPage.getPageId());

    Assert.assertFalse(page.isInTrash());
    Assert.assertFalse(finalParentPage.isInTrash());
    Assert.assertTrue(initialParentPage.isInTrashExplicitly());
    Assert.assertEquals(finalParentPage.getTitle(), page.getParentTitle());
    Assert.assertEquals(initialBaseModelsCount + 2, getNotInTrashBaseModelsCount(_node));
    Assert.assertEquals(initialTrashEntriesCount + 1, getTrashEntriesCount(group.getGroupId()));
    Assert.assertEquals(page.getParentTitle(), finalParentPage.getTitle());
  }
コード例 #4
0
  @Override
  protected void moveBaseModelToTrash(long primaryKey) throws Exception {
    WikiPage page = WikiPageLocalServiceUtil.getPageByPageId(primaryKey);

    WikiPageLocalServiceUtil.movePageToTrash(
        TestPropsValues.getUserId(), page.getNodeId(), page.getTitle());
  }
コード例 #5
0
  @Override
  public WikiPage updateStatus(int status, Map<String, Serializable> workflowContext)
      throws PortalException {

    long userId =
        GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
    long classPK =
        GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));

    ServiceContext serviceContext = (ServiceContext) workflowContext.get("serviceContext");

    WikiPage page = WikiPageLocalServiceUtil.getPageByPageId(classPK);

    return WikiPageLocalServiceUtil.updateStatus(
        userId, page, status, serviceContext, workflowContext);
  }
コード例 #6
0
  public void spamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    checkWikiPagePermission(themeDisplay.getScopeGroupId());

    long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "spamWikiPageIds");

    for (long wikiPageId : wikiPageIds) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId);

      wikiPage.setSummary(AkismetConstants.WIKI_PAGE_MARKED_AS_SPAM);

      WikiPageLocalServiceUtil.updateWikiPage(wikiPage);
    }
  }
コード例 #7
0
  @Test
  public void testDeleteTrashedParentPageWithExplicitTrashedChildPage() throws Exception {

    WikiPage[] pages =
        WikiTestUtil.addTrashedPageWithChildPage(_group.getGroupId(), _node.getNodeId(), true);

    WikiPage parentPage = pages[0];
    WikiPage childPage = pages[1];

    WikiPageLocalServiceUtil.deletePage(parentPage);

    try {
      WikiPageLocalServiceUtil.getPage(parentPage.getResourcePrimKey());

      Assert.fail();
    } catch (NoSuchPageResourceException nspre) {
      childPage = WikiPageLocalServiceUtil.getPageByPageId(childPage.getPageId());

      Assert.assertNull(childPage.fetchParentPage());
    }
  }
コード例 #8
0
  @Override
  protected BaseModel<?> updateBaseModel(long primaryKey, ServiceContext serviceContext)
      throws Exception {

    WikiPage page = WikiPageLocalServiceUtil.getPageByPageId(primaryKey);

    serviceContext = (ServiceContext) serviceContext.clone();

    return WikiPageLocalServiceUtil.updatePage(
        TestPropsValues.getUserId(),
        page.getNodeId(),
        page.getTitle(),
        page.getVersion(),
        RandomTestUtil.randomString(),
        RandomTestUtil.randomString(),
        false,
        page.getFormat(),
        page.getParentTitle(),
        page.getRedirectTitle(),
        serviceContext);
  }
コード例 #9
0
  @Test
  public void testDeleteTrashedPageWithRestoredRedirectPage() throws Exception {

    WikiPage[] pages =
        WikiTestUtil.addRenamedTrashedPage(_group.getGroupId(), _node.getNodeId(), true);

    WikiPage page = pages[0];
    WikiPage redirectPage = pages[1];

    WikiPageLocalServiceUtil.restorePageFromTrash(TestPropsValues.getUserId(), redirectPage);

    WikiPageLocalServiceUtil.deletePage(page);

    try {
      WikiPageLocalServiceUtil.getPage(page.getResourcePrimKey());

      Assert.fail();
    } catch (NoSuchPageResourceException nspre) {
      redirectPage = WikiPageLocalServiceUtil.getPageByPageId(redirectPage.getPageId());

      Assert.assertNull(redirectPage.fetchRedirectPage());
      Assert.assertEquals(WorkflowConstants.STATUS_APPROVED, redirectPage.getStatus());
    }
  }
コード例 #10
0
 @Override
 protected BaseModel<?> getBaseModel(long primaryKey) throws Exception {
   return WikiPageLocalServiceUtil.getPageByPageId(primaryKey);
 }
コード例 #11
0
  public void markNotSpamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    checkWikiPagePermission(themeDisplay.getScopeGroupId());

    long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "notSpamWikiPageIds");

    List<String> wikiPageLinks = new ArrayList<String>();

    for (long wikiPageId : wikiPageIds) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId);

      WikiPage latestVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), false);

      String latestContent = null;

      if (latestVersionWikiPage != null) {
        latestContent = latestVersionWikiPage.getContent();
      }

      WikiPage previousVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), true);

      String previousContent = null;

      if (previousVersionWikiPage != null) {
        previousContent = previousVersionWikiPage.getContent();
      }

      // Selected version

      wikiPage.setStatus(WorkflowConstants.STATUS_APPROVED);
      wikiPage.setSummary(StringPool.BLANK);

      wikiPage = WikiPageLocalServiceUtil.updateWikiPage(wikiPage);

      // Latest version

      if ((latestContent != null)
          && ((previousContent == null) || latestContent.equals(previousContent))) {

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        WikiPageLocalServiceUtil.revertPage(
            themeDisplay.getUserId(),
            wikiPage.getNodeId(),
            wikiPage.getTitle(),
            wikiPage.getVersion(),
            serviceContext);
      } else {
        StringBundler sb = new StringBundler(5);

        sb.append("<a href=\"");

        long plid = PortalUtil.getPlidFromPortletId(wikiPage.getGroupId(), PortletKeys.WIKI);

        LiferayPortletURL liferayPortletURL =
            PortletURLFactoryUtil.create(
                actionRequest, PortletKeys.WIKI, plid, PortletRequest.RENDER_PHASE);

        WikiNode wikiNode = wikiPage.getNode();

        liferayPortletURL.setParameter("struts_action", "/wiki/view");
        liferayPortletURL.setParameter("nodeName", wikiNode.getName());
        liferayPortletURL.setParameter("title", wikiPage.getTitle());
        liferayPortletURL.setParameter("version", String.valueOf(wikiPage.getVersion()));

        sb.append(liferayPortletURL.toString());
        sb.append("\" target=\"_blank\">");
        sb.append(HtmlUtil.escape(wikiPage.getTitle()));
        sb.append("</a>");

        wikiPageLinks.add(sb.toString());
      }

      // Akismet

      if (AkismetUtil.isWikiEnabled(wikiPage.getCompanyId())) {
        AkismetUtil.submitHam(wikiPage);
      }
    }

    if (!wikiPageLinks.isEmpty()) {
      SessionMessages.add(actionRequest, "requestProcessed");

      SessionMessages.add(
          actionRequest,
          "anotherUserHasMadeChangesToThesePages",
          StringUtil.merge(wikiPageLinks, "<br />"));

      super.sendRedirect(actionRequest, actionResponse);
    }
  }