1
22
23 package com.liferay.portlet.softwarecatalog.action;
24
25 import com.liferay.portal.kernel.util.ParamUtil;
26 import com.liferay.portal.kernel.util.StringUtil;
27 import com.liferay.portal.util.PortalUtil;
28 import com.liferay.portal.util.WebKeys;
29 import com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion;
30 import com.liferay.portlet.softwarecatalog.model.SCLicense;
31 import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
32 import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
33 import com.liferay.portlet.softwarecatalog.service.SCFrameworkVersionServiceUtil;
34 import com.liferay.portlet.softwarecatalog.service.SCLicenseServiceUtil;
35 import com.liferay.portlet.softwarecatalog.service.SCProductEntryServiceUtil;
36 import com.liferay.portlet.softwarecatalog.service.SCProductVersionServiceUtil;
37 import com.liferay.util.Version;
38
39 import javax.portlet.ActionRequest;
40 import javax.portlet.RenderRequest;
41
42 import javax.servlet.http.HttpServletRequest;
43
44
50 public class ActionUtil {
51
52 public static void getFrameworkVersion(ActionRequest actionRequest)
53 throws Exception {
54
55 HttpServletRequest request = PortalUtil.getHttpServletRequest(
56 actionRequest);
57
58 getFrameworkVersion(request);
59 }
60
61 public static void getFrameworkVersion(RenderRequest renderRequest)
62 throws Exception {
63
64 HttpServletRequest request = PortalUtil.getHttpServletRequest(
65 renderRequest);
66
67 getFrameworkVersion(request);
68 }
69
70 public static void getFrameworkVersion(HttpServletRequest request)
71 throws Exception {
72
73 long frameworkVersionId = ParamUtil.getLong(
74 request, "frameworkVersionId");
75
76 SCFrameworkVersion frameworkVersion = null;
77
78 if (frameworkVersionId > 0) {
79 frameworkVersion =
80 SCFrameworkVersionServiceUtil.getFrameworkVersion(
81 frameworkVersionId);
82 }
83
84 request.setAttribute(
85 WebKeys.SOFTWARE_CATALOG_FRAMEWORK_VERSION, frameworkVersion);
86 }
87
88 public static void getLicense(ActionRequest actionRequest)
89 throws Exception {
90
91 HttpServletRequest request = PortalUtil.getHttpServletRequest(
92 actionRequest);
93
94 getLicense(request);
95 }
96
97 public static void getLicense(RenderRequest renderRequest)
98 throws Exception {
99
100 HttpServletRequest request = PortalUtil.getHttpServletRequest(
101 renderRequest);
102
103 getLicense(request);
104 }
105
106 public static void getLicense(HttpServletRequest request) throws Exception {
107 long licenseId = ParamUtil.getLong(request, "licenseId");
108
109 SCLicense license = null;
110
111 if (licenseId > 0) {
112 license = SCLicenseServiceUtil.getLicense(licenseId);
113 }
114
115 request.setAttribute(WebKeys.SOFTWARE_CATALOG_LICENSE, license);
116 }
117
118 public static void getProductEntry(ActionRequest actionRequest)
119 throws Exception {
120
121 HttpServletRequest request = PortalUtil.getHttpServletRequest(
122 actionRequest);
123
124 getProductEntry(request);
125 }
126
127 public static void getProductEntry(RenderRequest renderRequest)
128 throws Exception {
129
130 HttpServletRequest request = PortalUtil.getHttpServletRequest(
131 renderRequest);
132
133 getProductEntry(request);
134 }
135
136 public static void getProductEntry(HttpServletRequest request)
137 throws Exception {
138
139 long productEntryId = ParamUtil.getLong(request, "productEntryId");
140
141 SCProductEntry productEntry = null;
142
143 if (productEntryId > 0) {
144 productEntry = SCProductEntryServiceUtil.getProductEntry(
145 productEntryId);
146 }
147
148 request.setAttribute(
149 WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
150 }
151
152 public static void getProductVersion(ActionRequest actionRequest)
153 throws Exception {
154
155 HttpServletRequest request = PortalUtil.getHttpServletRequest(
156 actionRequest);
157
158 getProductVersion(request);
159 }
160
161 public static void getProductVersion(RenderRequest renderRequest)
162 throws Exception {
163
164 HttpServletRequest request = PortalUtil.getHttpServletRequest(
165 renderRequest);
166
167 getProductVersion(request);
168 }
169
170 public static void getProductVersion(HttpServletRequest request)
171 throws Exception {
172
173 long productVersionId = ParamUtil.getLong(request, "productVersionId");
174 long copyProductVersionId = ParamUtil.getLong(
175 request, "copyProductVersionId");
176
177 SCProductVersion productVersion = null;
178 SCProductEntry productEntry = null;
179
180 if (productVersionId > 0) {
181 productVersion = SCProductVersionServiceUtil.getProductVersion(
182 productVersionId);
183
184 productEntry = SCProductEntryServiceUtil.getProductEntry(
185 productVersion.getProductEntryId());
186
187 request.setAttribute(
188 WebKeys.SOFTWARE_CATALOG_PRODUCT_VERSION, productVersion);
189
190 request.setAttribute(
191 WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
192 }
193 else if (copyProductVersionId > 0) {
194 productVersion = SCProductVersionServiceUtil.getProductVersion(
195 copyProductVersionId);
196
197 productEntry = SCProductEntryServiceUtil.getProductEntry(
198 productVersion.getProductEntryId());
199
200 String oldVersion = productVersion.getVersion();
201
202 Version version = Version.getInstance(oldVersion);
203
204 version = Version.incrementBuildNumber(version);
205
206 String newVersion = version.toString();
207
208 productVersion.setVersion(newVersion);
209
210 String directDownloadURL = productVersion.getDirectDownloadURL();
211
212 directDownloadURL = StringUtil.replace(
213 directDownloadURL, oldVersion, newVersion);
214
215 productVersion.setDirectDownloadURL(directDownloadURL);
216
217 request.setAttribute(
218 WebKeys.SOFTWARE_CATALOG_PRODUCT_VERSION, productVersion);
219
220 request.setAttribute(
221 WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY, productEntry);
222 }
223 else {
224 getProductEntry(request);
225 }
226 }
227
228 }