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

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

Introduction

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

Prototype

int ACTION_PUBLISH

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

Click Source Link

Usage

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. ja  v  a 2  s.c  o m*/
    }

    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.message.boards.comment.internal.MBCommentManagerImpl.java

License:Open Source License

@Override
public void addDiscussion(long userId, long groupId, String className, long classPK, String userName)
        throws PortalException {

    _mbMessageLocalService.addDiscussionMessage(userId, userName, groupId, className, classPK,
            WorkflowConstants.ACTION_PUBLISH);
}

From source file:com.liferay.message.boards.comment.internal.MBCommentManagerImplTest.java

License:Open Source License

@Test
public void testAddDiscussion() throws Exception {
    _mbCommentManagerImpl.addDiscussion(_USER_ID, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, _USER_NAME);

    Mockito.verify(_mbMessageLocalService).addDiscussionMessage(_USER_ID, _USER_NAME, _GROUP_ID, _CLASS_NAME,
            _ENTRY_ID, WorkflowConstants.ACTION_PUBLISH);
}

From source file:com.liferay.message.boards.internal.exportimport.data.handler.MBDiscussionStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, MBDiscussion discussion)
        throws Exception {

    long userId = portletDataContext.getUserId(discussion.getUserUuid());

    String className = discussion.getClassName();

    Map<Long, Long> relatedClassPKs = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(className);

    long newClassPK = MapUtil.getLong(relatedClassPKs, discussion.getClassPK(), discussion.getClassPK());

    MBDiscussion existingDiscussion = _mbDiscussionLocalService.fetchDiscussion(discussion.getClassName(),
            newClassPK);//from   w  w w. java 2 s . co  m

    if (existingDiscussion == null) {
        if (className.equals(Layout.class.getName()) && PropsValues.LAYOUT_COMMENTS_ENABLED) {

            MBMessage rootMessage = _mbMessageLocalService.addDiscussionMessage(userId,
                    discussion.getUserName(), portletDataContext.getScopeGroupId(), className, newClassPK,
                    WorkflowConstants.ACTION_PUBLISH);

            existingDiscussion = _mbDiscussionLocalService.getThreadDiscussion(rootMessage.getThreadId());
        } else {
            StringBundler sb = new StringBundler(4);

            sb.append("No discussion exists for class name ");
            sb.append(discussion.getClassName());
            sb.append(" and class PK ");
            sb.append(newClassPK);

            throw new NoSuchDiscussionException(sb.toString());
        }
    }

    Map<Long, Long> discussionIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(MBDiscussion.class);

    discussionIds.put(discussion.getDiscussionId(), existingDiscussion.getDiscussionId());

    Map<Long, Long> threadIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBThread.class);

    threadIds.put(discussion.getThreadId(), existingDiscussion.getThreadId());
}

From source file:com.liferay.message.boards.lar.test.MBMessageStagedModelDataHandlerTest.java

License:Open Source License

@Override
protected StagedModel addStagedModel(Group group, Map<String, List<StagedModel>> dependentStagedModelsMap)
        throws Exception {

    List<StagedModel> dependentStagedModels = dependentStagedModelsMap.get(MBCategory.class.getSimpleName());

    MBCategory category = (MBCategory) dependentStagedModels.get(0);

    List<ObjectValuePair<String, InputStream>> objectValuePairs = MBTestUtil
            .getInputStreamOVPs("attachment.txt", getClass(), StringPool.BLANK);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            TestPropsValues.getUserId());

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    MBMessage message = MBMessageLocalServiceUtil.addMessage(TestPropsValues.getUserId(),
            RandomTestUtil.randomString(), group.getGroupId(), category.getCategoryId(), 0, 0,
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), MBMessageConstants.DEFAULT_FORMAT,
            objectValuePairs, false, 0.0, false, serviceContext);

    MBMessageLocalServiceUtil.updateAnswer(message, true, false);

    List<FileEntry> attachmentsFileEntries = message.getAttachmentsFileEntries();

    FileEntry fileEntry = attachmentsFileEntries.get(0);

    Folder folder = fileEntry.getFolder();

    while (folder != null) {
        addDependentStagedModel(dependentStagedModelsMap, DLFolder.class, folder);

        folder = folder.getParentFolder();
    }/*  ww  w .  ja  v  a 2  s  .  c  o m*/

    addDependentStagedModel(dependentStagedModelsMap, DLFileEntry.class, attachmentsFileEntries.get(0));

    Repository repository = RepositoryUtil.fetchByPrimaryKey(fileEntry.getRepositoryId());

    addDependentStagedModel(dependentStagedModelsMap, Repository.class, repository);

    return message;
}

