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