protected void verifyContentSearch(long groupId, String portletId) throws Exception { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement( "select preferences from PortletPreferences inner join " + "Layout on PortletPreferences.plid = Layout.plid where " + "groupId = ? and portletId = ?"); ps.setLong(1, groupId); ps.setString(2, portletId); rs = ps.executeQuery(); while (rs.next()) { String xml = rs.getString("preferences"); PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.fromDefaultXML(xml); String articleId = portletPreferences.getValue("articleId", null); List<JournalContentSearch> contentSearches = JournalContentSearchLocalServiceUtil.getArticleContentSearches(groupId, articleId); if (contentSearches.isEmpty()) { continue; } JournalContentSearch contentSearch = contentSearches.get(0); JournalContentSearchLocalServiceUtil.updateContentSearch( contentSearch.getGroupId(), contentSearch.isPrivateLayout(), contentSearch.getLayoutId(), contentSearch.getPortletId(), articleId, true); } } finally { DataAccess.cleanUp(con, ps, rs); } }
protected String getJournalURL(ThemeDisplay themeDisplay, long groupId, Document result) throws Exception { Layout layout = themeDisplay.getLayout(); String articleId = result.get(Field.ENTRY_CLASS_PK); String version = result.get("version"); List<Long> hitLayoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds( layout.getGroupId(), layout.isPrivateLayout(), articleId); if (hitLayoutIds.size() > 0) { Long hitLayoutId = hitLayoutIds.get(0); Layout hitLayout = LayoutLocalServiceUtil.getLayout( layout.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue()); return PortalUtil.getLayoutURL(hitLayout, themeDisplay); } else { StringBundler sb = new StringBundler(7); sb.append(themeDisplay.getPathMain()); sb.append("/journal/view_article_content?groupId="); sb.append(groupId); sb.append("&articleId="); sb.append(articleId); sb.append("&version="); sb.append(version); return sb.toString(); } }
public void recordHits(Hits hits, long groupId, boolean privateLayout) throws Exception { setSearcher(((HitsImpl) hits).getSearcher()); // This can later be optimized according to LEP-915. List docs = new ArrayList(hits.getLength()); List scores = new ArrayList(hits.getLength()); for (int i = 0; i < hits.getLength(); i++) { Document doc = hits.doc(i); String articleId = doc.get("articleId"); long articleGroupId = GetterUtil.getLong(doc.get(LuceneFields.GROUP_ID)); if (JournalContentSearchLocalServiceUtil.getLayoutIdsCount(groupId, privateLayout, articleId) > 0) { docs.add(hits.doc(i)); scores.add(new Float(hits.score(i))); } else if (!isShowListed() && (articleGroupId == groupId)) { docs.add(hits.doc(i)); scores.add(new Float(hits.score(i))); } } setLength(docs.size()); setDocs((Document[]) docs.toArray(new Document[0])); setScores((Float[]) scores.toArray(new Float[0])); setSearchTime((float) (System.currentTimeMillis() - getStart()) / Time.SECOND); }
@Override public String getURLViewInContext( LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse, String noSuchEntryRedirect) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY); Layout layout = themeDisplay.getLayout(); if (Validator.isNotNull(_article.getLayoutUuid())) { layout = LayoutLocalServiceUtil.getLayoutByUuidAndCompanyId( _article.getLayoutUuid(), _article.getCompanyId()); } String portletId = (String) liferayPortletRequest.getAttribute(WebKeys.PORTLET_ID); PortletPreferences portletSetup = PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId); String linkToLayoutUuid = GetterUtil.getString(portletSetup.getValue("portletSetupLinkToLayoutUuid", null)); if (Validator.isNotNull(_article.getLayoutUuid()) && Validator.isNull(linkToLayoutUuid)) { Group group = themeDisplay.getScopeGroup(); if (group.getGroupId() != _article.getGroupId()) { group = GroupLocalServiceUtil.getGroup(_article.getGroupId()); } String groupFriendlyURL = PortalUtil.getGroupFriendlyURL(group, layout.isPrivateLayout(), themeDisplay); return PortalUtil.addPreservedParameters( themeDisplay, groupFriendlyURL .concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR) .concat(_article.getUrlTitle())); } List<Long> hitLayoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds( _article.getGroupId(), layout.isPrivateLayout(), _article.getArticleId()); if (!hitLayoutIds.isEmpty()) { Long hitLayoutId = hitLayoutIds.get(0); Layout hitLayout = LayoutLocalServiceUtil.getLayout( _article.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue()); return PortalUtil.getLayoutURL(hitLayout, themeDisplay); } return noSuchEntryRedirect; }
public JournalContentSearchActionableDynamicQuery() throws SystemException { setBaseLocalService(JournalContentSearchLocalServiceUtil.getService()); setClass(JournalContentSearch.class); setClassLoader(PortalClassLoaderUtil.getClassLoader()); setPrimaryKeyPropertyName("contentSearchId"); }
protected void importJournalArticle( PortletDataContext portletDataContext, Layout layout, Element layoutElement) throws Exception { UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties(); String articleId = typeSettingsProperties.getProperty("article-id", StringPool.BLANK); if (Validator.isNull(articleId)) { return; } JournalPortletDataHandlerImpl.importReferencedData(portletDataContext, layoutElement); Element structureElement = layoutElement.element("structure"); if (structureElement != null) { JournalPortletDataHandlerImpl.importStructure(portletDataContext, structureElement); } Element templateElement = layoutElement.element("template"); if (templateElement != null) { JournalPortletDataHandlerImpl.importTemplate(portletDataContext, templateElement); } Element articleElement = layoutElement.element("article"); if (articleElement != null) { JournalPortletDataHandlerImpl.importArticle(portletDataContext, articleElement); } Map<String, String> articleIds = (Map<String, String>) portletDataContext.getNewPrimaryKeysMap(JournalArticle.class + ".articleId"); articleId = MapUtil.getString(articleIds, articleId, articleId); typeSettingsProperties.setProperty("article-id", articleId); JournalContentSearchLocalServiceUtil.updateContentSearch( portletDataContext.getScopeGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), StringPool.BLANK, articleId, true); }
@Override public void setAddToPagePreferences( PortletPreferences preferences, String portletId, ThemeDisplay themeDisplay) throws Exception { preferences.setValue("articleId", _article.getArticleId()); preferences.setValue("groupId", String.valueOf(_article.getGroupId())); Layout layout = themeDisplay.getLayout(); JournalContentSearchLocalServiceUtil.updateContentSearch( layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), portletId, _article.getArticleId(), true); }
public void recordHits(Hits hits, long groupId, boolean privateLayout, int start, int end) throws Exception { // This can later be optimized according to LEP-915. List<Document> docs = new ArrayList<Document>(); List<Float> scores = new ArrayList<Float>(); Document[] docsArray = hits.getDocs(); for (int i = 0; i < docsArray.length; i++) { Document doc = hits.doc(i); String articleId = doc.get(Field.ARTICLE_ID); long articleGroupId = GetterUtil.getLong(doc.get(Field.GROUP_ID)); int layoutIdsCount = JournalContentSearchLocalServiceUtil.getLayoutIdsCount(groupId, privateLayout, articleId); if ((layoutIdsCount > 0) || (!isShowListed() && (articleGroupId == groupId))) { docs.add(hits.doc(i)); scores.add(hits.score(i)); } } int length = docs.size(); hits.setLength(length); if (end > length) { end = length; } docs = docs.subList(start, end); scores = scores.subList(start, end); hits.setDocs(docs.toArray(new Document[docs.size()])); hits.setScores(ArrayUtil.toFloatArray(scores)); hits.setSearchTime((float) (System.currentTimeMillis() - hits.getStart()) / Time.SECOND); }
protected String getEntryURL( ResourceRequest resourceRequest, JournalFeed feed, JournalArticle article, Layout layout, ThemeDisplay themeDisplay) throws Exception { List<Long> hitLayoutIds = JournalContentSearchLocalServiceUtil.getLayoutIds( layout.getGroupId(), layout.isPrivateLayout(), article.getArticleId()); if (hitLayoutIds.size() > 0) { Long hitLayoutId = hitLayoutIds.get(0); Layout hitLayout = LayoutLocalServiceUtil.getLayout( layout.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue()); return PortalUtil.getLayoutFriendlyURL(hitLayout, themeDisplay); } else { long plid = PortalUtil.getPlidFromFriendlyURL(feed.getCompanyId(), feed.getTargetLayoutFriendlyUrl()); String portletId = PortletKeys.JOURNAL_CONTENT; if (Validator.isNotNull(feed.getTargetPortletId())) { portletId = feed.getTargetPortletId(); } PortletURL entryURL = new PortletURLImpl(resourceRequest, portletId, plid, PortletRequest.RENDER_PHASE); entryURL.setParameter("struts_action", "/journal_content/view"); entryURL.setParameter("groupId", String.valueOf(article.getGroupId())); entryURL.setParameter("articleId", article.getArticleId()); return entryURL.toString(); } }
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 PortletPreferences doImportData( PortletDataContext context, String portletId, PortletPreferences preferences, String data) throws Exception { context.importPermissions( "com.liferay.portlet.journal", context.getSourceGroupId(), context.getScopeGroupId()); if (Validator.isNull(data)) { return null; } Document document = SAXReaderUtil.read(data); Element rootElement = document.getRootElement(); Element dlFoldersElement = rootElement.element("dl-folders"); List<Element> dlFolderElements = Collections.EMPTY_LIST; if (dlFoldersElement != null) { dlFolderElements = dlFoldersElement.elements("folder"); } for (Element folderElement : dlFolderElements) { DLPortletDataHandlerImpl.importFolder(context, folderElement); } Element dlFileEntriesElement = rootElement.element("dl-file-entries"); List<Element> dlFileEntryElements = Collections.EMPTY_LIST; if (dlFileEntriesElement != null) { dlFileEntryElements = dlFileEntriesElement.elements("file-entry"); } for (Element fileEntryElement : dlFileEntryElements) { DLPortletDataHandlerImpl.importFileEntry(context, fileEntryElement); } Element dlFileRanksElement = rootElement.element("dl-file-ranks"); List<Element> dlFileRankElements = Collections.EMPTY_LIST; if (dlFileRanksElement != null) { dlFileRankElements = dlFileRanksElement.elements("file-rank"); } for (Element fileRankElement : dlFileRankElements) { DLPortletDataHandlerImpl.importFileRank(context, fileRankElement); } Element igFoldersElement = rootElement.element("ig-folders"); List<Element> igFolderElements = Collections.EMPTY_LIST; if (igFoldersElement != null) { igFolderElements = igFoldersElement.elements("folder"); } for (Element folderElement : igFolderElements) { IGPortletDataHandlerImpl.importFolder(context, folderElement); } Element igImagesElement = rootElement.element("ig-images"); List<Element> igImageElements = Collections.EMPTY_LIST; if (igImagesElement != null) { igImageElements = igImagesElement.elements("image"); } for (Element imageElement : igImageElements) { IGPortletDataHandlerImpl.importImage(context, imageElement); } Element structureElement = rootElement.element("structure"); if (structureElement != null) { JournalPortletDataHandlerImpl.importStructure(context, structureElement); } Element templateElement = rootElement.element("template"); if (templateElement != null) { JournalPortletDataHandlerImpl.importTemplate(context, templateElement); } Element articleElement = rootElement.element("article"); if (articleElement != null) { JournalPortletDataHandlerImpl.importArticle(context, articleElement); } String articleId = preferences.getValue("article-id", StringPool.BLANK); if (Validator.isNotNull(articleId)) { Map<String, String> articleIds = (Map<String, String>) context.getNewPrimaryKeysMap(JournalArticle.class); articleId = MapUtil.getString(articleIds, articleId, articleId); preferences.setValue("group-id", String.valueOf(context.getScopeGroupId())); preferences.setValue("article-id", articleId); Layout layout = LayoutLocalServiceUtil.getLayout(context.getPlid()); JournalContentSearchLocalServiceUtil.updateContentSearch( context.getScopeGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), portletId, articleId, true); } return preferences; }
private long _initCompany(ServletContext servletContext, String webId) { // Begin initializing company if (_log.isDebugEnabled()) { _log.debug("Begin initializing company with web id " + webId); } long companyId = 0; try { Company company = CompanyLocalServiceUtil.checkCompany(webId); companyId = company.getCompanyId(); } catch (Exception e) { _log.error(e, e); } CompanyThreadLocal.setCompanyId(companyId); // Lucene LuceneHelperUtil.startup(companyId); // Initialize display if (_log.isDebugEnabled()) { _log.debug("Initialize display"); } try { String xml = HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-display.xml")); PortletCategory portletCategory = (PortletCategory) WebAppPool.get(companyId, WebKeys.PORTLET_CATEGORY); if (portletCategory == null) { portletCategory = new PortletCategory(); } PortletCategory newPortletCategory = PortletLocalServiceUtil.getEARDisplay(xml); portletCategory.merge(newPortletCategory); for (int i = 0; i < _companyIds.length; i++) { long currentCompanyId = _companyIds[i]; PortletCategory currentPortletCategory = (PortletCategory) WebAppPool.get(currentCompanyId, WebKeys.PORTLET_CATEGORY); if (currentPortletCategory != null) { portletCategory.merge(currentPortletCategory); } } WebAppPool.put(companyId, WebKeys.PORTLET_CATEGORY, portletCategory); } catch (Exception e) { _log.error(e, e); } // Check journal content search if (_log.isDebugEnabled()) { _log.debug("Check journal content search"); } if (GetterUtil.getBoolean(PropsUtil.get(PropsKeys.JOURNAL_SYNC_CONTENT_SEARCH_ON_STARTUP))) { try { JournalContentSearchLocalServiceUtil.checkContentSearches(companyId); } catch (Exception e) { _log.error(e, e); } } // Process application startup events if (_log.isDebugEnabled()) { _log.debug("Process application startup events"); } try { EventsProcessorUtil.process( PropsKeys.APPLICATION_STARTUP_EVENTS, PropsValues.APPLICATION_STARTUP_EVENTS, new String[] {String.valueOf(companyId)}); } catch (Exception e) { _log.error(e, e); } // End initializing company if (_log.isDebugEnabled()) { _log.debug("End initializing company with web id " + webId + " and company id " + companyId); } addCompanyId(companyId); return companyId; }