From source file:com.liferay.message.boards.lar.test.MBPortletDataHandlerTest.java

License:Open Source License

@Override
protected void addStagedModels() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(stagingGroup.getGroupId(),
            TestPropsValues.getUserId());

    MBCategory category = MBCategoryServiceUtil.addCategory(TestPropsValues.getUserId(),
            MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, RandomTestUtil.randomString(), StringPool.BLANK,
            serviceContext);/* ww  w .j a  v a2  s .  co  m*/

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    MBMessage message = MBMessageLocalServiceUtil.addMessage(TestPropsValues.getUserId(),
            RandomTestUtil.randomString(), stagingGroup.getGroupId(), category.getCategoryId(),
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext);

    MBThreadFlagLocalServiceUtil.addThreadFlag(TestPropsValues.getUserId(), message.getThread(),
            serviceContext);

    User user = UserTestUtil.addUser(TestPropsValues.getGroupId());

    MBBanLocalServiceUtil.addBan(TestPropsValues.getUserId(), user.getUserId(), serviceContext);
}

From source file:com.liferay.message.boards.search.test.MBMessageSearchTest.java

License:Open Source License

@Override
protected BaseModel<?> updateBaseModel(BaseModel<?> baseModel, String keywords, ServiceContext serviceContext)
        throws Exception {

    MBMessage message = (MBMessage) baseModel;

    ServiceContext updateServiceContext = ServiceContextTestUtil.getServiceContext(message.getGroupId(),
            TestPropsValues.getUserId());

    updateServiceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    return MBMessageLocalServiceUtil.updateMessage(TestPropsValues.getUserId(), message.getMessageId(),
            keywords, updateServiceContext);
}

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

License:Open Source License

@Test
public void testUpdateStatsUserWhenPublishingDraftMessage() throws Exception {

    int initialStatsUserMessageCount = getStatsUserMessageCount();

    addMessage(false);/*w w  w  . j  a va 2 s  . co m*/

    updateMessage(WorkflowConstants.ACTION_PUBLISH);

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

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

License:Open Source License

@Test
public void testUpdateStatsUserWhenPublishingPublishedMessage() throws Exception {

    int initialStatsUserMessageCount = getStatsUserMessageCount();

    addMessage(true);/*from w  w w.  j a  v  a 2  s.  com*/

    updateMessage(WorkflowConstants.ACTION_PUBLISH);

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

From source file:com.liferay.message.boards.web.internal.portlet.action.EditMessageMVCActionCommand.java

License:Open Source License

protected String getRedirect(ActionRequest actionRequest, ActionResponse actionResponse, MBMessage message) {

    if (message == null) {
        String redirect = ParamUtil.getString(actionRequest, "redirect");

        return redirect;
    }/*from   ww  w . j  av  a2 s .  co m*/

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

    if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) {
        return getSaveAndContinueRedirect(actionRequest, actionResponse, message);
    } else if (message == null) {
        return ParamUtil.getString(actionRequest, "redirect");
    }

    ActionResponseImpl actionResponseImpl = (ActionResponseImpl) actionResponse;

    PortletURL portletURL = actionResponseImpl.createRenderURL();

    portletURL.setParameter("mvcRenderCommandName", "/message_boards/view_message");
    portletURL.setParameter("messageId", String.valueOf(message.getMessageId()));

    return portletURL.toString();
}