@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; } }
public void testFindByPrimaryKeyExisting() throws Exception { WikiPageResource newWikiPageResource = addWikiPageResource(); WikiPageResource existingWikiPageResource = _persistence.findByPrimaryKey(newWikiPageResource.getPrimaryKey()); assertEquals(existingWikiPageResource, newWikiPageResource); }
@Override protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay) throws Exception { PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (!WikiPagePermission.contains(permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) { return null; } String groupName = StringPool.BLANK; if (activity.getGroupId() != themeDisplay.getScopeGroupId()) { groupName = getGroupName(activity.getGroupId(), themeDisplay); } String creatorUserName = getUserName(activity.getUserId(), themeDisplay); int activityType = activity.getType(); // Link WikiPageResource pageResource = WikiPageResourceLocalServiceUtil.getPageResource(activity.getClassPK()); String link = themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/wiki/find_page?pageResourcePrimKey=" + activity.getClassPK(); // Title String titlePattern = null; if (activityType == WikiActivityKeys.ADD_PAGE) { titlePattern = "activity-wiki-add-page"; } else if (activityType == WikiActivityKeys.UPDATE_PAGE) { titlePattern = "activity-wiki-update-page"; } if (Validator.isNotNull(groupName)) { titlePattern += "-in"; } String pageTitle = wrapLink(link, HtmlUtil.escape(cleanContent(pageResource.getTitle()))); Object[] titleArguments = new Object[] {groupName, creatorUserName, pageTitle}; String title = themeDisplay.translate(titlePattern, titleArguments); // Body String body = StringPool.BLANK; return new SocialActivityFeedEntry(link, title, body); }
public void testCreate() throws Exception { long pk = nextLong(); WikiPageResource wikiPageResource = _persistence.create(pk); assertNotNull(wikiPageResource); assertEquals(wikiPageResource.getPrimaryKey(), pk); }
public void testRemove() throws Exception { WikiPageResource newWikiPageResource = addWikiPageResource(); _persistence.remove(newWikiPageResource); WikiPageResource existingWikiPageResource = _persistence.fetchByPrimaryKey(newWikiPageResource.getPrimaryKey()); assertNull(existingWikiPageResource); }
protected WikiPageResource addWikiPageResource() throws Exception { long pk = nextLong(); WikiPageResource wikiPageResource = _persistence.create(pk); wikiPageResource.setUuid(randomString()); wikiPageResource.setNodeId(nextLong()); wikiPageResource.setTitle(randomString()); _persistence.update(wikiPageResource, false); return wikiPageResource; }
@Override public void updateTitle(long classPK, String name) throws PortalException, SystemException { WikiPage page = WikiPageLocalServiceUtil.getPage(classPK); page.setTitle(name); WikiPageLocalServiceUtil.updateWikiPage(page); WikiPageResource pageResource = WikiPageResourceLocalServiceUtil.getPageResource(page.getResourcePrimKey()); pageResource.setTitle(name); WikiPageResourceLocalServiceUtil.updateWikiPageResource(pageResource); }
public void testDynamicQueryByPrimaryKeyExisting() throws Exception { WikiPageResource newWikiPageResource = addWikiPageResource(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( WikiPageResource.class, WikiPageResource.class.getClassLoader()); dynamicQuery.add( RestrictionsFactoryUtil.eq("resourcePrimKey", newWikiPageResource.getResourcePrimKey())); List<WikiPageResource> result = _persistence.findWithDynamicQuery(dynamicQuery); assertEquals(1, result.size()); WikiPageResource existingWikiPageResource = result.get(0); assertEquals(existingWikiPageResource, newWikiPageResource); }
public int compareTo(WikiPageResource wikiPageResource) { long primaryKey = wikiPageResource.getPrimaryKey(); if (getPrimaryKey() < primaryKey) { return -1; } else if (getPrimaryKey() > primaryKey) { return 1; } else { return 0; } }
public void testResetOriginalValues() throws Exception { if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) { return; } WikiPageResource newWikiPageResource = addWikiPageResource(); _persistence.clearCache(); WikiPageResourceModelImpl existingWikiPageResourceModelImpl = (WikiPageResourceModelImpl) _persistence.findByPrimaryKey(newWikiPageResource.getPrimaryKey()); assertEquals( existingWikiPageResourceModelImpl.getNodeId(), existingWikiPageResourceModelImpl.getOriginalNodeId()); assertTrue( Validator.equals( existingWikiPageResourceModelImpl.getTitle(), existingWikiPageResourceModelImpl.getOriginalTitle())); }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } WikiPageResource wikiPageResource = null; try { wikiPageResource = (WikiPageResource) obj; } catch (ClassCastException cce) { return false; } long primaryKey = wikiPageResource.getPrimaryKey(); if (getPrimaryKey() == primaryKey) { return true; } else { return false; } }
public void testDynamicQueryByProjectionExisting() throws Exception { WikiPageResource newWikiPageResource = addWikiPageResource(); DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass( WikiPageResource.class, WikiPageResource.class.getClassLoader()); dynamicQuery.setProjection(ProjectionFactoryUtil.property("resourcePrimKey")); Object newResourcePrimKey = newWikiPageResource.getResourcePrimKey(); dynamicQuery.add( RestrictionsFactoryUtil.in("resourcePrimKey", new Object[] {newResourcePrimKey})); List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery); assertEquals(1, result.size()); Object existingResourcePrimKey = result.get(0); assertEquals(existingResourcePrimKey, newResourcePrimKey); }
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; }
public void testUpdateExisting() throws Exception { long pk = nextLong(); WikiPageResource newWikiPageResource = _persistence.create(pk); newWikiPageResource.setUuid(randomString()); newWikiPageResource.setNodeId(nextLong()); newWikiPageResource.setTitle(randomString()); _persistence.update(newWikiPageResource, false); WikiPageResource existingWikiPageResource = _persistence.findByPrimaryKey(newWikiPageResource.getPrimaryKey()); assertEquals(existingWikiPageResource.getUuid(), newWikiPageResource.getUuid()); assertEquals( existingWikiPageResource.getResourcePrimKey(), newWikiPageResource.getResourcePrimKey()); assertEquals(existingWikiPageResource.getNodeId(), newWikiPageResource.getNodeId()); assertEquals(existingWikiPageResource.getTitle(), newWikiPageResource.getTitle()); }