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.security.auth.PrincipalException;
026: import com.liferay.portal.struts.PortletAction;
027: import com.liferay.portlet.softwarecatalog.DuplicateProductVersionDirectDownloadURLException;
028: import com.liferay.portlet.softwarecatalog.NoSuchProductVersionException;
029: import com.liferay.portlet.softwarecatalog.ProductVersionChangeLogException;
030: import com.liferay.portlet.softwarecatalog.ProductVersionDownloadURLException;
031: import com.liferay.portlet.softwarecatalog.ProductVersionFrameworkVersionException;
032: import com.liferay.portlet.softwarecatalog.ProductVersionNameException;
033: import com.liferay.portlet.softwarecatalog.service.SCProductVersionServiceUtil;
034: import com.liferay.util.servlet.SessionErrors;
035:
036: import javax.portlet.ActionRequest;
037: import javax.portlet.ActionResponse;
038: import javax.portlet.PortletConfig;
039: import javax.portlet.RenderRequest;
040: import javax.portlet.RenderResponse;
041:
042: import org.apache.struts.action.ActionForm;
043: import org.apache.struts.action.ActionForward;
044: import org.apache.struts.action.ActionMapping;
045:
046: /**
047: * <a href="EditProductVersionAction.java.html"><b><i>View Source</i></b></a>
048: *
049: * @author Jorge Ferrer
050: *
051: */
052: public class EditProductVersionAction extends PortletAction {
053:
054: public void processAction(ActionMapping mapping, ActionForm form,
055: PortletConfig config, ActionRequest req, ActionResponse res)
056: throws Exception {
057:
058: String cmd = ParamUtil.getString(req, Constants.CMD);
059:
060: try {
061: if (cmd.equals(Constants.ADD)
062: || cmd.equals(Constants.UPDATE)) {
063: updateProductVersion(req);
064: } else if (cmd.equals(Constants.DELETE)) {
065: deleteProductVersion(req);
066: }
067:
068: sendRedirect(req, res);
069: } catch (Exception e) {
070: if (e instanceof NoSuchProductVersionException
071: || e instanceof PrincipalException) {
072:
073: SessionErrors.add(req, e.getClass().getName());
074:
075: setForward(req, "portlet.software_catalog.error");
076: } else if (e instanceof DuplicateProductVersionDirectDownloadURLException
077: || e instanceof ProductVersionChangeLogException
078: || e instanceof ProductVersionDownloadURLException
079: || e instanceof ProductVersionFrameworkVersionException
080: || e instanceof ProductVersionNameException) {
081:
082: SessionErrors.add(req, e.getClass().getName());
083: } else {
084: throw e;
085: }
086: }
087: }
088:
089: public ActionForward render(ActionMapping mapping, ActionForm form,
090: PortletConfig config, RenderRequest req, RenderResponse res)
091: throws Exception {
092:
093: try {
094: ActionUtil.getProductVersion(req);
095: } catch (Exception e) {
096: if (e instanceof NoSuchProductVersionException
097: || e instanceof PrincipalException) {
098:
099: SessionErrors.add(req, e.getClass().getName());
100:
101: return mapping
102: .findForward("portlet.software_catalog.error");
103: } else {
104: throw e;
105: }
106: }
107:
108: return mapping.findForward(getForward(req,
109: "portlet.software_catalog.edit_product_version"));
110: }
111:
112: protected void deleteProductVersion(ActionRequest req)
113: throws Exception {
114: long productVersionId = ParamUtil.getLong(req,
115: "productVersionId");
116:
117: SCProductVersionServiceUtil
118: .deleteProductVersion(productVersionId);
119: }
120:
121: protected void updateProductVersion(ActionRequest req)
122: throws Exception {
123: long productVersionId = ParamUtil.getLong(req,
124: "productVersionId");
125:
126: long productEntryId = ParamUtil.getLong(req, "productEntryId");
127: String version = ParamUtil.getString(req, "version");
128: String changeLog = ParamUtil.getString(req, "changeLog");
129: String downloadPageURL = ParamUtil.getString(req,
130: "downloadPageURL");
131: String directDownloadURL = ParamUtil.getString(req,
132: "directDownloadURL");
133: boolean repoStoreArtifact = ParamUtil.getBoolean(req,
134: "repoStoreArtifact");
135:
136: long[] frameworkVersionIds = ParamUtil.getLongValues(req,
137: "frameworkVersions");
138:
139: String[] communityPermissions = req
140: .getParameterValues("communityPermissions");
141: String[] guestPermissions = req
142: .getParameterValues("guestPermissions");
143:
144: if (productVersionId <= 0) {
145:
146: // Add product version
147:
148: SCProductVersionServiceUtil.addProductVersion(
149: productEntryId, version, changeLog,
150: downloadPageURL, directDownloadURL,
151: repoStoreArtifact, frameworkVersionIds,
152: communityPermissions, guestPermissions);
153: } else {
154:
155: // Update product version
156:
157: SCProductVersionServiceUtil.updateProductVersion(
158: productVersionId, version, changeLog,
159: downloadPageURL, directDownloadURL,
160: repoStoreArtifact, frameworkVersionIds);
161: }
162: }
163:
164: }
|