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