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