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.model.Layout;
29 import com.liferay.portal.security.auth.PrincipalException;
30 import com.liferay.portal.struts.PortletAction;
31 import com.liferay.portal.util.WebKeys;
32 import com.liferay.portlet.softwarecatalog.FrameworkVersionNameException;
33 import com.liferay.portlet.softwarecatalog.NoSuchFrameworkVersionException;
34 import com.liferay.portlet.softwarecatalog.service.SCFrameworkVersionServiceUtil;
35
36 import javax.portlet.ActionRequest;
37 import javax.portlet.ActionResponse;
38 import javax.portlet.PortletConfig;
39 import javax.portlet.RenderRequest;
40 import javax.portlet.RenderResponse;
41
42 import org.apache.struts.action.ActionForm;
43 import org.apache.struts.action.ActionForward;
44 import org.apache.struts.action.ActionMapping;
45
46
52 public class EditFrameworkVersionAction extends PortletAction {
53
54 public void processAction(
55 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
56 ActionRequest actionRequest, ActionResponse actionResponse)
57 throws Exception {
58
59 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
60
61 try {
62 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
63 updateFrameworkVersion(actionRequest);
64 }
65 else if (cmd.equals(Constants.DELETE)) {
66 deleteFrameworkVersion(actionRequest);
67 }
68
69 sendRedirect(actionRequest, actionResponse);
70 }
71 catch (Exception e) {
72 if (e instanceof NoSuchFrameworkVersionException ||
73 e instanceof PrincipalException) {
74
75 SessionErrors.add(actionRequest, e.getClass().getName());
76
77 setForward(actionRequest, "portlet.software_catalog.error");
78 }
79 else if (e instanceof FrameworkVersionNameException) {
80
81 SessionErrors.add(actionRequest, e.getClass().getName());
82 }
83 else {
84 throw e;
85 }
86 }
87 }
88
89 public ActionForward render(
90 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
91 RenderRequest renderRequest, RenderResponse renderResponse)
92 throws Exception {
93
94 try {
95 ActionUtil.getFrameworkVersion(renderRequest);
96 }
97 catch (Exception e) {
98 if (e instanceof NoSuchFrameworkVersionException ||
99 e instanceof PrincipalException) {
100
101 SessionErrors.add(renderRequest, e.getClass().getName());
102
103 return mapping.findForward("portlet.software_catalog.error");
104 }
105 else {
106 throw e;
107 }
108 }
109
110 return mapping.findForward(getForward(
111 renderRequest, "portlet.software_catalog.edit_framework_version"));
112 }
113
114 protected void deleteFrameworkVersion(ActionRequest actionRequest)
115 throws Exception {
116
117 long frameworkVersionId = ParamUtil.getLong(
118 actionRequest, "frameworkVersionId");
119
120 SCFrameworkVersionServiceUtil.deleteFrameworkVersion(
121 frameworkVersionId);
122 }
123
124 protected void updateFrameworkVersion(ActionRequest actionRequest)
125 throws Exception {
126
127 Layout layout = (Layout)actionRequest.getAttribute(WebKeys.LAYOUT);
128
129 long frameworkVersionId = ParamUtil.getLong(
130 actionRequest, "frameworkVersionId");
131
132 String name = ParamUtil.getString(actionRequest, "name");
133 String url = ParamUtil.getString(actionRequest, "url");
134 boolean active = ParamUtil.getBoolean(actionRequest, "active");
135 int priority = ParamUtil.getInteger(actionRequest, "priority");
136
137 String[] communityPermissions = actionRequest.getParameterValues(
138 "communityPermissions");
139 String[] guestPermissions = actionRequest.getParameterValues(
140 "guestPermissions");
141
142 if (frameworkVersionId <= 0) {
143
144
146 SCFrameworkVersionServiceUtil.addFrameworkVersion(
147 layout.getPlid(), name, url, active, priority,
148 communityPermissions, guestPermissions);
149 }
150 else {
151
152
154 SCFrameworkVersionServiceUtil.updateFrameworkVersion(
155 frameworkVersionId, name, url, active, priority);
156 }
157 }
158
159 }