1
22
23 package com.liferay.portlet.softwarecatalog.action;
24
25 import com.liferay.portal.kernel.servlet.SessionErrors;
26 import com.liferay.portal.kernel.util.Constants;
27 import com.liferay.portal.kernel.util.ParamUtil;
28 import com.liferay.portal.security.auth.PrincipalException;
29 import com.liferay.portal.service.ServiceContext;
30 import com.liferay.portal.service.ServiceContextFactory;
31 import com.liferay.portal.struts.PortletAction;
32 import com.liferay.portlet.softwarecatalog.DuplicateProductVersionDirectDownloadURLException;
33 import com.liferay.portlet.softwarecatalog.NoSuchProductVersionException;
34 import com.liferay.portlet.softwarecatalog.ProductVersionChangeLogException;
35 import com.liferay.portlet.softwarecatalog.ProductVersionDownloadURLException;
36 import com.liferay.portlet.softwarecatalog.ProductVersionFrameworkVersionException;
37 import com.liferay.portlet.softwarecatalog.ProductVersionNameException;
38 import com.liferay.portlet.softwarecatalog.UnavailableProductVersionDirectDownloadURLException;
39 import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
40 import com.liferay.portlet.softwarecatalog.service.SCProductVersionServiceUtil;
41
42 import javax.portlet.ActionRequest;
43 import javax.portlet.ActionResponse;
44 import javax.portlet.PortletConfig;
45 import javax.portlet.RenderRequest;
46 import javax.portlet.RenderResponse;
47
48 import org.apache.struts.action.ActionForm;
49 import org.apache.struts.action.ActionForward;
50 import org.apache.struts.action.ActionMapping;
51
52
58 public class EditProductVersionAction extends PortletAction {
59
60 public void processAction(
61 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
62 ActionRequest actionRequest, ActionResponse actionResponse)
63 throws Exception {
64
65 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
66
67 try {
68 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
69 updateProductVersion(actionRequest);
70 }
71 else if (cmd.equals(Constants.DELETE)) {
72 deleteProductVersion(actionRequest);
73 }
74
75 sendRedirect(actionRequest, actionResponse);
76 }
77 catch (Exception e) {
78 if (e instanceof NoSuchProductVersionException ||
79 e instanceof PrincipalException) {
80
81 SessionErrors.add(actionRequest, e.getClass().getName());
82
83 setForward(actionRequest, "portlet.software_catalog.error");
84 }
85 else if (e instanceof
86 DuplicateProductVersionDirectDownloadURLException ||
87 e instanceof ProductVersionChangeLogException ||
88 e instanceof ProductVersionDownloadURLException ||
89 e instanceof ProductVersionFrameworkVersionException ||
90 e instanceof ProductVersionNameException ||
91 e instanceof
92 UnavailableProductVersionDirectDownloadURLException) {
93
94 SessionErrors.add(actionRequest, e.getClass().getName());
95 }
96 else {
97 throw e;
98 }
99 }
100 }
101
102 public ActionForward render(
103 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
104 RenderRequest renderRequest, RenderResponse renderResponse)
105 throws Exception {
106
107 try {
108 ActionUtil.getProductVersion(renderRequest);
109 }
110 catch (Exception e) {
111 if (e instanceof NoSuchProductVersionException ||
112 e instanceof PrincipalException) {
113
114 SessionErrors.add(renderRequest, e.getClass().getName());
115
116 return mapping.findForward("portlet.software_catalog.error");
117 }
118 else {
119 throw e;
120 }
121 }
122
123 return mapping.findForward(getForward(
124 renderRequest, "portlet.software_catalog.edit_product_version"));
125 }
126
127 protected void deleteProductVersion(ActionRequest actionRequest)
128 throws Exception {
129
130 long productVersionId = ParamUtil.getLong(
131 actionRequest, "productVersionId");
132
133 SCProductVersionServiceUtil.deleteProductVersion(productVersionId);
134 }
135
136 protected void updateProductVersion(ActionRequest actionRequest)
137 throws Exception {
138
139 long productVersionId = ParamUtil.getLong(
140 actionRequest, "productVersionId");
141
142 long productEntryId = ParamUtil.getLong(
143 actionRequest, "productEntryId");
144 String version = ParamUtil.getString(actionRequest, "version");
145 String changeLog = ParamUtil.getString(actionRequest, "changeLog");
146 String downloadPageURL = ParamUtil.getString(
147 actionRequest, "downloadPageURL");
148 String directDownloadURL = ParamUtil.getString(
149 actionRequest, "directDownloadURL");
150 boolean testDirectDownloadURL = ParamUtil.getBoolean(
151 actionRequest, "testDirectDownloadURL");
152 boolean repoStoreArtifact = ParamUtil.getBoolean(
153 actionRequest, "repoStoreArtifact");
154
155 long[] frameworkVersionIds = ParamUtil.getLongValues(
156 actionRequest, "frameworkVersions");
157
158 ServiceContext serviceContext = ServiceContextFactory.getInstance(
159 SCProductVersion.class.getName(), actionRequest);
160
161 if (productVersionId <= 0) {
162
163
165 SCProductVersionServiceUtil.addProductVersion(
166 productEntryId, version, changeLog, downloadPageURL,
167 directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
168 frameworkVersionIds, serviceContext);
169 }
170 else {
171
172
174 SCProductVersionServiceUtil.updateProductVersion(
175 productVersionId, version, changeLog, downloadPageURL,
176 directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
177 frameworkVersionIds);
178 }
179 }
180
181 }