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