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
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 long frameworkVersionId = ParamUtil.getLong(
129 actionRequest, "frameworkVersionId");
130
131 String name = ParamUtil.getString(actionRequest, "name");
132 String url = ParamUtil.getString(actionRequest, "url");
133 boolean active = ParamUtil.getBoolean(actionRequest, "active");
134 int priority = ParamUtil.getInteger(actionRequest, "priority");
135
136 ServiceContext serviceContext = ServiceContextFactory.getInstance(
137 SCFrameworkVersion.class.getName(), actionRequest);
138
139 if (frameworkVersionId <= 0) {
140
141
143 SCFrameworkVersionServiceUtil.addFrameworkVersion(
144 name, url, active, priority, serviceContext);
145 }
146 else {
147
148
150 SCFrameworkVersionServiceUtil.updateFrameworkVersion(
151 frameworkVersionId, name, url, active, priority);
152 }
153 }
154
155 }