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 actionRequest)
51          throws Exception {
52  
53          HttpServletRequest request = PortalUtil.getHttpServletRequest(
54              actionRequest);
55  
56          getFrameworkVersion(request);
57      }
58  
59      public static void getFrameworkVersion(RenderRequest renderRequest)
60          throws Exception {
61  
62          HttpServletRequest request = PortalUtil.getHttpServletRequest(
63              renderRequest);
64  
65          getFrameworkVersion(request);
66      }
67  
68      public static void getFrameworkVersion(HttpServletRequest request)
69          throws Exception {
70  
71          long frameworkVersionId = ParamUtil.getLong(
72              request, "frameworkVersionId");
73  
74          SCFrameworkVersion frameworkVersion = null;
75  
76          if (frameworkVersionId > 0) {
77              frameworkVersion =
78                  SCFrameworkVersionServiceUtil.getFrameworkVersion(
79                      frameworkVersionId);
80          }
81  
82          request.setAttribute(
83              WebKeys.SOFTWARE_CATALOG_FRAMEWORK_VERSION, frameworkVersion);
84      }
85  
86      public static void getLicense(ActionRequest actionRequest)
87          throws Exception {
88  
89          HttpServletRequest request = PortalUtil.getHttpServletRequest(
90              actionRequest);
91  
92          getLicense(request);
93      }
94  
95      public static void getLicense(RenderRequest renderRequest)
96          throws Exception {
97  
98          HttpServletRequest request = PortalUtil.getHttpServletRequest(
99              renderRequest);
100 
101         getLicense(request);
102     }
103 
104     public static void getLicense(HttpServletRequest request) throws Exception {
105         long licenseId = ParamUtil.getLong(request, "licenseId");
106 
107         SCLicense license = null;
108 
109         if (licenseId > 0) {
110             license = SCLicenseServiceUtil.getLicense(licenseId);
111         }
112 
113         request.setAttribute(WebKeys.SOFTWARE_CATALOG_LICENSE, license);
114     }
115 
116     public static void getProductEntry(ActionRequest actionRequest)
117         throws Exception {
118 
119         HttpServletRequest request = PortalUtil.getHttpServletRequest(
120             actionRequest);
121 
122         getProductEntry(request);
123     }
124 
125     public static void getProductEntry(RenderRequest renderRequest)
126         throws Exception {
127 
128         HttpServletRequest request = PortalUtil.getHttpServletRequest(
129             renderRequest);
130 
131         getProductEntry(request);
132     }
133 
134     public static void getProductEntry(HttpServletRequest request)
135         throws Exception {
136 
137         long productEntryId = ParamUtil.getLong(request, "productEntryId");
138 
139         SCProductEntry productEntry = null;
140 
141         if (productEntryId > 0) {
142             productEntry = SCProductEntryServiceUtil.getProductEntry(
143                 productEntryId);
144         }
145 
146         request.setAttribute(
147             WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
148     }
149 
150     public static void getProductVersion(ActionRequest actionRequest)
151         throws Exception {
152 
153         HttpServletRequest request = PortalUtil.getHttpServletRequest(
154             actionRequest);
155 
156         getProductVersion(request);
157     }
158 
159     public static void getProductVersion(RenderRequest renderRequest)
160         throws Exception {
161 
162         HttpServletRequest request = PortalUtil.getHttpServletRequest(
163             renderRequest);
164 
165         getProductVersion(request);
166     }
167 
168     public static void getProductVersion(HttpServletRequest request)
169         throws Exception {
170 
171         long productVersionId = ParamUtil.getLong(request, "productVersionId");
172         long copyProductVersionId = ParamUtil.getLong(
173             request, "copyProductVersionId");
174 
175         SCProductVersion productVersion = null;
176         SCProductEntry productEntry = null;
177 
178         if (productVersionId > 0) {
179             productVersion = SCProductVersionServiceUtil.getProductVersion(
180                 productVersionId);
181 
182             productEntry = SCProductEntryServiceUtil.getProductEntry(
183                 productVersion.getProductEntryId());
184 
185             request.setAttribute(
186                 WebKeys.SOFTWARE_CATALOG_PRODUCT_VERSION, productVersion);
187 
188             request.setAttribute(
189                 WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
190         }
191         else if (copyProductVersionId > 0) {
192             productVersion = SCProductVersionServiceUtil.getProductVersion(
193                 copyProductVersionId);
194 
195             productEntry = SCProductEntryServiceUtil.getProductEntry(
196                 productVersion.getProductEntryId());
197 
198             request.setAttribute(
199                 WebKeys.SOFTWARE_CATALOG_PRODUCT_VERSION, productVersion);
200 
201             request.setAttribute(
202                 WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
203         }
204         else {
205             getProductEntry(request);
206         }
207     }
208 
209 }