001
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.util.PortletKeys;
023 import com.liferay.portlet.softwarecatalog.service.SCLicenseServiceUtil;
024
025 import javax.portlet.ActionRequest;
026 import javax.portlet.ActionResponse;
027
028
031 @OSGiBeanProperties(
032 property = {
033 "javax.portlet.name=" + PortletKeys.SOFTWARE_CATALOG,
034 "mvc.command.name=/software_catalog/edit_license"
035 },
036 service = MVCActionCommand.class
037 )
038 public class EditLicenseMVCActionCommand extends BaseMVCActionCommand {
039
040 @Override
041 public void doProcessAction(
042 ActionRequest actionRequest, ActionResponse actionResponse)
043 throws Exception {
044
045 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
046
047 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
048 updateLicense(actionRequest);
049 }
050 else if (cmd.equals(Constants.DELETE)) {
051 deleteLicense(actionRequest);
052 }
053
054 sendRedirect(actionRequest, actionResponse);
055 }
056
057 protected void deleteLicense(ActionRequest actionRequest) throws Exception {
058 long licenseId = ParamUtil.getLong(actionRequest, "licenseId");
059
060 SCLicenseServiceUtil.deleteLicense(licenseId);
061 }
062
063 protected void updateLicense(ActionRequest actionRequest) throws Exception {
064 long licenseId = ParamUtil.getLong(actionRequest, "licenseId");
065
066 String name = ParamUtil.getString(actionRequest, "name");
067 String url = ParamUtil.getString(actionRequest, "url");
068 boolean openSource = ParamUtil.getBoolean(actionRequest, "openSource");
069 boolean active = ParamUtil.getBoolean(actionRequest, "active");
070 boolean recommended = ParamUtil.getBoolean(
071 actionRequest, "recommended");
072
073 if (licenseId <= 0) {
074
075
076
077 SCLicenseServiceUtil.addLicense(
078 name, url, openSource, active, recommended);
079 }
080 else {
081
082
083
084 SCLicenseServiceUtil.updateLicense(
085 licenseId, name, url, openSource, active, recommended);
086 }
087 }
088
089 }