/**
* 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.wiki.web.internal.portlet.action;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
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.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.wiki.constants.WikiPortletKeys;
import com.liferay.wiki.exception.NoSuchNodeException;
import com.liferay.wiki.exception.NoSuchPageException;
import com.liferay.wiki.model.WikiPage;
import com.liferay.wiki.service.WikiPageLocalService;
import com.liferay.wiki.service.WikiPageService;
import java.util.List;
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(
immediate = true,
property = {
"javax.portlet.name=" + WikiPortletKeys.WIKI_ADMIN,
"mvc.command.name=/wiki/edit_node_attachment"
},
service = MVCActionCommand.class
)
public class EditNodeAttachmentMVCActionCommand extends BaseMVCActionCommand {
@Override
protected void doProcessAction(
ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
try {
if (cmd.equals(Constants.EMPTY_TRASH)) {
emptyTrash(actionRequest);
}
}
catch (Exception e) {
if (e instanceof NoSuchNodeException ||
e instanceof NoSuchPageException ||
e instanceof PrincipalException) {
SessionErrors.add(actionRequest, e.getClass());
}
else {
throw e;
}
}
}
protected void emptyTrash(ActionRequest actionRequest) throws Exception {
long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
List<WikiPage> wikiPages = _wikiPageLocalService.getPages(
nodeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
for (WikiPage wikiPage : wikiPages) {
if (wikiPage.getDeletedAttachmentsFileEntriesCount() > 0) {
_wikiPageService.deleteTrashPageAttachments(
nodeId, wikiPage.getTitle());
}
}
}
@Reference(unbind = "-")
protected void setWikiPageLocalService(
WikiPageLocalService wikiPageLocalService) {
_wikiPageLocalService = wikiPageLocalService;
}
@Reference(unbind = "-")
protected void setWikiPageService(WikiPageService wikiPageService) {
_wikiPageService = wikiPageService;
}
private WikiPageLocalService _wikiPageLocalService;
private WikiPageService _wikiPageService;
}