1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.softwarecatalog.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.util.PortalUtil;
27  import com.liferay.portal.util.WebKeys;
28  import com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion;
29  import com.liferay.portlet.softwarecatalog.model.SCLicense;
30  import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
31  import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
32  import com.liferay.portlet.softwarecatalog.service.SCFrameworkVersionServiceUtil;
33  import com.liferay.portlet.softwarecatalog.service.SCLicenseServiceUtil;
34  import com.liferay.portlet.softwarecatalog.service.SCProductEntryServiceUtil;
35  import com.liferay.portlet.softwarecatalog.service.SCProductVersionServiceUtil;
36  
37  import javax.portlet.ActionRequest;
38  import javax.portlet.RenderRequest;
39  
40  import javax.servlet.http.HttpServletRequest;
41  
42  /**
43   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Jorge Ferrer
46   *
47   */
48  public class ActionUtil {
49  
50      public static void getFrameworkVersion(ActionRequest req) throws Exception {
51          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
52  
53          getFrameworkVersion(httpReq);
54      }
55  
56      public static void getFrameworkVersion(RenderRequest req) throws Exception {
57          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
58  
59          getFrameworkVersion(httpReq);
60      }
61  
62      public static void getFrameworkVersion(HttpServletRequest req)
63          throws Exception {
64  
65          long frameworkVersionId = ParamUtil.getLong(req, "frameworkVersionId");
66  
67          SCFrameworkVersion frameworkVersion = null;
68  
69          if (frameworkVersionId > 0) {
70              frameworkVersion =
71                  SCFrameworkVersionServiceUtil.getFrameworkVersion(
72                      frameworkVersionId);
73          }
74  
75          req.setAttribute(
76              WebKeys.SOFTWARE_CATALOG_FRAMEWORK_VERSION, frameworkVersion);
77      }
78  
79      public static void getLicense(ActionRequest req) throws Exception {
80          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
81  
82          getLicense(httpReq);
83      }
84  
85      public static void getLicense(RenderRequest req) throws Exception {
86          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
87  
88          getLicense(httpReq);
89      }
90  
91      public static void getLicense(HttpServletRequest req) throws Exception {
92          long licenseId = ParamUtil.getLong(req, "licenseId");
93  
94          SCLicense license = null;
95  
96          if (licenseId > 0) {
97              license = SCLicenseServiceUtil.getLicense(licenseId);
98          }
99  
100         req.setAttribute(WebKeys.SOFTWARE_CATALOG_LICENSE, license);
101     }
102 
103     public static void getProductEntry(ActionRequest req) throws Exception {
104         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
105 
106         getProductEntry(httpReq);
107     }
108 
109     public static void getProductEntry(RenderRequest req) throws Exception {
110         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
111 
112         getProductEntry(httpReq);
113     }
114 
115     public static void getProductEntry(HttpServletRequest req)
116         throws Exception {
117 
118         long productEntryId = ParamUtil.getLong(req, "productEntryId");
119 
120         SCProductEntry productEntry = null;
121 
122         if (productEntryId > 0) {
123             productEntry = SCProductEntryServiceUtil.getProductEntry(
124                 productEntryId);
125         }
126 
127         req.setAttribute(
128             WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
129     }
130 
131     public static void getProductVersion(ActionRequest req) throws Exception {
132         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
133 
134         getProductVersion(httpReq);
135     }
136 
137     public static void getProductVersion(RenderRequest req) throws Exception {
138         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
139 
140         getProductVersion(httpReq);
141     }
142 
143     public static void getProductVersion(HttpServletRequest req)
144         throws Exception {
145 
146         long productVersionId = ParamUtil.getLong(req, "productVersionId");
147         long copyProductVersionId = ParamUtil.getLong(
148             req, "copyProductVersionId");
149 
150         SCProductVersion productVersion = null;
151         SCProductEntry productEntry = null;
152 
153         if (productVersionId > 0) {
154             productVersion = SCProductVersionServiceUtil.getProductVersion(
155                 productVersionId);
156 
157             productEntry = SCProductEntryServiceUtil.getProductEntry(
158                 productVersion.getProductEntryId());
159 
160             req.setAttribute(
161                 WebKeys.SOFTWARE_CATALOG_PRODUCT_VERSION, productVersion);
162 
163             req.setAttribute(
164                 WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
165         }
166         else if (copyProductVersionId > 0) {
167             productVersion = SCProductVersionServiceUtil.getProductVersion(
168                 copyProductVersionId);
169 
170             productEntry = SCProductEntryServiceUtil.getProductEntry(
171                 productVersion.getProductEntryId());
172 
173             req.setAttribute(
174                 WebKeys.SOFTWARE_CATALOG_PRODUCT_VERSION, productVersion);
175 
176             req.setAttribute(
177                 WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
178         }
179         else {
180             getProductEntry(req);
181         }
182     }
183 
184 }