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.service.ServiceContext;
30 import com.liferay.portal.service.ServiceContextFactory;
31 import com.liferay.portal.struts.PortletAction;
32 import com.liferay.portlet.softwarecatalog.FrameworkVersionNameException;
33 import com.liferay.portlet.softwarecatalog.NoSuchFrameworkVersionException;
34 import com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion;
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
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 long frameworkVersionId = ParamUtil.getLong(
128 actionRequest, "frameworkVersionId");
129
130 String name = ParamUtil.getString(actionRequest, "name");
131 String url = ParamUtil.getString(actionRequest, "url");
132 boolean active = ParamUtil.getBoolean(actionRequest, "active");
133 int priority = ParamUtil.getInteger(actionRequest, "priority");
134
135 ServiceContext serviceContext = ServiceContextFactory.getInstance(
136 SCFrameworkVersion.class.getName(), actionRequest);
137
138 if (frameworkVersionId <= 0) {
139
140
142 SCFrameworkVersionServiceUtil.addFrameworkVersion(
143 name, url, active, priority, serviceContext);
144 }
145 else {
146
147
149 SCFrameworkVersionServiceUtil.updateFrameworkVersion(
150 frameworkVersionId, name, url, active, priority);
151 }
152 }
153
154 }