/** * 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.MBCategoryService; import com.liferay.message.boards.web.constants.MBPortletKeys; 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.util.ParamUtil; import com.liferay.portal.kernel.util.Portal; import com.liferay.portal.kernel.util.Validator; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; /** * @author Eduardo Garcia */ @Component( property = { "javax.portlet.name=" + MBPortletKeys.MESSAGE_BOARDS, "javax.portlet.name=" + MBPortletKeys.MESSAGE_BOARDS_ADMIN, "mvc.command.name=/message_boards/move_category" }, service = MVCActionCommand.class ) public class MoveCategoryMVCActionCommand extends BaseMVCActionCommand { @Override protected void doProcessAction( ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try { moveCategory(actionRequest, actionResponse); String redirect = _portal.escapeRedirect( ParamUtil.getString(actionRequest, "redirect")); if (Validator.isNotNull(redirect)) { actionResponse.sendRedirect(redirect); } } catch (PrincipalException pe) { SessionErrors.add(actionRequest, pe.getClass()); } } protected void moveCategory( ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { long categoryId = ParamUtil.getLong(actionRequest, "mbCategoryId"); long parentCategoryId = ParamUtil.getLong( actionRequest, "parentCategoryId"); boolean mergeWithParentCategory = ParamUtil.getBoolean( actionRequest, "mergeWithParentCategory"); _mbCategoryService.moveCategory( categoryId, parentCategoryId, mergeWithParentCategory); } @Reference(unbind = "-") protected void setMBCategoryService(MBCategoryService mbCategoryService) { _mbCategoryService = mbCategoryService; } private MBCategoryService _mbCategoryService; @Reference private Portal _portal; }