@Override public void deleteStagedModel(String uuid, long groupId, String className, String extraData) throws PortalException, SystemException { WikiNode wikiNode = WikiNodeLocalServiceUtil.fetchWikiNodeByUuidAndGroupId(uuid, groupId); if (wikiNode != null) { WikiNodeLocalServiceUtil.deleteNode(wikiNode); } }
@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); }
@Override protected void doImportMissingReference( PortletDataContext portletDataContext, String uuid, long groupId, long nodeId) throws Exception { WikiNode existingNode = WikiNodeLocalServiceUtil.fetchNodeByUuidAndGroupId(uuid, groupId); Map<Long, Long> nodeIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiNode.class); nodeIds.put(nodeId, existingNode.getNodeId()); }
@Override protected boolean validateMissingReference(String uuid, long companyId, long groupId) throws Exception { WikiNode node = WikiNodeLocalServiceUtil.fetchNodeByUuidAndGroupId(uuid, groupId); if (node == null) { return false; } return true; }
public static WikiNode getFirstVisibleNode(PortletRequest portletRequest) throws PortalException, SystemException { ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); WikiNode node = null; int nodesCount = WikiNodeLocalServiceUtil.getNodesCount(themeDisplay.getScopeGroupId()); if (nodesCount == 0) { Layout layout = themeDisplay.getLayout(); ServiceContext serviceContext = ServiceContextFactory.getInstance(WikiNode.class.getName(), portletRequest); serviceContext.setAddCommunityPermissions(true); if (layout.isPublicLayout()) { serviceContext.setAddGuestPermissions(true); } else { serviceContext.setAddGuestPermissions(false); } node = WikiNodeLocalServiceUtil.addDefaultNode(themeDisplay.getUserId(), serviceContext); } else { node = WikiUtil.getFirstNode(portletRequest); if (node == null) { throw new PrincipalException(); } return node; } portletRequest.setAttribute(WebKeys.WIKI_NODE, node); return node; }
@Override protected BaseModel<?> getParentBaseModel(Group group, ServiceContext serviceContext) throws Exception { serviceContext = (ServiceContext) serviceContext.clone(); serviceContext.setWorkflowAction(WorkflowConstants.STATUS_APPROVED); return WikiNodeLocalServiceUtil.addNode( TestPropsValues.getUserId(), RandomTestUtil.randomString(_NODE_NAME_MAX_LENGTH), RandomTestUtil.randomString(), serviceContext); }
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); }
@Override protected void doRestoreStagedModel(PortletDataContext portletDataContext, WikiNode node) throws Exception { long userId = portletDataContext.getUserId(node.getUserUuid()); WikiNode existingNode = WikiNodeLocalServiceUtil.fetchNodeByUuidAndGroupId( node.getUuid(), portletDataContext.getScopeGroupId()); if ((existingNode == null) || !existingNode.isInTrash()) { return; } TrashHandler trashHandler = existingNode.getTrashHandler(); if (trashHandler.isRestorable(existingNode.getNodeId())) { trashHandler.restoreTrashEntry(userId, existingNode.getNodeId()); } }
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; }
@Test public void testActionableDynamicQuery() throws Exception { final IntegerWrapper count = new IntegerWrapper(); ActionableDynamicQuery actionableDynamicQuery = WikiNodeLocalServiceUtil.getActionableDynamicQuery(); actionableDynamicQuery.setPerformActionMethod( new ActionableDynamicQuery.PerformActionMethod() { @Override public void performAction(Object object) { WikiNode wikiNode = (WikiNode) object; Assert.assertNotNull(wikiNode); count.increment(); } }); actionableDynamicQuery.performActions(); Assert.assertEquals(count.getValue(), _persistence.countAll()); }
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; }
@Override protected void moveParentBaseModelToTrash(long primaryKey) throws Exception { WikiNodeLocalServiceUtil.moveNodeToTrash(TestPropsValues.getUserId(), primaryKey); }
private void trashWikiAttachments(boolean restore) throws Exception { ServiceContext serviceContext = new ServiceContext(); serviceContext.setScopeGroupId(TestPropsValues.getGroupId()); WikiNode wikiNode = WikiNodeLocalServiceUtil.addNode( TestPropsValues.getUserId(), ServiceTestUtil.randomString(), "", serviceContext); WikiPage wikiPage = WikiPageLocalServiceUtil.addPage( TestPropsValues.getUserId(), wikiNode.getNodeId(), ServiceTestUtil.randomString(), null, WikiPageConstants.NEW, true, serviceContext); String[] attachmentsFiles = wikiPage.getAttachmentsFiles(); int initialNotInTrashCount = attachmentsFiles.length; String[] deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); int initialTrashEntriesCount = deletedAttachmentsFiles.length; Class<?> clazz = getClass(); byte[] fileBytes = FileUtil.getBytes(clazz.getResourceAsStream("dependencies/OSX_Test.docx")); File file = null; if ((fileBytes != null) && (fileBytes.length > 0)) { file = FileUtil.createTempFile(fileBytes); } WikiPageLocalServiceUtil.addPageAttachment( TestPropsValues.getUserId(), wikiNode.getNodeId(), wikiPage.getTitle(), ServiceTestUtil.randomString() + ".txt", file); attachmentsFiles = wikiPage.getAttachmentsFiles(); Assert.assertEquals(initialNotInTrashCount + 1, attachmentsFiles.length); deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length); String fileName = attachmentsFiles[0]; WikiPageLocalServiceUtil.movePageAttachmentToTrash( wikiNode.getNodeId(), wikiPage.getTitle(), fileName); attachmentsFiles = wikiPage.getAttachmentsFiles(); Assert.assertEquals(initialNotInTrashCount, attachmentsFiles.length); deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); Assert.assertEquals(initialTrashEntriesCount + 1, deletedAttachmentsFiles.length); fileName = deletedAttachmentsFiles[0]; if (restore) { WikiPageLocalServiceUtil.movePageAttachmentFromTrash( wikiNode.getNodeId(), wikiPage.getTitle(), fileName); attachmentsFiles = wikiPage.getAttachmentsFiles(); Assert.assertEquals(initialNotInTrashCount + 1, attachmentsFiles.length); deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length); } else { WikiPageLocalServiceUtil.deletePageAttachment( wikiNode.getNodeId(), wikiPage.getTitle(), fileName); attachmentsFiles = wikiPage.getAttachmentsFiles(); Assert.assertEquals(initialNotInTrashCount, attachmentsFiles.length); deletedAttachmentsFiles = wikiPage.getDeletedAttachmentsFiles(); Assert.assertEquals(initialTrashEntriesCount, deletedAttachmentsFiles.length); } }
@Override protected void addSubscriptionContainerModel(long containerModelId) throws Exception { WikiNodeLocalServiceUtil.subscribeNode(TestPropsValues.getUserId(), containerModelId); }