001
014
015 package com.liferay.portlet.workflowdefinitions.action;
016
017 import com.liferay.portal.kernel.dao.orm.QueryUtil;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.kernel.workflow.WorkflowDefinition;
020 import com.liferay.portal.kernel.workflow.WorkflowDefinitionManagerUtil;
021 import com.liferay.portal.theme.ThemeDisplay;
022 import com.liferay.portal.util.PortalUtil;
023 import com.liferay.portal.util.WebKeys;
024
025 import java.util.List;
026
027 import javax.portlet.PortletRequest;
028
029 import javax.servlet.http.HttpServletRequest;
030
031
034 public class ActionUtil {
035
036 public static void getWorkflowDefinition(HttpServletRequest request)
037 throws Exception {
038
039 if (request.getAttribute(WebKeys.WORKFLOW_DEFINITION) != null) {
040 return;
041 }
042
043 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
044 WebKeys.THEME_DISPLAY);
045
046 String name = ParamUtil.getString(request, "name");
047 int version = ParamUtil.getInteger(request, "version");
048
049 List<WorkflowDefinition> workflowDefinitions =
050 WorkflowDefinitionManagerUtil.getWorkflowDefinitions(
051 themeDisplay.getCompanyId(), name, QueryUtil.ALL_POS,
052 QueryUtil.ALL_POS, null);
053
054 for (WorkflowDefinition workflowDefinition : workflowDefinitions) {
055 if (version == workflowDefinition.getVersion()) {
056 request.setAttribute(
057 WebKeys.WORKFLOW_DEFINITION, workflowDefinition);
058
059 break;
060 }
061 }
062 }
063
064 public static void getWorkflowDefinition(PortletRequest portletRequest)
065 throws Exception {
066
067 HttpServletRequest request = PortalUtil.getHttpServletRequest(
068 portletRequest);
069
070 getWorkflowDefinition(request);
071 }
072
073 }