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.journal.test.util.JournalTestUtil.java

License:Open Source License

public static JournalArticle addArticle(long groupId, long folderId, long classNameId, String articleId,
        boolean autoArticleId, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap,
        Map<Locale, String> contentMap, String layoutUuid, Locale defaultLocale, Date expirationDate,
        boolean workflowEnabled, boolean approved, ServiceContext serviceContext) throws Exception {

    String content = DDMStructureTestUtil.getSampleStructuredContent(contentMap,
            LocaleUtil.toLanguageId(defaultLocale));

    DDMForm ddmForm = DDMStructureTestUtil.getSampleDDMForm(_locales, defaultLocale);

    long ddmGroupId = GetterUtil.getLong(serviceContext.getAttribute("ddmGroupId"), groupId);

    DDMStructure ddmStructure = DDMStructureTestUtil.addStructure(ddmGroupId, JournalArticle.class.getName(),
            ddmForm, defaultLocale);//from  w w  w  .ja v a2s.c o  m

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(ddmGroupId, ddmStructure.getStructureId(),
            PortalUtil.getClassNameId(JournalArticle.class));

    boolean neverExpire = true;

    int expirationDateDay = 0;
    int expirationDateMonth = 0;
    int expirationDateYear = 0;
    int expirationDateHour = 0;
    int expirationDateMinute = 0;

    if (expirationDate != null) {
        neverExpire = false;

        Calendar expirationCal = CalendarFactoryUtil.getCalendar(TestPropsValues.getUser().getTimeZone());

        expirationCal.setTime(expirationDate);

        expirationDateMonth = expirationCal.get(Calendar.MONTH);
        expirationDateDay = expirationCal.get(Calendar.DATE);
        expirationDateYear = expirationCal.get(Calendar.YEAR);
        expirationDateHour = expirationCal.get(Calendar.HOUR_OF_DAY);
        expirationDateMinute = expirationCal.get(Calendar.MINUTE);
    }

    Calendar displayCal = CalendarFactoryUtil.getCalendar(TestPropsValues.getUser().getTimeZone());

    int displayDateDay = displayCal.get(Calendar.DATE);
    int displayDateMonth = displayCal.get(Calendar.MONTH);
    int displayDateYear = displayCal.get(Calendar.YEAR);
    int displayDateHour = displayCal.get(Calendar.HOUR_OF_DAY);
    int displayDateMinute = displayCal.get(Calendar.MINUTE);

    if (workflowEnabled) {
        serviceContext = (ServiceContext) serviceContext.clone();

        if (approved) {
            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
        } else {
            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
        }
    }

    return JournalArticleLocalServiceUtil.addArticle(serviceContext.getUserId(), groupId, folderId, classNameId,
            0, articleId, autoArticleId, JournalArticleConstants.VERSION_DEFAULT, titleMap, descriptionMap,
            content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), layoutUuid, displayDateMonth,
            displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth,
            expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, 0, 0,
            0, 0, 0, true, true, false, null, null, null, null, serviceContext);
}

From source file:com.liferay.journal.test.util.JournalTestUtil.java

License:Open Source License

public static JournalArticle updateArticle(long userId, JournalArticle article, Map<Locale, String> titleMap,
        String content, boolean workflowEnabled, boolean approved, ServiceContext serviceContext)
        throws Exception {

    if (workflowEnabled) {
        serviceContext = (ServiceContext) serviceContext.clone();

        if (approved) {
            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
        } else {/*from   ww  w .  j  av  a 2s. c  o m*/
            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
        }
    }

    Date displayDate = article.getDisplayDate();

    int displayDateMonth = 0;
    int displayDateDay = 0;
    int displayDateYear = 0;
    int displayDateHour = 0;
    int displayDateMinute = 0;

    if (displayDate != null) {
        Calendar displayCal = CalendarFactoryUtil.getCalendar(TestPropsValues.getUser().getTimeZone());

        displayCal.setTime(displayDate);

        displayDateMonth = displayCal.get(Calendar.MONTH);
        displayDateDay = displayCal.get(Calendar.DATE);
        displayDateYear = displayCal.get(Calendar.YEAR);
        displayDateHour = displayCal.get(Calendar.HOUR_OF_DAY);
        displayDateMinute = displayCal.get(Calendar.MINUTE);
    }

    serviceContext.setCommand(Constants.UPDATE);
    serviceContext.setLayoutFullURL("http://localhost");

    return JournalArticleLocalServiceUtil.updateArticle(userId, article.getGroupId(), article.getFolderId(),
            article.getArticleId(), article.getVersion(), titleMap, article.getDescriptionMap(), content,
            article.getDDMStructureKey(), article.getDDMTemplateKey(), article.getLayoutUuid(),
            displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, 0, 0, 0, 0,
            0, true, 0, 0, 0, 0, 0, true, article.getIndexable(), article.isSmallImage(),
            article.getSmallImageURL(), null, null, null, serviceContext);
}

