com.liferay.message.boards.internal.trash.MBMessageTrashHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.message.boards.service
Show all versions of com.liferay.message.boards.service
Liferay Message Boards Service
/**
* 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.internal.trash;
import com.liferay.document.library.kernel.model.DLFileEntry;
import com.liferay.message.boards.model.MBMessage;
import com.liferay.message.boards.model.MBThread;
import com.liferay.message.boards.service.MBMessageLocalService;
import com.liferay.message.boards.service.MBMessageService;
import com.liferay.message.boards.service.MBThreadLocalService;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.ContainerModel;
import com.liferay.portal.kernel.model.TrashedModel;
import com.liferay.portal.kernel.portletfilerepository.PortletFileRepositoryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.security.permission.resource.ModelResourcePermission;
import com.liferay.portal.kernel.trash.TrashHandler;
import com.liferay.trash.BaseTrashHandler;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* Implements trash handling for message boards message entity.
*
* @author Zsolt Berentey
*/
@Component(
property = "model.class.name=com.liferay.message.boards.model.MBMessage",
service = TrashHandler.class
)
public class MBMessageTrashHandler extends BaseTrashHandler {
@Override
public void deleteTrashEntry(long classPK) {
}
@Override
public String getClassName() {
return MBMessage.class.getName();
}
@Override
public ContainerModel getContainerModel(long containerModelId)
throws PortalException {
return _mbThreadLocalService.getThread(containerModelId);
}
@Override
public String getContainerModelClassName(long classPK) {
return MBThread.class.getName();
}
@Override
public ContainerModel getParentContainerModel(TrashedModel trashedModel)
throws PortalException {
MBMessage message = (MBMessage)trashedModel;
return getContainerModel(message.getThreadId());
}
@Override
public TrashedModel getTrashedModel(long classPK) {
return _mbMessageLocalService.fetchMBMessage(classPK);
}
@Override
public boolean isDeletable(long classPK) throws PortalException {
return false;
}
@Override
public void restoreRelatedTrashEntry(String className, long classPK)
throws PortalException {
if (!className.equals(DLFileEntry.class.getName())) {
return;
}
FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(
classPK);
MBMessage message = _mbMessageLocalService.getFileEntryMessage(classPK);
_mbMessageService.restoreMessageAttachmentFromTrash(
message.getMessageId(), fileEntry.getTitle());
}
@Override
public void restoreTrashEntry(long userId, long classPK) {
}
@Override
protected boolean hasPermission(
PermissionChecker permissionChecker, long classPK, String actionId)
throws PortalException {
return _messageModelResourcePermission.contains(
permissionChecker, classPK, actionId);
}
@Reference
private MBMessageLocalService _mbMessageLocalService;
@Reference
private MBMessageService _mbMessageService;
@Reference
private MBThreadLocalService _mbThreadLocalService;
@Reference(
target = "(model.class.name=com.liferay.message.boards.model.MBMessage)"
)
private ModelResourcePermission _messageModelResourcePermission;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy