List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_APPROVED
int STATUS_APPROVED
To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants STATUS_APPROVED.
Click Source Link
From source file:com.liferay.akismet.hook.service.impl.AkismetMBMessageLocalServiceImpl.java
License:Open Source License
@Override public MBMessage addMessage(long userId, String userName, long groupId, long categoryId, String subject, String body, String format, List<ObjectValuePair<String, InputStream>> inputStreamOVPs, boolean anonymous, double priority, boolean allowPingbacks, ServiceContext serviceContext) throws PortalException { boolean enabled = isMessageBoardsEnabled(userId, groupId, serviceContext); if (enabled) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); }//from ww w .j ava 2 s. co m MBMessage message = super.addMessage(userId, userName, groupId, categoryId, subject, body, format, inputStreamOVPs, anonymous, priority, allowPingbacks, serviceContext); AkismetData akismetData = updateAkismetData(message, serviceContext); if (!enabled) { return message; } String content = subject + "\n\n" + body; int status = WorkflowConstants.STATUS_APPROVED; if (AkismetUtil.isSpam(userId, content, akismetData)) { status = WorkflowConstants.STATUS_DENIED; } return super.updateStatus(userId, message.getMessageId(), status, serviceContext); }
From source file:com.liferay.akismet.hook.service.impl.AkismetMBMessageLocalServiceImpl.java
License:Open Source License
@Override public MBMessage updateDiscussionMessage(long userId, long messageId, String className, long classPK, String subject, String body, ServiceContext serviceContext) throws PortalException { boolean enabled = isDiscussionsEnabled(userId, serviceContext); if (enabled) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); }/*from w ww . j a va2s . c o m*/ MBMessage message = super.updateDiscussionMessage(userId, messageId, className, classPK, subject, body, serviceContext); AkismetData akismetData = updateAkismetData(message, serviceContext); if (!enabled) { return message; } String content = subject + "\n\n" + body; int status = WorkflowConstants.STATUS_APPROVED; if (AkismetUtil.isSpam(userId, content, akismetData)) { status = WorkflowConstants.STATUS_DENIED; } return super.updateStatus(userId, message.getMessageId(), status, serviceContext); }
From source file:com.liferay.akismet.hook.service.impl.AkismetMBMessageLocalServiceImpl.java
License:Open Source License
@Override public MBMessage updateMessage(long userId, long messageId, String subject, String body, List<ObjectValuePair<String, InputStream>> inputStreamOVPs, List<String> existingFiles, double priority, boolean allowPingbacks, ServiceContext serviceContext) throws PortalException { MBMessage message = super.getMBMessage(messageId); boolean enabled = isMessageBoardsEnabled(userId, message.getGroupId(), serviceContext); if (enabled) { serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); }//from w w w . j a v a2s. c om message = super.updateMessage(userId, messageId, subject, body, inputStreamOVPs, existingFiles, priority, allowPingbacks, serviceContext); AkismetData akismetData = updateAkismetData(message, serviceContext); if (!enabled) { return message; } String content = subject + "\n\n" + body; int status = WorkflowConstants.STATUS_APPROVED; if (AkismetUtil.isSpam(userId, content, akismetData)) { status = WorkflowConstants.STATUS_DENIED; } return super.updateStatus(userId, message.getMessageId(), status, serviceContext); }
From source file:com.liferay.akismet.hook.service.impl.AkismetMBMessageLocalServiceImpl.java
License:Open Source License
protected boolean isMessageBoardsEnabled(long userId, long groupId, ServiceContext serviceContext) throws PortalException { if (serviceContext.getWorkflowAction() != WorkflowConstants.ACTION_PUBLISH) { return false; }/*from ww w. j a v a2 s . com*/ if (!AkismetUtil.hasRequiredInfo(serviceContext)) { return false; } User user = UserLocalServiceUtil.getUser(userId); if (!AkismetUtil.isMessageBoardsEnabled(user.getCompanyId())) { return false; } int checkThreshold = PrefsPortletPropsUtil.getInteger(user.getCompanyId(), PortletPropsKeys.AKISMET_CHECK_THRESHOLD); if (checkThreshold > 0) { int count = super.getGroupMessagesCount(groupId, userId, WorkflowConstants.STATUS_APPROVED); if (count > checkThreshold) { return false; } } return true; }
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); }// w w w .j av a 2s. c om 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 ww w . j a va2 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.akismet.hook.service.impl.AkismetWikiPageLocalServiceImpl.java
License:Open Source License
protected boolean isWikiEnabled(long userId, long nodeId, ServiceContext serviceContext) throws PortalException { if (!AkismetUtil.hasRequiredInfo(serviceContext)) { return false; }// w w w .jav a 2s. c om User user = UserLocalServiceUtil.getUser(userId); if (!AkismetUtil.isWikiEnabled(user.getCompanyId())) { return false; } int checkThreshold = PrefsPortletPropsUtil.getInteger(user.getCompanyId(), PortletPropsKeys.AKISMET_CHECK_THRESHOLD); if (checkThreshold > 0) { int count = super.getPagesCount(userId, nodeId, WorkflowConstants.STATUS_APPROVED); if (count > checkThreshold) { return false; } } return true; }
From source file:com.liferay.akismet.moderation.portlet.ModerationPortlet.java
License:Open Source License
public void markNotSpamMBMessages(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); checkMBMessagePermission(themeDisplay.getScopeGroupId()); long[] mbMessageIds = ParamUtil.getLongValues(actionRequest, "notSpamMBMessageIds"); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); for (long mbMessageId : mbMessageIds) { MBMessage mbMessage = MBMessageLocalServiceUtil.updateStatus(themeDisplay.getUserId(), mbMessageId, WorkflowConstants.STATUS_APPROVED, serviceContext); if (AkismetUtil.isMessageBoardsEnabled(mbMessage.getCompanyId())) { AkismetUtil.submitHam(mbMessage); }// w w w.j a va 2s. co m } }
From source file:com.liferay.akismet.moderation.portlet.ModerationPortlet.java
License:Open Source License
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(); }/*from w w w .j av a2 s . com*/ 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, "anotherUserHasMadeChangesToThesePages", StringUtil.merge(wikiPageLinks, "<br />")); addSuccessMessage(actionRequest, actionResponse); super.sendRedirect(actionRequest, actionResponse); } }
From source file:com.liferay.akismet.util.AkismetUtil.java
License:Open Source License
public static WikiPage getWikiPage(long nodeId, String title, double version, boolean previous) { DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(WikiPage.class); Property summaryProperty = PropertyFactoryUtil.forName("summary"); dynamicQuery.add(summaryProperty.ne(AkismetConstants.WIKI_PAGE_MARKED_AS_SPAM)); dynamicQuery.add(summaryProperty.ne(AkismetConstants.WIKI_PAGE_PENDING_APPROVAL)); Property nodeIdProperty = PropertyFactoryUtil.forName("nodeId"); dynamicQuery.add(nodeIdProperty.eq(nodeId)); Property titleProperty = PropertyFactoryUtil.forName("title"); dynamicQuery.add(titleProperty.eq(title)); Property statusProperty = PropertyFactoryUtil.forName("status"); dynamicQuery.add(statusProperty.eq(WorkflowConstants.STATUS_APPROVED)); Property versionProperty = PropertyFactoryUtil.forName("version"); if (previous) { dynamicQuery.add(versionProperty.lt(version)); } else {/* w w w. jav a2 s. co m*/ dynamicQuery.add(versionProperty.ge(version)); } OrderFactoryUtil.addOrderByComparator(dynamicQuery, new PageVersionComparator()); List<WikiPage> wikiPages = WikiPageLocalServiceUtil.dynamicQuery(dynamicQuery, 0, 1); if (wikiPages.isEmpty()) { return null; } return wikiPages.get(0); }