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