com.liferay.portlet.workflowtasks.action.EditWorkflowTaskAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of portal-impl Show documentation
Show all versions of portal-impl Show documentation
Contains implementation for the portal services.
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portlet.workflowtasks.action;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.kernel.workflow.WorkflowException;
import com.liferay.portal.kernel.workflow.WorkflowTaskDueDateException;
import com.liferay.portal.kernel.workflow.WorkflowTaskManagerUtil;
import com.liferay.portal.security.auth.PrincipalException;
import com.liferay.portal.struts.PortletAction;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import java.util.Calendar;
import java.util.Date;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
/**
* @author Jorge Ferrer
* @author Marcellus Tavares
* @author Brian Wing Shun Chan
*/
public class EditWorkflowTaskAction extends PortletAction {
@Override
public void processAction(
ActionMapping actionMapping, ActionForm actionForm,
PortletConfig portletConfig, ActionRequest actionRequest,
ActionResponse actionResponse)
throws Exception {
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
try {
if (cmd.equals(Constants.ASSIGN)) {
assignTask(actionRequest);
}
else if (cmd.equals(Constants.SAVE)) {
completeTask(actionRequest);
}
else if (cmd.equals(Constants.UPDATE)) {
updateTask(actionRequest);
}
String redirect = ParamUtil.getString(actionRequest, "redirect");
String closeRedirect = ParamUtil.getString(
actionRequest, "closeRedirect");
if (Validator.isNotNull(closeRedirect)) {
redirect = HttpUtil.setParameter(
redirect, "closeRedirect", closeRedirect);
SessionMessages.add(
actionRequest,
PortalUtil.getPortletId(actionRequest) +
SessionMessages.KEY_SUFFIX_CLOSE_REDIRECT,
closeRedirect);
}
sendRedirect(actionRequest, actionResponse, redirect);
}
catch (Exception e) {
if (e instanceof WorkflowTaskDueDateException) {
SessionErrors.add(actionRequest, e.getClass());
}
else if (e instanceof PrincipalException ||
e instanceof WorkflowException) {
SessionErrors.add(actionRequest, e.getClass());
setForward(actionRequest, "portlet.workflow_tasks.error");
}
else {
throw e;
}
}
}
@Override
public ActionForward render(
ActionMapping actionMapping, ActionForm actionForm,
PortletConfig portletConfig, RenderRequest renderRequest,
RenderResponse renderResponse)
throws Exception {
try {
ActionUtil.getWorkflowTask(renderRequest);
}
catch (Exception e) {
if (e instanceof WorkflowException) {
SessionErrors.add(renderRequest, e.getClass());
return actionMapping.findForward(
"portlet.workflow_tasks.error");
}
else {
throw e;
}
}
return actionMapping.findForward(
getForward(
renderRequest, "portlet.workflow_tasks.edit_workflow_task"));
}
protected void assignTask(ActionRequest actionRequest) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
WebKeys.THEME_DISPLAY);
long workflowTaskId = ParamUtil.getLong(
actionRequest, "workflowTaskId");
long assigneeUserId = ParamUtil.getLong(
actionRequest, "assigneeUserId");
String comment = ParamUtil.getString(actionRequest, "comment");
WorkflowTaskManagerUtil.assignWorkflowTaskToUser(
themeDisplay.getCompanyId(), themeDisplay.getUserId(),
workflowTaskId, assigneeUserId, comment, null, null);
}
protected void completeTask(ActionRequest actionRequest) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
WebKeys.THEME_DISPLAY);
long workflowTaskId = ParamUtil.getLong(
actionRequest, "workflowTaskId");
String transitionName = ParamUtil.getString(
actionRequest, "transitionName");
String comment = ParamUtil.getString(actionRequest, "comment");
WorkflowTaskManagerUtil.completeWorkflowTask(
themeDisplay.getCompanyId(), themeDisplay.getUserId(),
workflowTaskId, transitionName, comment, null);
}
@Override
protected boolean isCheckMethodOnProcessAction() {
return _CHECK_METHOD_ON_PROCESS_ACTION;
}
protected void updateTask(ActionRequest actionRequest) throws Exception {
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
WebKeys.THEME_DISPLAY);
long workflowTaskId = ParamUtil.getLong(
actionRequest, "workflowTaskId");
String comment = ParamUtil.getString(actionRequest, "comment");
int dueDateMonth = ParamUtil.getInteger(actionRequest, "dueDateMonth");
int dueDateDay = ParamUtil.getInteger(actionRequest, "dueDateDay");
int dueDateYear = ParamUtil.getInteger(actionRequest, "dueDateYear");
int dueDateHour = ParamUtil.getInteger(actionRequest, "dueDateHour");
int dueDateMinute = ParamUtil.getInteger(
actionRequest, "dueDateMinute");
int dueDateAmPm = ParamUtil.getInteger(actionRequest, "dueDateAmPm");
if (dueDateAmPm == Calendar.PM) {
dueDateHour += 12;
}
Date dueDate = PortalUtil.getDate(
dueDateMonth, dueDateDay, dueDateYear, dueDateHour, dueDateMinute,
WorkflowTaskDueDateException.class);
WorkflowTaskManagerUtil.updateDueDate(
themeDisplay.getCompanyId(), themeDisplay.getUserId(),
workflowTaskId, comment, dueDate);
}
private static final boolean _CHECK_METHOD_ON_PROCESS_ACTION = false;
}