From source file:com.liferay.journal.trash.test.JournalFolderTrashHandlerTest.java

License:Open Source License

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

    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(primaryKey);

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

        folder = JournalFolderLocalServiceUtil.updateStatus(TestPropsValues.getUserId(), folder,
                WorkflowConstants.STATUS_DRAFT);
    }// w  w w . ja  v a 2  s  .c om

    return folder;
}

From source file:com.liferay.journal.web.internal.portlet.JournalPortlet.java

License:Open Source License

protected void sendEditArticleRedirect(ActionRequest actionRequest, ActionResponse actionResponse,
        JournalArticle article, String oldUrlTitle) throws Exception {

    String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

    String redirect = ParamUtil.getString(actionRequest, "redirect");

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

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

    String namespace = _portal.getPortletNamespace(portletId);

    if (Validator.isNotNull(oldUrlTitle)) {
        String oldRedirectParam = namespace + "redirect";

        String oldRedirect = HttpUtil.getParameter(redirect, oldRedirectParam, false);

        if (Validator.isNotNull(oldRedirect)) {
            String newRedirect = HttpUtil.decodeURL(oldRedirect);

            newRedirect = StringUtil.replace(newRedirect, oldUrlTitle, article.getUrlTitle());
            newRedirect = StringUtil.replace(newRedirect, oldRedirectParam, "redirect");

            redirect = StringUtil.replace(redirect, oldRedirect, newRedirect);
        }/*from w ww .  j a  va  2s.c  om*/
    }

    if ((actionName.equals("deleteArticle") || actionName.equals("deleteArticles"))
            && !ActionUtil.hasArticle(actionRequest)) {

        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

        PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest, themeDisplay.getPpid(),
                PortletRequest.RENDER_PHASE);

        redirect = portletURL.toString();
    }

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

        redirect = getSaveAndContinueRedirect(actionRequest, article, redirect);

        if (actionName.equals("previewArticle")) {
            SessionMessages.add(actionRequest, "previewRequested");

            hideDefaultSuccessMessage(actionRequest);
        }
    } else {
        WindowState windowState = actionRequest.getWindowState();

        if (windowState.equals(LiferayWindowState.POP_UP)) {
            redirect = _portal.escapeRedirect(redirect);

            if (Validator.isNotNull(redirect)) {
                if (actionName.equals("addArticle") && (article != null)) {
                    redirect = HttpUtil.addParameter(redirect, namespace + "className",
                            JournalArticle.class.getName());
                    redirect = HttpUtil.addParameter(redirect, namespace + "classPK",
                            JournalArticleAssetRenderer.getClassPK(article));
                }
            }
        }
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
}

From source file:com.liferay.knowledgebase.portlet.BaseKBPortlet.java

License:Open Source License

public void updateKBArticle(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String portletId = PortalUtil.getPortletId(actionRequest);

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

    long resourcePrimKey = ParamUtil.getLong(actionRequest, "resourcePrimKey");
    long parentResourceClassNameId = ParamUtil.getLong(actionRequest, "parentResourceClassNameId",
            PortalUtil.getClassNameId(KBFolderConstants.getClassName()));
    long parentResourcePrimKey = ParamUtil.getLong(actionRequest, "parentResourcePrimKey",
            KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    String title = ParamUtil.getString(actionRequest, "title");
    String urlTitle = ParamUtil.getString(actionRequest, "urlTitle");
    String content = ParamUtil.getString(actionRequest, "content");
    String description = ParamUtil.getString(actionRequest, "description");
    String sourceURL = ParamUtil.getString(actionRequest, "sourceURL");
    String[] sections = actionRequest.getParameterValues("sections");
    String[] selectedFileNames = ParamUtil.getParameterValues(actionRequest, "selectedFileName");
    long[] removeFileEntryIds = ParamUtil.getLongValues(actionRequest, "removeFileEntryIds");
    int workflowAction = ParamUtil.getInteger(actionRequest, "workflowAction");

    KBArticle kbArticle = null;//from  w  ww  . ja va  2 s.  c  om

    ServiceContext serviceContext = ServiceContextFactory.getInstance(KBArticle.class.getName(), actionRequest);

    if (cmd.equals(Constants.ADD)) {
        kbArticle = KBArticleServiceUtil.addKBArticle(portletId, parentResourceClassNameId,
                parentResourcePrimKey, title, urlTitle, content, description, sourceURL, sections,
                selectedFileNames, serviceContext);
    } else if (cmd.equals(Constants.UPDATE)) {
        kbArticle = KBArticleServiceUtil.updateKBArticle(resourcePrimKey, title, content, description,
                sourceURL, sections, selectedFileNames, removeFileEntryIds, serviceContext);
    }

    if (!cmd.equals(Constants.ADD) && !cmd.equals(Constants.UPDATE)) {
        return;
    }

    if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) {
        String editURL = buildEditURL(actionRequest, actionResponse, kbArticle);

        actionRequest.setAttribute(WebKeys.REDIRECT, editURL);
    }
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.EnableLayoutMVCActionCommand.java

License:Open Source License

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

    long incompleteLayoutRevisionId = ParamUtil.getLong(actionRequest, "incompleteLayoutRevisionId");

    LayoutRevision incompleteLayoutRevision = _layoutRevisionLocalService
            .getLayoutRevision(incompleteLayoutRevisionId);

    long layoutBranchId = ParamUtil.getLong(actionRequest, "layoutBranchId",
            incompleteLayoutRevision.getLayoutBranchId());

    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

    _layoutRevisionLocalService.updateLayoutRevision(serviceContext.getUserId(),
            incompleteLayoutRevision.getLayoutRevisionId(), layoutBranchId, incompleteLayoutRevision.getName(),
            incompleteLayoutRevision.getTitle(), incompleteLayoutRevision.getDescription(),
            incompleteLayoutRevision.getKeywords(), incompleteLayoutRevision.getRobots(),
            incompleteLayoutRevision.getTypeSettings(), incompleteLayoutRevision.getIconImage(),
            incompleteLayoutRevision.getIconImageId(), incompleteLayoutRevision.getThemeId(),
            incompleteLayoutRevision.getColorSchemeId(), incompleteLayoutRevision.getCss(), serviceContext);
}

