001
014
015 package com.liferay.portal.repository.util;
016
017 import com.liferay.portal.InvalidRepositoryException;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.repository.LocalRepository;
020 import com.liferay.portal.kernel.repository.RepositoryProviderUtil;
021 import com.liferay.portal.kernel.repository.capabilities.TrashCapability;
022 import com.liferay.portal.kernel.repository.model.FileEntry;
023 import com.liferay.portal.kernel.repository.model.Folder;
024 import com.liferay.portal.kernel.repository.util.RepositoryTrash;
025 import com.liferay.portal.service.ServiceContext;
026 import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
027
028
031 public class RepositoryTrashImpl implements RepositoryTrash {
032
033 @Override
034 public FileEntry moveFileEntryFromTrash(
035 long userId, long repositoryId, long fileEntryId, long newFolderId,
036 ServiceContext serviceContext)
037 throws PortalException {
038
039 LocalRepository localRepository =
040 RepositoryProviderUtil.getLocalRepository(repositoryId);
041
042 validateCapability(localRepository);
043
044 TrashCapability trashCapability = localRepository.getCapability(
045 TrashCapability.class);
046
047 FileEntry fileEntry = localRepository.getFileEntry(fileEntryId);
048
049 Folder newFolder = null;
050
051 if (newFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
052 newFolder = localRepository.getFolder(newFolderId);
053 }
054
055 return trashCapability.moveFileEntryFromTrash(
056 userId, fileEntry, newFolder, serviceContext);
057 }
058
059 @Override
060 public FileEntry moveFileEntryToTrash(
061 long userId, long repositoryId, long fileEntryId)
062 throws PortalException {
063
064 LocalRepository localRepository =
065 RepositoryProviderUtil.getLocalRepository(repositoryId);
066
067 validateCapability(localRepository);
068
069 TrashCapability trashCapability = localRepository.getCapability(
070 TrashCapability.class);
071
072 FileEntry fileEntry = localRepository.getFileEntry(fileEntryId);
073
074 return trashCapability.moveFileEntryToTrash(userId, fileEntry);
075 }
076
077 @Override
078 public void restoreFileEntryFromTrash(
079 long userId, long repositoryId, long fileEntryId)
080 throws PortalException {
081
082 LocalRepository localRepository =
083 RepositoryProviderUtil.getLocalRepository(repositoryId);
084
085 validateCapability(localRepository);
086
087 TrashCapability trashCapability = localRepository.getCapability(
088 TrashCapability.class);
089
090 FileEntry fileEntry = localRepository.getFileEntry(fileEntryId);
091
092 trashCapability.restoreFileEntryFromTrash(userId, fileEntry);
093 }
094
095 protected void validateCapability(LocalRepository localRepository)
096 throws InvalidRepositoryException {
097
098 if (!localRepository.isCapabilityProvided(TrashCapability.class)) {
099 throw new InvalidRepositoryException(
100 "Repository " + localRepository.getRepositoryId() +
101 " does not support trash operations");
102 }
103 }
104
105 }