コード例 #1
0
  @Test
  public void testChangePageNodeWithRedirectPage() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(),
        _group.getGroupId(),
        _node.getNodeId(),
        "InitialTitlePage",
        true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiPageLocalServiceUtil.renamePage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "InitialTitlePage",
        "RenamedPage",
        serviceContext);

    WikiPageLocalServiceUtil.changeNode(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "RenamedPage",
        destinationNode.getNodeId(),
        serviceContext);

    WikiPage page = WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "RenamedPage");
    WikiPage redirectPage =
        WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "InitialTitlePage");

    Assert.assertEquals(destinationNode.getNodeId(), page.getNodeId());
    Assert.assertEquals(destinationNode.getNodeId(), redirectPage.getNodeId());
    Assert.assertEquals("RenamedPage", redirectPage.getRedirectTitle());
  }
コード例 #2
0
  @Test
  public void testChangeChildPageNode() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(), "ParentPage", true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "ChildPage",
        RandomTestUtil.randomString(),
        "ParentPage",
        true,
        serviceContext);

    WikiPageLocalServiceUtil.changeNode(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "ChildPage",
        destinationNode.getNodeId(),
        serviceContext);

    WikiPage parentPage = WikiPageLocalServiceUtil.getPage(_node.getNodeId(), "ParentPage");
    WikiPage childPage = WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "ChildPage");

    Assert.assertEquals(_node.getNodeId(), parentPage.getNodeId());
    Assert.assertEquals(destinationNode.getNodeId(), childPage.getNodeId());
    Assert.assertTrue(Validator.isNull(childPage.getParentTitle()));
  }
コード例 #3
0
  @Test
  public void testChangePageNodeWithChildHierarchy() throws Exception {
    WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId());

    WikiTestUtil.addPage(
        TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(), "ParentPage", true);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    List<WikiPage> childPages = createPageHierarchy("ParentPage", 10, serviceContext);

    WikiPageLocalServiceUtil.changeNode(
        TestPropsValues.getUserId(),
        _node.getNodeId(),
        "ParentPage",
        destinationNode.getNodeId(),
        serviceContext);

    WikiPage page = WikiPageLocalServiceUtil.getPage(destinationNode.getNodeId(), "ParentPage");

    Assert.assertEquals(destinationNode.getNodeId(), page.getNodeId());

    for (WikiPage childPage : childPages) {
      childPage = WikiPageLocalServiceUtil.getPage(childPage.getResourcePrimKey());

      Assert.assertEquals(destinationNode.getNodeId(), childPage.getNodeId());
    }
  }
コード例 #4
0
  public void deleteTrashEntries(long[] classPKs, boolean checkPermission)
      throws PortalException, SystemException {

    for (long classPK : classPKs) {
      WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

      if (checkPermission) {
        WikiPageServiceUtil.deletePage(page.getNodeId(), page.getTitle());
      } else {
        WikiPageLocalServiceUtil.deletePage(page.getNodeId(), page.getTitle());
      }
    }
  }
コード例 #5
0
  @Override
  public void checkDuplicateTrashEntry(TrashEntry trashEntry, long containerModelId, String newName)
      throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(trashEntry.getClassPK());

    if (containerModelId == TrashEntryConstants.DEFAULT_CONTAINER_ID) {
      containerModelId = page.getNodeId();
    }

    String restoredTitle = page.getTitle();

    if (Validator.isNotNull(newName)) {
      restoredTitle = newName;
    }

    String originalTitle = TrashUtil.stripTrashNamespace(restoredTitle);

    WikiPageResource pageResource =
        WikiPageResourceLocalServiceUtil.fetchPageResource(containerModelId, originalTitle);

    if (pageResource != null) {
      DuplicateEntryException dee = new DuplicateEntryException();

      WikiPage duplicatePage = WikiPageLocalServiceUtil.getPage(pageResource.getResourcePrimKey());

      dee.setDuplicateEntryId(duplicatePage.getPageId());
      dee.setOldName(duplicatePage.getTitle());
      dee.setTrashEntryId(trashEntry.getEntryId());

      throw dee;
    }
  }
コード例 #6
0
  @Override
  protected void moveBaseModelToTrash(long primaryKey) throws Exception {
    WikiPage page = WikiPageLocalServiceUtil.getPageByPageId(primaryKey);

    WikiPageLocalServiceUtil.movePageToTrash(
        TestPropsValues.getUserId(), page.getNodeId(), page.getTitle());
  }
コード例 #7
0
  @Override
  public int compareTo(WikiPage wikiPage) {
    int value = 0;

    if (getNodeId() < wikiPage.getNodeId()) {
      value = -1;
    } else if (getNodeId() > wikiPage.getNodeId()) {
      value = 1;
    } else {
      value = 0;
    }

    if (value != 0) {
      return value;
    }

    value = getTitle().compareToIgnoreCase(wikiPage.getTitle());

    if (value != 0) {
      return value;
    }

    if (getVersion() < wikiPage.getVersion()) {
      value = -1;
    } else if (getVersion() > wikiPage.getVersion()) {
      value = 1;
    } else {
      value = 0;
    }

    value = value * -1;

    if (value != 0) {
      return value;
    }

    return 0;
  }
コード例 #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 testCopyPage() throws Exception {
    WikiPage page = WikiTestUtil.addPage(_group.getGroupId(), _node.getNodeId(), true);

    WikiTestUtil.addWikiAttachment(page.getUserId(), page.getNodeId(), page.getTitle(), getClass());

    List<FileEntry> attachmentsFileEntries = page.getAttachmentsFileEntries();

    WikiPage copyPage =
        WikiTestUtil.copyPage(
            page, true, ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

    List<FileEntry> copyAttachmentsFileEntries = copyPage.getAttachmentsFileEntries();

    Assert.assertEquals(copyAttachmentsFileEntries.size(), attachmentsFileEntries.size());

    FileEntry fileEntry = attachmentsFileEntries.get(0);
    FileEntry copyFileEntry = copyAttachmentsFileEntries.get(0);

    Assert.assertEquals(copyFileEntry.getExtension(), fileEntry.getExtension());
    Assert.assertEquals(copyFileEntry.getMimeType(), fileEntry.getMimeType());
    Assert.assertEquals(copyFileEntry.getTitle(), fileEntry.getTitle());
    Assert.assertEquals(copyFileEntry.getSize(), fileEntry.getSize());
  }
コード例 #10
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);
    }
  }