001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.softwarecatalog.action;
016    
017    import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
018    import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
019    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
020    import com.liferay.portal.kernel.util.Constants;
021    import com.liferay.portal.kernel.util.ParamUtil;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portal.service.ServiceContextFactory;
024    import com.liferay.portal.util.PortletKeys;
025    import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
026    import com.liferay.portlet.softwarecatalog.service.SCProductVersionServiceUtil;
027    
028    import javax.portlet.ActionRequest;
029    import javax.portlet.ActionResponse;
030    
031    /**
032     * @author Jorge Ferrer
033     * @author Philip Jones
034     */
035    @OSGiBeanProperties(
036            property = {
037                    "javax.portlet.name=" + PortletKeys.SOFTWARE_CATALOG,
038                    "mvc.command.name=/software_catalog/edit_product_version"
039            },
040            service = MVCActionCommand.class
041    )
042    public class EditProductVersionMVCActionCommand extends BaseMVCActionCommand {
043    
044            @Override
045            public void doProcessAction(
046                            ActionRequest actionRequest, ActionResponse actionResponse)
047                    throws Exception {
048    
049                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
050    
051                    if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
052                            updateProductVersion(actionRequest);
053                    }
054                    else if (cmd.equals(Constants.DELETE)) {
055                            deleteProductVersion(actionRequest);
056                    }
057    
058                    sendRedirect(actionRequest, actionResponse);
059            }
060    
061            protected void deleteProductVersion(ActionRequest actionRequest)
062                    throws Exception {
063    
064                    long productVersionId = ParamUtil.getLong(
065                            actionRequest, "productVersionId");
066    
067                    SCProductVersionServiceUtil.deleteProductVersion(productVersionId);
068            }
069    
070            protected void updateProductVersion(ActionRequest actionRequest)
071                    throws Exception {
072    
073                    long productVersionId = ParamUtil.getLong(
074                            actionRequest, "productVersionId");
075    
076                    long productEntryId = ParamUtil.getLong(
077                            actionRequest, "productEntryId");
078                    String version = ParamUtil.getString(actionRequest, "version");
079                    String changeLog = ParamUtil.getString(actionRequest, "changeLog");
080                    String downloadPageURL = ParamUtil.getString(
081                            actionRequest, "downloadPageURL");
082                    String directDownloadURL = ParamUtil.getString(
083                            actionRequest, "directDownloadURL");
084                    boolean testDirectDownloadURL = ParamUtil.getBoolean(
085                            actionRequest, "testDirectDownloadURL");
086                    boolean repoStoreArtifact = ParamUtil.getBoolean(
087                            actionRequest, "repoStoreArtifact");
088    
089                    long[] frameworkVersionIds = ParamUtil.getLongValues(
090                            actionRequest, "frameworkVersions");
091    
092                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
093                            SCProductVersion.class.getName(), actionRequest);
094    
095                    if (productVersionId <= 0) {
096    
097                            // Add product version
098    
099                            SCProductVersionServiceUtil.addProductVersion(
100                                    productEntryId, version, changeLog, downloadPageURL,
101                                    directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
102                                    frameworkVersionIds, serviceContext);
103                    }
104                    else {
105    
106                            // Update product version
107    
108                            SCProductVersionServiceUtil.updateProductVersion(
109                                    productVersionId, version, changeLog, downloadPageURL,
110                                    directDownloadURL, testDirectDownloadURL, repoStoreArtifact,
111                                    frameworkVersionIds);
112                    }
113            }
114    
115    }