@Override public String getRestoreLink(PortletRequest portletRequest, long classPK) throws PortalException, SystemException { String portletId = PortletKeys.WIKI; WikiPage page = WikiPageLocalServiceUtil.getPage(classPK); long plid = PortalUtil.getPlidFromPortletId(page.getGroupId(), PortletKeys.WIKI); if (plid == LayoutConstants.DEFAULT_PLID) { plid = PortalUtil.getControlPanelPlid(portletRequest); portletId = PortletKeys.WIKI_ADMIN; } PortletURL portletURL = PortletURLFactoryUtil.create(portletRequest, portletId, plid, PortletRequest.RENDER_PHASE); WikiNode node = page.getNode(); portletURL.setParameter("struts_action", "/wiki/view"); portletURL.setParameter("nodeName", node.getName()); portletURL.setParameter("title", HtmlUtil.unescape(page.getTitle())); return portletURL.toString(); }
public static List<WikiNode> orderNodes(List<WikiNode> nodes, String[] visibleNodeNames) { if ((visibleNodeNames == null) || (visibleNodeNames.length == 0)) { return nodes; } nodes = ListUtil.copy(nodes); List<WikiNode> orderedNodes = new ArrayList<WikiNode>(nodes.size()); for (String visibleNodeName : visibleNodeNames) { for (WikiNode node : nodes) { if (node.getName().equals(visibleNodeName)) { orderedNodes.add(node); nodes.remove(node); break; } } } orderedNodes.addAll(nodes); return orderedNodes; }
public String getNodePagesRSS( long nodeId, int max, String type, double version, String displayStyle, String feedURL, String entryURL) throws PortalException, SystemException { WikiNodePermission.check(getPermissionChecker(), nodeId, ActionKeys.VIEW); WikiNode node = wikiNodePersistence.findByPrimaryKey(nodeId); long companyId = node.getCompanyId(); String name = node.getName(); String description = node.getDescription(); List<WikiPage> pages = getNodePages(nodeId, max); boolean diff = false; Locale locale = null; return exportToRSS( companyId, name, description, type, version, displayStyle, feedURL, entryURL, pages, diff, locale); }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, WikiNode node) throws Exception { long userId = portletDataContext.getUserId(node.getUserUuid()); ServiceContext serviceContext = portletDataContext.createServiceContext(node); WikiNode importedNode = null; if (portletDataContext.isDataStrategyMirror()) { WikiNode existingNode = WikiNodeLocalServiceUtil.fetchNodeByUuidAndGroupId( node.getUuid(), portletDataContext.getScopeGroupId()); String initialNodeName = PropsValues.WIKI_INITIAL_NODE_NAME; if ((existingNode == null) && initialNodeName.equals(node.getName())) { WikiNode initialNode = WikiNodeLocalServiceUtil.fetchNode( portletDataContext.getScopeGroupId(), node.getName()); if (initialNode != null) { WikiNodeLocalServiceUtil.deleteWikiNode(initialNode); } } if (existingNode == null) { serviceContext.setUuid(node.getUuid()); importedNode = WikiNodeLocalServiceUtil.addNode( userId, node.getName(), node.getDescription(), serviceContext); } else { importedNode = WikiNodeLocalServiceUtil.updateNode( existingNode.getNodeId(), node.getName(), node.getDescription(), serviceContext); } } else { String initialNodeName = PropsValues.WIKI_INITIAL_NODE_NAME; if (initialNodeName.equals(node.getName())) { WikiNode initialNode = WikiNodeLocalServiceUtil.fetchNode( portletDataContext.getScopeGroupId(), node.getName()); if (initialNode != null) { WikiNodeLocalServiceUtil.deleteWikiNode(initialNode); } } String nodeName = getNodeName(portletDataContext, node, node.getName(), 2); importedNode = WikiNodeLocalServiceUtil.addNode(userId, nodeName, node.getDescription(), serviceContext); } portletDataContext.importClassedModel(node, importedNode); }
public static List<String> getNodeNames(List<WikiNode> nodes) { List<String> nodeNames = new ArrayList<String>(nodes.size()); for (WikiNode node : nodes) { nodeNames.add(node.getName()); } return nodeNames; }
protected String getNodeName( PortletDataContext portletDataContext, WikiNode node, String name, int count) throws Exception { WikiNode existingNode = WikiNodeLocalServiceUtil.fetchNode(portletDataContext.getScopeGroupId(), name); if (existingNode == null) { return name; } String nodeName = node.getName(); return getNodeName( portletDataContext, node, nodeName.concat(StringPool.SPACE).concat(String.valueOf(count)), ++count); }
@Test public void testChangePageNodeWithRedirectPageNameDuplication() throws Exception { WikiNode destinationNode = WikiTestUtil.addNode(_group.getGroupId()); WikiTestUtil.addPage( TestPropsValues.getUserId(), _group.getGroupId(), _node.getNodeId(), "DuplicatedTitlePage", true); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); WikiPageLocalServiceUtil.renamePage( TestPropsValues.getUserId(), _node.getNodeId(), "DuplicatedTitlePage", "RenamedPage", serviceContext); WikiTestUtil.addPage( TestPropsValues.getUserId(), _group.getGroupId(), destinationNode.getNodeId(), "DuplicatedTitlePage", true); try { WikiPageLocalServiceUtil.changeNode( TestPropsValues.getUserId(), _node.getNodeId(), "RenamedPage", destinationNode.getNodeId(), serviceContext); Assert.fail(); } catch (NodeChangeException nce) { Assert.assertEquals("DuplicatedTitlePage", nce.getPageTitle()); Assert.assertEquals(destinationNode.getName(), nce.getNodeName()); Assert.assertEquals(NodeChangeException.DUPLICATE_PAGE, nce.getType()); } }
public static List<WikiNode> getNodes( List<WikiNode> nodes, String[] hiddenNodes, PermissionChecker permissionChecker) { nodes = ListUtil.copy(nodes); Arrays.sort(hiddenNodes); Iterator<WikiNode> itr = nodes.iterator(); while (itr.hasNext()) { WikiNode node = itr.next(); if (!(Arrays.binarySearch(hiddenNodes, node.getName()) < 0) || !WikiNodePermission.contains(permissionChecker, node, ActionKeys.VIEW)) { itr.remove(); } } return nodes; }
public static String getTitleText(Locale locale, String className, long classPK, String title) throws PortalException, SystemException { if (Validator.isNotNull(title)) { return title; } if (className.equals(BlogsEntry.class.getName())) { title = "Blog at "; } else if (className.equals(BookmarksFolder.class.getName())) { BookmarksFolder bookmarksFolder = BookmarksFolderLocalServiceUtil.getBookmarksFolder(classPK); return bookmarksFolder.getName(); } else if (className.equals(Layout.class.getName())) { Layout layout = LayoutLocalServiceUtil.getLayout(classPK); return layout.getName(locale); } else if (className.equals(MBCategory.class.getName())) { title = "Message Board at "; } else if (className.equals(WikiNode.class.getName())) { WikiNode wikiNode = WikiNodeLocalServiceUtil.getWikiNode(classPK); return wikiNode.getName(); } try { Group group = GroupLocalServiceUtil.getGroup(classPK); title += group.getDescriptiveName(locale); } catch (Exception e) { } if (Validator.isNull(title)) { title = String.valueOf(classPK); } return title; }
public static WikiNode getFirstNode(PortletRequest portletRequest) throws PortalException, SystemException { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = themeDisplay.getScopeGroupId(); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); List<WikiNode> nodes = WikiNodeLocalServiceUtil.getNodes(groupId); PortletPreferences preferences = portletRequest.getPreferences(); String[] visibleNodeNames = StringUtil.split(preferences.getValue("visibleNodes", null)); nodes = orderNodes(nodes, visibleNodeNames); String[] hiddenNodes = StringUtil.split(preferences.getValue("hiddenNodes", StringPool.BLANK)); Arrays.sort(hiddenNodes); for (WikiNode node : nodes) { if ((Arrays.binarySearch(hiddenNodes, node.getName()) < 0) && (WikiNodePermission.contains(permissionChecker, node, ActionKeys.VIEW))) { return node; } } return null; }
private String formatJournalArticleURL() { /* This checks if the object is viewable by the current user and, if so, works out * the original url for the search results. The "visible" flag variable is set for each one. */ Long lGroupId; Long lArticleId; Long lUserId; String strJournalURL = Global.strNoURLReturned; JournalContentSearchLocalServiceUtil jcslu = new JournalContentSearchLocalServiceUtil(); LayoutLocalServiceUtil llsu = new LayoutLocalServiceUtil(); List<Long> listLayouts = new ArrayList<Long>(); Layout layLayout; User user; int iCount = 0; this.isVisible = false; try { this.context = FacesContext.getCurrentInstance(); this.portletRequest = (PortletRequest) context.getExternalContext().getRequest(); this.themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); } catch (Exception e) { System.out.println(e); } try { lGroupId = Long.decode(this.getGroupId()); } catch (NumberFormatException n) { lGroupId = 0l; // zero long, not letter O } try { lArticleId = Long.decode(this.getArticleId()); } catch (NumberFormatException n) { lArticleId = 0l; // zero long, not letter O } try { lUserId = Long.decode(this.getUserId()); } catch (NumberFormatException n) { lUserId = 0l; // zero long, not letter O } if ((lGroupId != 0) && (lArticleId != 0)) { try { try { permissionChecker = themeDisplay.getPermissionChecker(); this.setIsVisible( permissionChecker.hasPermission( lGroupId, this.entryClassName, this.rootEntryClassPK, ActionKeys.VIEW)); if (this.isIsVisible()) { if (getEntryClassName().equalsIgnoreCase(JournalArticle.class.getName())) { iCount = jcslu.getLayoutIdsCount(lGroupId, false, articleId); listLayouts = jcslu.getLayoutIds(lGroupId, false, articleId); if (iCount > 0) { layLayout = llsu.getLayout(lGroupId, false, listLayouts.get(0)); layoutFriendlyURL = PortalUtil.getLayoutFriendlyURL(layLayout, themeDisplay); layoutFullURL = PortalUtil.getLayoutActualURL(layLayout, themeDisplay.getPathMain()); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); if (layoutFullURL.startsWith("http://")) { strJournalURL = layoutFullURL; } else { if (strHost.equalsIgnoreCase("localhost")) { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else { strJournalURL = layoutFriendlyURL; } } } } else if (getEntryClassName().equalsIgnoreCase(BlogsEntry.class.getName())) { BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(lArticleId); Group trgtGroup = GroupLocalServiceUtil.getGroup(lGroupId); String strFrUrl = trgtGroup.getFriendlyURL(); String strUrlPath; user = UserLocalServiceUtil.getUser(lUserId); if (strFrUrl.equalsIgnoreCase("/fishnet")) { strUrlPath = "/home/-/blogs/"; } else if (strFrUrl.equalsIgnoreCase("/fishlink")) { strUrlPath = "/home/-/blogs/"; } else if (strFrUrl.equalsIgnoreCase("/freshwater-biological-association")) { strUrlPath = "/home/-/blogs/"; } else { strUrlPath = "/blog/-/blogs/"; } layoutFriendlyURL = "/web" + strFrUrl + strUrlPath + entry.getUrlTitle(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else if (getEntryClassName().equalsIgnoreCase(WikiPage.class.getName())) { WikiPageResource pageResource = WikiPageResourceLocalServiceUtil.getPageResource(lArticleId); WikiPage wikiPage = WikiPageLocalServiceUtil.getPage( pageResource.getNodeId(), pageResource.getTitle()); WikiNode wikiNode = WikiNodeLocalServiceUtil.getNode(pageResource.getNodeId()); String strWikiNodeName = wikiNode.getName(); String strWikiTitle = wikiPage.getTitle(); Long lPageGroupId = wikiPage.getGroupId(); Group trgtGroup = GroupLocalServiceUtil.getGroup(lPageGroupId); String strFrUrl = trgtGroup.getFriendlyURL(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); // Extremely nasty hack! if (strFrUrl.equalsIgnoreCase("/tera")) { String strReplacedTitle = strWikiTitle.replaceAll("\\s", "\\+"); layoutFriendlyURL = "/web" + strFrUrl + "/home?p_p_id=54_INSTANCE_rU18&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_54_INSTANCE_rU18_struts_action=%2Fwiki_display%2Fview&_54_INSTANCE_rU18_nodeName=" + strWikiNodeName + "&_54_INSTANCE_rU18_title=" + strReplacedTitle; } else if (strFrUrl.equalsIgnoreCase("/fwl")) { layoutFriendlyURL = "/web" + strFrUrl + "/wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } else if (strFrUrl.equalsIgnoreCase("/fishlink")) { layoutFriendlyURL = "/web" + strFrUrl + strFrUrl + "-wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } else { layoutFriendlyURL = "/freshwater-wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle; } // </hack> strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; } else if (getEntryClassName().equalsIgnoreCase(DLFileEntry.class.getName())) { DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(lArticleId); lGroupId = fileEntry.getGroupId(); AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(getEntryClassName(), lArticleId); Long lEntryId = assetEntry.getEntryId(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); // Another hack layoutFriendlyURL = "/fwl/documents/-/asset_publisher/8Ztl/document/id/" + lEntryId; strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + "/web" + layoutFriendlyURL; if (fileEntry.getTitle().isEmpty()) { this.setTitle("From Document Library"); } else { this.setTitle(fileEntry.getTitle()); } // } else if (getEntryClassName().equalsIgnoreCase(IGImage.class.getName())) { IGImage image = IGImageLocalServiceUtil.getImage(lArticleId); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "igimage.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } // PortletURL viewImageURL = new PortletURLImpl(request, PortletKeys.IMAGE_GALLERY, // plid, PortletRequest.RENDER_PHASE); // viewImageURL.setWindowState(WindowState.MAXIMIZED); // viewImageURL.setParameter("struts_action", "/image_gallery/view"); // viewImageURL.setParameter("folderId", String.valueOf(image.getFolderId())); } else if (getEntryClassName().equalsIgnoreCase(MBMessage.class.getName())) { MBMessage message = MBMessageLocalServiceUtil.getMessage(lArticleId); String aHref = "<a href=" + themeDisplay.getPathMain() + "/message_boards/find_message?messageId=" + message.getMessageId() + ">"; strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "mbmessage.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } } else if (getEntryClassName().equalsIgnoreCase(BookmarksEntry.class.getName())) { BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(lArticleId); String entryURL = themeDisplay.getPathMain() + "/bookmarks/open_entry?entryId=" + entry.getEntryId(); strHost = portletRequest.getServerName(); iServerPort = portletRequest.getServerPort(); strScheme = portletRequest.getScheme(); layoutFriendlyURL = "bookmarks.fba.org.uk"; // if (layoutFullURL.startsWith("http://")) { // strJournalURL = layoutFullURL; // } else { strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL; // } } } } catch (PortalException ex) { Logger.getLogger(Liferay.class.getName()).log(Level.SEVERE, null, ex); } } catch (SystemException ex) { Logger.getLogger(Liferay.class.getName()).log(Level.SEVERE, null, ex); } } return strJournalURL; }
protected void compareVersions(RenderRequest renderRequest, RenderResponse renderResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); long nodeId = ParamUtil.getLong(renderRequest, "nodeId"); String title = ParamUtil.getString(renderRequest, "title"); double sourceVersion = ParamUtil.getDouble(renderRequest, "sourceVersion"); double targetVersion = ParamUtil.getDouble(renderRequest, "targetVersion"); String type = ParamUtil.getString(renderRequest, "type", "escape"); WikiPage sourcePage = WikiPageServiceUtil.getPage(nodeId, title, sourceVersion); WikiPage targetPage = WikiPageServiceUtil.getPage(nodeId, title, targetVersion); if (type.equals("html")) { WikiNode sourceNode = sourcePage.getNode(); PortletURL viewPageURL = renderResponse.createRenderURL(); viewPageURL.setParameter("struts_action", "/wiki/view"); viewPageURL.setParameter("nodeName", sourceNode.getName()); PortletURL editPageURL = renderResponse.createRenderURL(); editPageURL.setParameter("struts_action", "/wiki/edit_page"); editPageURL.setParameter("nodeId", String.valueOf(nodeId)); editPageURL.setParameter("title", title); String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix( themeDisplay.getPathMain(), themeDisplay.getPlid(), nodeId, title); String htmlDiffResult = WikiUtil.diffHtml(sourcePage, targetPage, viewPageURL, editPageURL, attachmentURLPrefix); renderRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, htmlDiffResult); } else { String sourceContent = sourcePage.getContent(); String targetContent = targetPage.getContent(); sourceContent = WikiUtil.processContent(sourceContent); targetContent = WikiUtil.processContent(targetContent); if (type.equals("strip")) { sourceContent = HtmlUtil.extractText(sourceContent); targetContent = HtmlUtil.extractText(targetContent); } else { sourceContent = HtmlUtil.escape(sourceContent); targetContent = HtmlUtil.escape(targetContent); } List<DiffResult>[] diffResults = DiffUtil.diff( new UnsyncStringReader(sourceContent), new UnsyncStringReader(targetContent)); renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults); } renderRequest.setAttribute(WebKeys.WIKI_NODE_ID, nodeId); renderRequest.setAttribute(WebKeys.TITLE, title); renderRequest.setAttribute(WebKeys.SOURCE_VERSION, sourceVersion); renderRequest.setAttribute(WebKeys.TARGET_VERSION, targetVersion); }
protected void processRegularPages( long userId, WikiNode node, Element rootElement, List<String> specialNamespaces, Map<String, String> usersMap, InputStream imagesInputStream, Map<String, String[]> options) { boolean importLatestVersion = MapUtil.getBoolean(options, WikiImporterKeys.OPTIONS_IMPORT_LATEST_VERSION); boolean strictImportMode = MapUtil.getBoolean(options, WikiImporterKeys.OPTIONS_STRICT_IMPORT_MODE); ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker(); int count = 0; int percentage = 10; int maxPercentage = 50; if (imagesInputStream == null) { maxPercentage = 99; } List<Element> pageElements = rootElement.elements("page"); for (int i = 0; i < pageElements.size(); i++) { Element pageElement = pageElements.get(i); String title = pageElement.elementText("title"); title = normalizeTitle(title); percentage = Math.min(10 + (i * (maxPercentage - percentage)) / pageElements.size(), maxPercentage); progressTracker.setPercent(percentage); if (isSpecialMediaWikiPage(title, specialNamespaces)) { continue; } List<Element> revisionElements = pageElement.elements("revision"); if (importLatestVersion) { Element lastRevisionElement = revisionElements.get(revisionElements.size() - 1); revisionElements = new ArrayList<Element>(); revisionElements.add(lastRevisionElement); } for (Element revisionElement : revisionElements) { Element contributorElement = revisionElement.element("contributor"); String author = contributorElement.elementText("username"); String content = revisionElement.elementText("text"); String summary = revisionElement.elementText("comment"); try { importPage(userId, author, node, title, content, summary, usersMap, strictImportMode); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Page with title " + title + " could not be imported", e); } } } count++; } if (_log.isInfoEnabled()) { _log.info("Imported " + count + " pages into " + node.getName()); } }
protected void processImages(long userId, WikiNode node, InputStream imagesInputStream) throws Exception { if (imagesInputStream == null) { return; } ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker(); int count = 0; ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(imagesInputStream); List<String> entries = zipReader.getEntries(); int total = entries.size(); if (total > 0) { try { WikiPageLocalServiceUtil.getPage(node.getNodeId(), SHARED_IMAGES_TITLE); } catch (NoSuchPageException nspe) { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); WikiPageLocalServiceUtil.addPage( userId, node.getNodeId(), SHARED_IMAGES_TITLE, SHARED_IMAGES_CONTENT, null, true, serviceContext); } } List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<ObjectValuePair<String, InputStream>>(); try { int percentage = 50; for (int i = 0; i < entries.size(); i++) { String entry = entries.get(i); String key = entry; InputStream inputStream = zipReader.getEntryAsInputStream(entry); String[] paths = StringUtil.split(key, CharPool.SLASH); if (!isValidImage(paths, inputStream)) { if (_log.isInfoEnabled()) { _log.info("Ignoring " + key); } continue; } String fileName = StringUtil.toLowerCase(paths[paths.length - 1]); ObjectValuePair<String, InputStream> inputStreamOVP = new ObjectValuePair<String, InputStream>(fileName, inputStream); inputStreamOVPs.add(inputStreamOVP); count++; if ((i % 5) == 0) { WikiPageLocalServiceUtil.addPageAttachments( userId, node.getNodeId(), SHARED_IMAGES_TITLE, inputStreamOVPs); inputStreamOVPs.clear(); percentage = Math.min(50 + (i * 50) / total, 99); progressTracker.setPercent(percentage); } } if (!inputStreamOVPs.isEmpty()) { WikiPageLocalServiceUtil.addPageAttachments( userId, node.getNodeId(), SHARED_IMAGES_TITLE, inputStreamOVPs); } } finally { for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) { InputStream inputStream = inputStreamOVP.getValue(); StreamUtil.cleanUp(inputStream); } } zipReader.close(); if (_log.isInfoEnabled()) { _log.info("Imported " + count + " images into " + node.getName()); } }
@Test public void testUpdateExisting() throws Exception { long pk = RandomTestUtil.nextLong(); WikiNode newWikiNode = _persistence.create(pk); newWikiNode.setUuid(RandomTestUtil.randomString()); newWikiNode.setGroupId(RandomTestUtil.nextLong()); newWikiNode.setCompanyId(RandomTestUtil.nextLong()); newWikiNode.setUserId(RandomTestUtil.nextLong()); newWikiNode.setUserName(RandomTestUtil.randomString()); newWikiNode.setCreateDate(RandomTestUtil.nextDate()); newWikiNode.setModifiedDate(RandomTestUtil.nextDate()); newWikiNode.setName(RandomTestUtil.randomString()); newWikiNode.setDescription(RandomTestUtil.randomString()); newWikiNode.setLastPostDate(RandomTestUtil.nextDate()); newWikiNode.setStatus(RandomTestUtil.nextInt()); newWikiNode.setStatusByUserId(RandomTestUtil.nextLong()); newWikiNode.setStatusByUserName(RandomTestUtil.randomString()); newWikiNode.setStatusDate(RandomTestUtil.nextDate()); _persistence.update(newWikiNode); WikiNode existingWikiNode = _persistence.findByPrimaryKey(newWikiNode.getPrimaryKey()); Assert.assertEquals(existingWikiNode.getUuid(), newWikiNode.getUuid()); Assert.assertEquals(existingWikiNode.getNodeId(), newWikiNode.getNodeId()); Assert.assertEquals(existingWikiNode.getGroupId(), newWikiNode.getGroupId()); Assert.assertEquals(existingWikiNode.getCompanyId(), newWikiNode.getCompanyId()); Assert.assertEquals(existingWikiNode.getUserId(), newWikiNode.getUserId()); Assert.assertEquals(existingWikiNode.getUserName(), newWikiNode.getUserName()); Assert.assertEquals( Time.getShortTimestamp(existingWikiNode.getCreateDate()), Time.getShortTimestamp(newWikiNode.getCreateDate())); Assert.assertEquals( Time.getShortTimestamp(existingWikiNode.getModifiedDate()), Time.getShortTimestamp(newWikiNode.getModifiedDate())); Assert.assertEquals(existingWikiNode.getName(), newWikiNode.getName()); Assert.assertEquals(existingWikiNode.getDescription(), newWikiNode.getDescription()); Assert.assertEquals( Time.getShortTimestamp(existingWikiNode.getLastPostDate()), Time.getShortTimestamp(newWikiNode.getLastPostDate())); Assert.assertEquals(existingWikiNode.getStatus(), newWikiNode.getStatus()); Assert.assertEquals(existingWikiNode.getStatusByUserId(), newWikiNode.getStatusByUserId()); Assert.assertEquals(existingWikiNode.getStatusByUserName(), newWikiNode.getStatusByUserName()); Assert.assertEquals( Time.getShortTimestamp(existingWikiNode.getStatusDate()), Time.getShortTimestamp(newWikiNode.getStatusDate())); }
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); } }