Example usage for com.liferay.portal.kernel.workflow WorkflowConstants ACTION_SAVE_DRAFT

List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants ACTION_SAVE_DRAFT

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow WorkflowConstants ACTION_SAVE_DRAFT.

Prototype

int ACTION_SAVE_DRAFT

To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants ACTION_SAVE_DRAFT.

Click Source Link

Usage

From source file:com.liferay.akismet.hook.service.impl.AkismetMBMessageLocalServiceImpl.java

License:Open Source License

@Override
public MBMessage addDiscussionMessage(long userId, String userName, long groupId, String className,
        long classPK, long threadId, long parentMessageId, 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 ava  2 s .c  o m*/

    MBMessage message = super.addDiscussionMessage(userId, userName, groupId, className, classPK, threadId,
            parentMessageId, 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 addMessage(long userId, String userName, long groupId, long categoryId, long threadId,
        long parentMessageId, 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  w  w  w . j  ava  2  s  .  c om*/

    MBMessage message = super.addMessage(userId, userName, groupId, categoryId, threadId, parentMessageId,
            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 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 a v a2s  . c o  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);
    }//  w w w  .  j  a  va2  s  .  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  ww w . ja  v a 2  s .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.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  a va2s  .co 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.  ja 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.blogs.test.util.BlogsTestUtil.java

License:Open Source License

public static BlogsEntry addEntryWithWorkflow(long userId, String title, boolean approved,
        ServiceContext serviceContext) throws Exception {

    boolean workflowEnabled = WorkflowThreadLocal.isEnabled();

    try {/* w  ww . j  a  v  a 2s  . c  o  m*/
        WorkflowThreadLocal.setEnabled(true);

        Calendar displayCalendar = CalendarFactoryUtil.getCalendar(2012, 1, 1);

        serviceContext = (ServiceContext) serviceContext.clone();

        serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

        BlogsEntry entry = BlogsEntryLocalServiceUtil.addEntry(userId, title, RandomTestUtil.randomString(),
                RandomTestUtil.randomString(), RandomTestUtil.randomString(), displayCalendar.getTime(), true,
                true, new String[0], StringPool.BLANK, null, null, serviceContext);

        if (approved) {
            return updateStatus(entry, serviceContext);
        }

        return entry;
    } finally {
        WorkflowThreadLocal.setEnabled(workflowEnabled);
    }
}

From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {/*from w w w  . j a  v  a 2s .co  m*/
        BlogsEntry entry = null;
        List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = null;

        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

        if (uploadException != null) {
            Throwable cause = uploadException.getCause();

            if (uploadException.isExceededFileSizeLimit()) {
                throw new FileSizeException(cause);
            }

            if (uploadException.isExceededLiferayFileItemSizeLimit()) {
                throw new LiferayFileItemException(cause);
            }

            if (uploadException.isExceededUploadRequestSizeLimit()) {
                throw new UploadRequestSizeException(cause);
            }

            throw new PortalException(cause);
        } else if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {

            Callable<Object[]> updateEntryCallable = new UpdateEntryCallable(actionRequest);

            Object[] returnValue = TransactionInvokerUtil.invoke(_transactionConfig, updateEntryCallable);

            entry = (BlogsEntry) returnValue[0];
            blogsEntryAttachmentFileEntryReferences = (List<BlogsEntryAttachmentFileEntryReference>) returnValue[1];
        } else if (cmd.equals(Constants.DELETE)) {
            deleteEntries(actionRequest, false);
        } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
            deleteEntries(actionRequest, true);
        } else if (cmd.equals(Constants.RESTORE)) {
            restoreTrashEntries(actionRequest);
        } else if (cmd.equals(Constants.SUBSCRIBE)) {
            subscribe(actionRequest);
        } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
            unsubscribe(actionRequest);
        }

        String redirect = ParamUtil.getString(actionRequest, "redirect");
        String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

        int workflowAction = ParamUtil.getInteger(actionRequest, "workflowAction",
                WorkflowConstants.ACTION_SAVE_DRAFT);

        boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax");

        if (ajax) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

            for (BlogsEntryAttachmentFileEntryReference blogsEntryAttachmentFileEntryReference : blogsEntryAttachmentFileEntryReferences) {

                JSONObject blogsEntryFileEntryReferencesJSONObject = JSONFactoryUtil.createJSONObject();

                blogsEntryFileEntryReferencesJSONObject.put("attributeDataImageId",
                        EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
                blogsEntryFileEntryReferencesJSONObject.put("fileEntryId", String.valueOf(
                        blogsEntryAttachmentFileEntryReference.getTempBlogsEntryAttachmentFileEntryId()));
                blogsEntryFileEntryReferencesJSONObject.put("fileEntryUrl",
                        PortletFileRepositoryUtil.getPortletFileEntryURL(null,
                                blogsEntryAttachmentFileEntryReference.getBlogsEntryAttachmentFileEntry(),
                                StringPool.BLANK));

                jsonArray.put(blogsEntryFileEntryReferencesJSONObject);
            }

            jsonObject.put("blogsEntryAttachmentReferences", jsonArray);
            jsonObject.put("coverImageFileEntryId", entry.getCoverImageFileEntryId());
            jsonObject.put("entryId", entry.getEntryId());
            jsonObject.put("redirect", redirect);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

            return;
        }

        if ((entry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

            redirect = getSaveAndContinueRedirect(actionRequest, entry, redirect);

            sendRedirect(actionRequest, actionResponse, redirect);
        } else {
            WindowState windowState = actionRequest.getWindowState();

            if (!windowState.equals(LiferayWindowState.POP_UP)) {
                sendRedirect(actionRequest, actionResponse, redirect);
            } else {
                redirect = PortalUtil.escapeRedirect(redirect);

                if (Validator.isNotNull(redirect)) {
                    if (cmd.equals(Constants.ADD) && (entry != null)) {
                        String namespace = PortalUtil.getPortletNamespace(portletId);

                        redirect = HttpUtil.addParameter(redirect, namespace + "className",
                                BlogsEntry.class.getName());
                        redirect = HttpUtil.addParameter(redirect, namespace + "classPK", entry.getEntryId());
                    }

                    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
                }
            }
        }
    } catch (AssetCategoryException | AssetTagException e) {
        SessionErrors.add(actionRequest, e.getClass(), e);

        actionResponse.setRenderParameter("mvcRenderCommandName", "/blogs/edit_entry");

        hideDefaultSuccessMessage(actionRequest);
    } catch (EntryContentException | EntryCoverImageCropException | EntryDescriptionException
            | EntryDisplayDateException | EntrySmallImageNameException | EntrySmallImageScaleException
            | EntryTitleException | EntryUrlTitleException | FileSizeException | LiferayFileItemException
            | SanitizerException | UploadRequestSizeException e) {

        SessionErrors.add(actionRequest, e.getClass());

        actionResponse.setRenderParameter("mvcRenderCommandName", "/blogs/edit_entry");

        hideDefaultSuccessMessage(actionRequest);
    } catch (NoSuchEntryException | PrincipalException e) {
        SessionErrors.add(actionRequest, e.getClass());

        actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp");

        hideDefaultSuccessMessage(actionRequest);
    } catch (Throwable t) {
        _log.error(t, t);

        actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp");

        hideDefaultSuccessMessage(actionRequest);
    }
}

From source file:com.liferay.bookmarks.trash.test.BookmarksEntryTrashHandlerTest.java

License:Open Source License

@Override
public BaseModel<?> updateBaseModel(long primaryKey, ServiceContext serviceContext) throws Exception {

    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(primaryKey);

    if (serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_SAVE_DRAFT) {

        entry = BookmarksEntryLocalServiceUtil.updateStatus(TestPropsValues.getUserId(), entry,
                WorkflowConstants.STATUS_DRAFT);
    }/*  w ww  . j  a va 2s .c  o  m*/

    return entry;
}