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