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.backgroundtask.action;
016    
017    import com.liferay.portal.NoSuchBackgroundTaskException;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.servlet.SessionErrors;
020    import com.liferay.portal.kernel.util.ParamUtil;
021    import com.liferay.portal.security.auth.PrincipalException;
022    import com.liferay.portal.service.BackgroundTaskLocalServiceUtil;
023    import com.liferay.portal.struts.PortletAction;
024    
025    import javax.portlet.ActionRequest;
026    import javax.portlet.ActionResponse;
027    import javax.portlet.PortletConfig;
028    
029    import org.apache.struts.action.ActionForm;
030    import org.apache.struts.action.ActionMapping;
031    
032    /**
033     * @author Michael C. Han
034     */
035    public class DeleteBackgroundTaskAction extends PortletAction {
036    
037            @Override
038            public void processAction(
039                            ActionMapping actionMapping, ActionForm actionForm,
040                            PortletConfig portletConfig, ActionRequest actionRequest,
041                            ActionResponse actionResponse)
042                    throws Exception {
043    
044                    try {
045                            deleteBackgroundTask(actionRequest);
046    
047                            sendRedirect(actionRequest, actionResponse);
048                    }
049                    catch (Exception e) {
050                            if (e instanceof NoSuchBackgroundTaskException ||
051                                    e instanceof PrincipalException) {
052    
053                                    SessionErrors.add(actionRequest, e.getClass());
054    
055                                    setForward(actionRequest, "portlet.background_task.error");
056                            }
057                            else {
058                                    throw e;
059                            }
060                    }
061            }
062    
063            protected void deleteBackgroundTask(ActionRequest actionRequest)
064                    throws PortalException {
065    
066                    long backgroundTaskId = ParamUtil.getLong(
067                            actionRequest, "backgroundTaskId");
068    
069                    BackgroundTaskLocalServiceUtil.deleteBackgroundTask(backgroundTaskId);
070            }
071    
072    }