001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.softwarecatalog.action;
022:
023: import com.liferay.portal.kernel.util.Constants;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.model.Layout;
026: import com.liferay.portal.security.auth.PrincipalException;
027: import com.liferay.portal.struts.PortletAction;
028: import com.liferay.portal.util.WebKeys;
029: import com.liferay.portlet.softwarecatalog.FrameworkVersionNameException;
030: import com.liferay.portlet.softwarecatalog.NoSuchFrameworkVersionException;
031: import com.liferay.portlet.softwarecatalog.service.SCFrameworkVersionServiceUtil;
032: import com.liferay.util.servlet.SessionErrors;
033:
034: import javax.portlet.ActionRequest;
035: import javax.portlet.ActionResponse;
036: import javax.portlet.PortletConfig;
037: import javax.portlet.RenderRequest;
038: import javax.portlet.RenderResponse;
039:
040: import org.apache.struts.action.ActionForm;
041: import org.apache.struts.action.ActionForward;
042: import org.apache.struts.action.ActionMapping;
043:
044: /**
045: * <a href="EditFrameworkVersionAction.java.html"><b><i>View Source</i></b></a>
046: *
047: * @author Jorge Ferrer
048: *
049: */
050: public class EditFrameworkVersionAction extends PortletAction {
051:
052: public void processAction(ActionMapping mapping, ActionForm form,
053: PortletConfig config, ActionRequest req, ActionResponse res)
054: throws Exception {
055:
056: String cmd = ParamUtil.getString(req, Constants.CMD);
057:
058: try {
059: if (cmd.equals(Constants.ADD)
060: || cmd.equals(Constants.UPDATE)) {
061: updateFrameworkVersion(req);
062: } else if (cmd.equals(Constants.DELETE)) {
063: deleteFrameworkVersion(req);
064: }
065:
066: sendRedirect(req, res);
067: } catch (Exception e) {
068: if (e instanceof NoSuchFrameworkVersionException
069: || e instanceof PrincipalException) {
070:
071: SessionErrors.add(req, e.getClass().getName());
072:
073: setForward(req, "portlet.software_catalog.error");
074: } else if (e instanceof FrameworkVersionNameException) {
075:
076: SessionErrors.add(req, e.getClass().getName());
077: } else {
078: throw e;
079: }
080: }
081: }
082:
083: public ActionForward render(ActionMapping mapping, ActionForm form,
084: PortletConfig config, RenderRequest req, RenderResponse res)
085: throws Exception {
086:
087: try {
088: ActionUtil.getFrameworkVersion(req);
089: } catch (Exception e) {
090: if (e instanceof NoSuchFrameworkVersionException
091: || e instanceof PrincipalException) {
092:
093: SessionErrors.add(req, e.getClass().getName());
094:
095: return mapping
096: .findForward("portlet.software_catalog.error");
097: } else {
098: throw e;
099: }
100: }
101:
102: return mapping.findForward(getForward(req,
103: "portlet.software_catalog.edit_framework_version"));
104: }
105:
106: protected void deleteFrameworkVersion(ActionRequest req)
107: throws Exception {
108: long frameworkVersionId = ParamUtil.getLong(req,
109: "frameworkVersionId");
110:
111: SCFrameworkVersionServiceUtil
112: .deleteFrameworkVersion(frameworkVersionId);
113: }
114:
115: protected void updateFrameworkVersion(ActionRequest req)
116: throws Exception {
117: Layout layout = (Layout) req.getAttribute(WebKeys.LAYOUT);
118:
119: long frameworkVersionId = ParamUtil.getLong(req,
120: "frameworkVersionId");
121:
122: String name = ParamUtil.getString(req, "name");
123: String url = ParamUtil.getString(req, "url");
124: boolean active = ParamUtil.getBoolean(req, "active");
125: int priority = ParamUtil.getInteger(req, "priority");
126:
127: String[] communityPermissions = req
128: .getParameterValues("communityPermissions");
129: String[] guestPermissions = req
130: .getParameterValues("guestPermissions");
131:
132: if (frameworkVersionId <= 0) {
133:
134: // Add framework version
135:
136: SCFrameworkVersionServiceUtil.addFrameworkVersion(layout
137: .getPlid(), name, url, active, priority,
138: communityPermissions, guestPermissions);
139: } else {
140:
141: // Update framework version
142:
143: SCFrameworkVersionServiceUtil.updateFrameworkVersion(
144: frameworkVersionId, name, url, active, priority);
145: }
146: }
147:
148: }
|