protected void updateNode(ActionRequest actionRequest) throws Exception { long nodeId = ParamUtil.getLong(actionRequest, "nodeId"); String name = ParamUtil.getString(actionRequest, "name"); String description = ParamUtil.getString(actionRequest, "description"); ServiceContext serviceContext = ServiceContextFactory.getInstance(WikiNode.class.getName(), actionRequest); if (nodeId <= 0) { // Add node WikiNodeServiceUtil.addNode(name, description, serviceContext); } else { // Update node WikiNode wikiNode = WikiNodeServiceUtil.getNode(nodeId); String oldName = wikiNode.getName(); WikiNodeServiceUtil.updateNode(nodeId, name, description, serviceContext); WikiPortletInstanceSettings wikiPortletInstanceSettings = getWikiPortletInstanceSettings(actionRequest); updateSettings(wikiPortletInstanceSettings, oldName, name); } }
@Override protected void validateImport( Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception { List<StagedModel> dependentStagedModels = dependentStagedModelsMap.get(WikiNode.class.getSimpleName()); Assert.assertEquals(1, dependentStagedModels.size()); WikiNode node = (WikiNode) dependentStagedModels.get(0); WikiNodeLocalServiceUtil.getWikiNodeByUuidAndGroupId(node.getUuid(), group.getGroupId()); }
@Override protected void addStagedModels() throws Exception { WikiNode node = WikiTestUtil.addNode(stagingGroup.getGroupId()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(stagingGroup.getGroupId()); WikiTestUtil.addPage( TestPropsValues.getUserId(), node.getNodeId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), true, serviceContext); }
@Override protected List<StagedModel> addWorkflowedStagedModels(Group group) throws Exception { List<StagedModel> stagedModels = new ArrayList<>(); WikiNode node = WikiTestUtil.addNode(group.getGroupId()); WikiPage page = WikiTestUtil.addPage(group.getGroupId(), node.getNodeId(), true); stagedModels.add(page); WikiPage draftPage = WikiTestUtil.addPage(group.getGroupId(), node.getNodeId(), false); stagedModels.add(draftPage); return stagedModels; }
@Override protected StagedModel addStagedModel( Group group, Map<String, List<StagedModel>> dependentStagedModelsMap) throws Exception { List<StagedModel> dependentStagedModels = dependentStagedModelsMap.get(WikiNode.class.getSimpleName()); WikiNode node = (WikiNode) dependentStagedModels.get(0); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); WikiPage page = WikiTestUtil.addPage( TestPropsValues.getUserId(), node.getNodeId(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), true, serviceContext); WikiTestUtil.addWikiAttachment( TestPropsValues.getUserId(), node.getNodeId(), page.getTitle(), WikiAttachmentsTest.class); List<FileEntry> attachmentsFileEntries = page.getAttachmentsFileEntries(); FileEntry fileEntry = attachmentsFileEntries.get(0); Folder folder = fileEntry.getFolder(); while (folder != null) { addDependentStagedModel(dependentStagedModelsMap, DLFolder.class, folder); folder = folder.getParentFolder(); } addDependentStagedModel( dependentStagedModelsMap, DLFileEntry.class, attachmentsFileEntries.get(0)); Repository repository = RepositoryUtil.fetchByPrimaryKey(fileEntry.getRepositoryId()); addDependentStagedModel(dependentStagedModelsMap, Repository.class, repository); return page; }
protected void deleteNode(ActionRequest actionRequest, boolean moveToTrash) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); int nodeCount = WikiNodeLocalServiceUtil.getNodesCount(themeDisplay.getScopeGroupId()); if (nodeCount == 1) { SessionErrors.add(actionRequest, RequiredNodeException.class); return; } long nodeId = ParamUtil.getLong(actionRequest, "nodeId"); WikiNode wikiNode = WikiNodeServiceUtil.getNode(nodeId); String oldName = wikiNode.getName(); WikiCacheThreadLocal.setClearCache(false); WikiNode trashWikiNode = null; if (moveToTrash) { trashWikiNode = WikiNodeServiceUtil.moveNodeToTrash(nodeId); } else { WikiNodeServiceUtil.deleteNode(nodeId); } WikiCacheUtil.clearCache(nodeId); WikiCacheThreadLocal.setClearCache(true); WikiPortletInstanceSettings wikiPortletInstanceSettings = getWikiPortletInstanceSettings(actionRequest); updateSettings(wikiPortletInstanceSettings, oldName, StringPool.BLANK); if (moveToTrash && (trashWikiNode != null)) { TrashUtil.addTrashSessionMessages(actionRequest, trashWikiNode); hideDefaultSuccessMessage(actionRequest); } }
public void markNotSpamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "notSpamWikiPageIds"); List<String> wikiPageLinks = new ArrayList<>(); 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(), WikiPortletKeys.WIKI); LiferayPortletURL liferayPortletURL = PortletURLFactoryUtil.create( actionRequest, WikiPortletKeys.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, "anotherUserHasMadeChangesToThesePages", StringUtil.merge(wikiPageLinks, "<br />")); addSuccessMessage(actionRequest, actionResponse); super.sendRedirect(actionRequest, actionResponse); } }