From source file:com.liferay.login.web.internal.portlet.action.CreateAnonymousAccountMVCActionCommand.java

License:Open Source License

protected void addAnonymousUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    HttpServletRequest request = _portal.getHttpServletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    boolean autoPassword = true;
    String password1 = null;/*from  www  .  j a  va2  s .c o  m*/
    String password2 = null;
    boolean autoScreenName = true;
    String screenName = null;
    String emailAddress = ParamUtil.getString(actionRequest, "emailAddress");
    long facebookId = 0;
    String openId = StringPool.BLANK;
    String firstName = ParamUtil.getString(actionRequest, "firstName");
    String lastName = ParamUtil.getString(actionRequest, "lastName");
    long prefixId = 0;
    long suffixId = 0;
    boolean male = true;
    int birthdayMonth = 0;
    int birthdayDay = 1;
    int birthdayYear = 1970;
    String jobTitle = null;
    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;
    boolean sendEmail = false;

    ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest);

    serviceContext.setAttribute("anonymousUser", Boolean.TRUE);

    CaptchaConfiguration captchaConfiguration = getCaptchaConfiguration();

    if (captchaConfiguration.createAccountCaptchaEnabled()) {
        CaptchaUtil.check(actionRequest);
    }

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

    User user = _userService.addUser(themeDisplay.getCompanyId(), autoPassword, password1, password2,
            autoScreenName, screenName, emailAddress, facebookId, openId, themeDisplay.getLocale(), firstName,
            null, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, jobTitle,
            groupIds, organizationIds, roleIds, userGroupIds, sendEmail, serviceContext);

    _userLocalService.updateStatus(user.getUserId(), WorkflowConstants.STATUS_INCOMPLETE, new ServiceContext());

    // Session messages

    SessionMessages.add(request, "userAdded", user.getEmailAddress());
    SessionMessages.add(request, "userAddedPassword", user.getPasswordUnencrypted());
}

From source file:com.liferay.message.boards.internal.service.MBStatsUserMBMessageLocalServiceWrapper.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 curMessage = super.updateMessage(userId, messageId, subject, body, inputStreamOVPs, existingFiles,
            priority, allowPingbacks, serviceContext);

    if ((serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_SAVE_DRAFT)
            && !curMessage.isDiscussion()) {

        _mbStatsUserLocalService.updateStatsUser(curMessage.getGroupId(), userId, curMessage.getModifiedDate());
    }//from  w w w . jav a 2 s.co m

    return curMessage;
}

From source file:com.liferay.message.boards.service.test.MBStatsUserLocalServiceTest.java

License:Open Source License

@Test
public void testUpdateStatsUserWhenSavingDraftMessageAsDraft() throws Exception {

    int initialStatsUserMessageCount = getStatsUserMessageCount();

    addMessage(false);//from   w w  w  .j a  v  a2s.c  o m

    updateMessage(WorkflowConstants.ACTION_SAVE_DRAFT);

    Assert.assertEquals(initialStatsUserMessageCount, getStatsUserMessageCount());
}

From source file:com.liferay.message.boards.service.test.MBStatsUserLocalServiceTest.java

License:Open Source License

@Test
public void testUpdateStatsUserWhenSavingPublishedMessageAsDraft() throws Exception {

    int initialStatsUserMessageCount = getStatsUserMessageCount();

    addMessage(true);//  ww w.j a  v  a  2 s .co m

    updateMessage(WorkflowConstants.ACTION_SAVE_DRAFT);

    Assert.assertEquals(initialStatsUserMessageCount, getStatsUserMessageCount());
}