1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.workflowadmin.action;
16  
17  import com.liferay.portal.kernel.dao.orm.QueryUtil;
18  import com.liferay.portal.kernel.util.ParamUtil;
19  import com.liferay.portal.kernel.workflow.WorkflowDefinition;
20  import com.liferay.portal.kernel.workflow.WorkflowDefinitionManagerUtil;
21  import com.liferay.portal.theme.ThemeDisplay;
22  import com.liferay.portal.util.PortalUtil;
23  import com.liferay.portal.util.WebKeys;
24  
25  import java.util.List;
26  
27  import javax.portlet.ActionRequest;
28  import javax.portlet.RenderRequest;
29  
30  import javax.servlet.http.HttpServletRequest;
31  
32  /**
33   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Bruno Farache
36   */
37  public class ActionUtil {
38  
39      public static void getWorkflowDefinition(ActionRequest actionRequest)
40          throws Exception {
41  
42          HttpServletRequest request = PortalUtil.getHttpServletRequest(
43              actionRequest);
44  
45          getWorkflowDefinition(request);
46      }
47  
48      public static void getWorkflowDefinition(RenderRequest renderRequest)
49          throws Exception {
50  
51          HttpServletRequest request = PortalUtil.getHttpServletRequest(
52              renderRequest);
53  
54          getWorkflowDefinition(request);
55      }
56  
57      public static void getWorkflowDefinition(HttpServletRequest request)
58          throws Exception {
59  
60          if (request.getAttribute(WebKeys.WORKFLOW_DEFINITION) != null) {
61              return;
62          }
63  
64          ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
65              WebKeys.THEME_DISPLAY);
66  
67          String name = ParamUtil.getString(request, "name");
68          int version = ParamUtil.getInteger(request, "version");
69  
70          List<WorkflowDefinition> workflowDefinitions =
71              WorkflowDefinitionManagerUtil.getWorkflowDefinitions(
72                  themeDisplay.getCompanyId(), name, QueryUtil.ALL_POS,
73                  QueryUtil.ALL_POS, null);
74  
75          for (WorkflowDefinition workflowDefinition : workflowDefinitions) {
76              if (version == workflowDefinition.getVersion()) {
77                  request.setAttribute(
78                      WebKeys.WORKFLOW_DEFINITION, workflowDefinition);
79  
80                  break;
81              }
82          }
83      }
84  
85  }