/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.message.boards.web.internal.portlet.action; import com.liferay.message.boards.kernel.service.MBMessageLocalService; import com.liferay.message.boards.kernel.service.MBMessageService; import com.liferay.message.boards.web.constants.MBPortletKeys; import com.liferay.portal.kernel.exception.PortalException; import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand; import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand; import com.liferay.portal.kernel.security.auth.PrincipalException; import com.liferay.portal.kernel.servlet.SessionErrors; import com.liferay.portal.kernel.theme.ThemeDisplay; import com.liferay.portal.kernel.util.Constants; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.kernel.util.Validator; import com.liferay.portal.kernel.util.WebKeys; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Eudaldo Alonso */ @Component( property = { "javax.portlet.name=" + MBPortletKeys.MESSAGE_BOARDS, "javax.portlet.name=" + MBPortletKeys.MESSAGE_BOARDS_ADMIN, "mvc.command.name=/message_boards/edit_message_attachments" }, service = MVCActionCommand.class ) public class EditMessageAttachmentsMVCActionCommand extends BaseMVCActionCommand { protected void deleteAttachment(ActionRequest actionRequest) throws PortalException { long messageId = ParamUtil.getLong(actionRequest, "messageId"); String fileName = ParamUtil.getString(actionRequest, "fileName"); _mbMessageLocalService.deleteMessageAttachment(messageId, fileName); } @Override protected void doProcessAction( ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try { if (cmd.equals(Constants.DELETE)) { deleteAttachment(actionRequest); } else if (cmd.equals(Constants.EMPTY_TRASH)) { emptyTrash(actionRequest); } else if (cmd.equals(Constants.RESTORE)) { restoreEntries(actionRequest); } if (Validator.isNotNull(cmd)) { String redirect = ParamUtil.getString( actionRequest, "redirect"); sendRedirect(actionRequest, actionResponse, redirect); } } catch (PrincipalException pe) { SessionErrors.add(actionRequest, pe.getClass()); actionResponse.setRenderParameter( "mvcPath", "/message_boards/error.jsp"); } } protected void emptyTrash(ActionRequest actionRequest) throws Exception { long messageId = ParamUtil.getLong(actionRequest, "messageId"); _mbMessageService.emptyMessageAttachments(messageId); } protected void restoreEntries(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute( WebKeys.THEME_DISPLAY); long messageId = ParamUtil.getLong(actionRequest, "messageId"); String fileName = ParamUtil.getString(actionRequest, "fileName"); _mbMessageLocalService.restoreMessageAttachmentFromTrash( themeDisplay.getUserId(), messageId, fileName); } @Reference(unbind = "-") protected void setMBMessageLocalService( MBMessageLocalService mbMessageLocalService) { _mbMessageLocalService = mbMessageLocalService; } @Reference(unbind = "-") protected void setMBMessageService(MBMessageService mbMessageService) { _mbMessageService = mbMessageService; } private MBMessageLocalService _mbMessageLocalService; private MBMessageService _mbMessageService; }