List of usage examples for com.liferay.portal.kernel.util NotificationThreadLocal setEnabled
public static void setEnabled(boolean enabled)
From source file:com.liferay.akismet.hook.service.impl.AkismetWikiPageLocalServiceImpl.java
License:Open Source License
@Override public WikiPage addPage(long userId, long nodeId, String title, double version, String content, String summary, boolean minorEdit, String format, boolean head, String parentTitle, String redirectTitle, ServiceContext serviceContext) throws PortalException { int workflowAction = serviceContext.getWorkflowAction(); if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) { return super.addPage(userId, nodeId, title, content, summary, minorEdit, serviceContext); }//from ww w .j av a 2 s . c o m WikiPage page = super.addPage(userId, nodeId, title, version, content, summary, minorEdit, format, head, parentTitle, redirectTitle, serviceContext); AkismetData akismetData = updateAkismetData(page, serviceContext); if (!isWikiEnabled(userId, nodeId, serviceContext)) { return page; } String akismetContent = page.getTitle() + "\n\n" + page.getContent(); if (!AkismetUtil.isSpam(userId, akismetContent, akismetData)) { return super.updateStatus(userId, page.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED, serviceContext); } boolean notificationEnabled = false; try { notificationEnabled = NotificationThreadLocal.isEnabled(); NotificationThreadLocal.setEnabled(false); page.setSummary(AkismetConstants.WIKI_PAGE_PENDING_APPROVAL); page.setStatus(WorkflowConstants.STATUS_APPROVED); return super.updateWikiPage(page); } finally { NotificationThreadLocal.setEnabled(notificationEnabled); } }
From source file:com.liferay.akismet.hook.service.impl.AkismetWikiPageLocalServiceImpl.java
License:Open Source License
@Override public WikiPage updatePage(long userId, long nodeId, String title, double version, String content, String summary, boolean minorEdit, String format, String parentTitle, String redirectTitle, ServiceContext serviceContext) throws PortalException { int workflowAction = serviceContext.getWorkflowAction(); if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) { return super.updatePage(userId, nodeId, title, version, content, summary, minorEdit, format, parentTitle, redirectTitle, serviceContext); }//from w w w .j a v a 2 s . c o m WikiPage page = super.updatePage(userId, nodeId, title, version, content, summary, minorEdit, format, parentTitle, redirectTitle, serviceContext); AkismetData akismetData = updateAkismetData(page, serviceContext); if (!isWikiEnabled(userId, nodeId, serviceContext)) { return page; } String akismetContent = page.getTitle() + "\n\n" + page.getContent(); if (!AkismetUtil.isSpam(userId, akismetContent, akismetData)) { return super.updateStatus(userId, page.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED, serviceContext); } boolean notificationEnabled = false; try { notificationEnabled = NotificationThreadLocal.isEnabled(); NotificationThreadLocal.setEnabled(false); page.setSummary(AkismetConstants.WIKI_PAGE_PENDING_APPROVAL); page.setStatus(WorkflowConstants.STATUS_APPROVED); page = super.updateWikiPage(page); WikiPage previousPage = AkismetUtil.getWikiPage(page.getNodeId(), page.getTitle(), page.getVersion(), true); if (previousPage == null) { return page; } ServiceContext newServiceContext = new ServiceContext(); newServiceContext.setFormDate(page.getModifiedDate()); return super.revertPage(userId, nodeId, title, previousPage.getVersion(), newServiceContext); } finally { NotificationThreadLocal.setEnabled(notificationEnabled); } }
From source file:com.liferay.portlet.wiki.action.ImportPagesAction.java
License:Open Source License
protected void importPages(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); String importProgressId = ParamUtil.getString(uploadPortletRequest, "importProgressId"); ProgressTracker progressTracker = new ProgressTracker(actionRequest, importProgressId); ProgressTrackerThreadLocal.setProgressTracker(progressTracker); progressTracker.start();/* w ww . j a v a 2 s .c om*/ long nodeId = ParamUtil.getLong(uploadPortletRequest, "nodeId"); String importer = ParamUtil.getString(uploadPortletRequest, "importer"); int filesCount = ParamUtil.getInteger(uploadPortletRequest, "filesCount", 10); InputStream[] inputStreams = new InputStream[filesCount]; try { for (int i = 0; i < filesCount; i++) { inputStreams[i] = uploadPortletRequest.getFileAsStream("file" + i); } NotificationThreadLocal.setEnabled(false); WikiCacheThreadLocal.setClearCache(false); WikiNodeServiceUtil.importPages(nodeId, importer, inputStreams, actionRequest.getParameterMap()); } finally { for (InputStream inputStream : inputStreams) { StreamUtil.cleanUp(inputStream); } } WikiCacheUtil.clearCache(nodeId); progressTracker.finish(); }
From source file:com.liferay.wiki.web.internal.portlet.action.ImportPagesMVCActionCommand.java
License:Open Source License
protected void importPages(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); String importProgressId = ParamUtil.getString(uploadPortletRequest, "importProgressId"); ProgressTracker progressTracker = new ProgressTracker(importProgressId); ProgressTrackerThreadLocal.setProgressTracker(progressTracker); progressTracker.start(actionRequest); long nodeId = ParamUtil.getLong(uploadPortletRequest, "nodeId"); String importer = ParamUtil.getString(uploadPortletRequest, "importer"); int filesCount = ParamUtil.getInteger(uploadPortletRequest, "filesCount", 10); InputStream[] inputStreams = new InputStream[filesCount]; try {//from w ww . ja v a 2 s .c o m for (int i = 0; i < filesCount; i++) { inputStreams[i] = uploadPortletRequest.getFileAsStream("file" + i); } NotificationThreadLocal.setEnabled(false); WikiCacheThreadLocal.setClearCache(false); _wikiNodeService.importPages(nodeId, importer, inputStreams, actionRequest.getParameterMap()); } finally { for (InputStream inputStream : inputStreams) { StreamUtil.cleanUp(inputStream); } } _wikiCacheHelper.clearCache(nodeId); progressTracker.finish(actionRequest); }