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