1
22
23 package com.liferay.portlet.softwarecatalog.action;
24
25 import com.liferay.portal.kernel.util.Constants;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.security.auth.PrincipalException;
28 import com.liferay.portal.struts.PortletAction;
29 import com.liferay.portlet.softwarecatalog.DuplicateProductVersionDirectDownloadURLException;
30 import com.liferay.portlet.softwarecatalog.NoSuchProductVersionException;
31 import com.liferay.portlet.softwarecatalog.ProductVersionChangeLogException;
32 import com.liferay.portlet.softwarecatalog.ProductVersionDownloadURLException;
33 import com.liferay.portlet.softwarecatalog.ProductVersionFrameworkVersionException;
34 import com.liferay.portlet.softwarecatalog.ProductVersionNameException;
35 import com.liferay.portlet.softwarecatalog.service.SCProductVersionServiceUtil;
36 import com.liferay.util.servlet.SessionErrors;
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 config,
58 ActionRequest req, ActionResponse res)
59 throws Exception {
60
61 String cmd = ParamUtil.getString(req, Constants.CMD);
62
63 try {
64 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
65 updateProductVersion(req);
66 }
67 else if (cmd.equals(Constants.DELETE)) {
68 deleteProductVersion(req);
69 }
70
71 sendRedirect(req, res);
72 }
73 catch (Exception e) {
74 if (e instanceof NoSuchProductVersionException ||
75 e instanceof PrincipalException) {
76
77 SessionErrors.add(req, e.getClass().getName());
78
79 setForward(req, "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(req, e.getClass().getName());
89 }
90 else {
91 throw e;
92 }
93 }
94 }
95
96 public ActionForward render(
97 ActionMapping mapping, ActionForm form, PortletConfig config,
98 RenderRequest req, RenderResponse res)
99 throws Exception {
100
101 try {
102 ActionUtil.getProductVersion(req);
103 }
104 catch (Exception e) {
105 if (e instanceof NoSuchProductVersionException ||
106 e instanceof PrincipalException) {
107
108 SessionErrors.add(req, 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 req, "portlet.software_catalog.edit_product_version"));
119 }
120
121 protected void deleteProductVersion(ActionRequest req) throws Exception {
122 long productVersionId = ParamUtil.getLong(req, "productVersionId");
123
124 SCProductVersionServiceUtil.deleteProductVersion(productVersionId);
125 }
126
127 protected void updateProductVersion(ActionRequest req) throws Exception {
128 long productVersionId = ParamUtil.getLong(req, "productVersionId");
129
130 long productEntryId = ParamUtil.getLong(req, "productEntryId");
131 String version = ParamUtil.getString(req, "version");
132 String changeLog = ParamUtil.getString(req, "changeLog");
133 String downloadPageURL = ParamUtil.getString(req, "downloadPageURL");
134 String directDownloadURL = ParamUtil.getString(
135 req, "directDownloadURL");
136 boolean repoStoreArtifact = ParamUtil.getBoolean(
137 req, "repoStoreArtifact");
138
139 long[] frameworkVersionIds = ParamUtil.getLongValues(
140 req, "frameworkVersions");
141
142 String[] communityPermissions = req.getParameterValues(
143 "communityPermissions");
144 String[] guestPermissions = req.getParameterValues(
145 "guestPermissions");
146
147 if (productVersionId <= 0) {
148
149
151 SCProductVersionServiceUtil.addProductVersion(
152 productEntryId, version, changeLog, downloadPageURL,
153 directDownloadURL, repoStoreArtifact, frameworkVersionIds,
154 communityPermissions, guestPermissions);
155 }
156 else {
157
158
160 SCProductVersionServiceUtil.updateProductVersion(
161 productVersionId, version, changeLog, downloadPageURL,
162 directDownloadURL, repoStoreArtifact, frameworkVersionIds);
163 }
164 }
165
166 }