001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.repository.LocalRepository;
021    import com.liferay.portal.kernel.repository.RepositoryProviderUtil;
022    import com.liferay.portal.kernel.repository.capabilities.TrashCapability;
023    import com.liferay.portal.kernel.repository.model.FileEntry;
024    import com.liferay.portal.kernel.repository.model.Folder;
025    import com.liferay.portal.service.ServiceContext;
026    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
027    import com.liferay.portlet.documentlibrary.service.base.DLTrashLocalServiceBaseImpl;
028    
029    /**
030     * @author Adolfo P??rez
031     */
032    @ProviderType
033    public class DLTrashLocalServiceImpl extends DLTrashLocalServiceBaseImpl {
034    
035            @Override
036            public FileEntry moveFileEntryFromTrash(
037                            long userId, long repositoryId, long fileEntryId, long newFolderId,
038                            ServiceContext serviceContext)
039                    throws PortalException {
040    
041                    LocalRepository localRepository =
042                            RepositoryProviderUtil.getLocalRepository(repositoryId);
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                    TrashCapability trashCapability = localRepository.getCapability(
068                            TrashCapability.class);
069    
070                    FileEntry fileEntry = localRepository.getFileEntry(fileEntryId);
071    
072                    return trashCapability.moveFileEntryToTrash(userId, fileEntry);
073            }
074    
075            @Override
076            public void restoreFileEntryFromTrash(
077                            long userId, long repositoryId, long fileEntryId)
078                    throws PortalException {
079    
080                    LocalRepository localRepository =
081                            RepositoryProviderUtil.getLocalRepository(repositoryId);
082    
083                    TrashCapability trashCapability = localRepository.getCapability(
084                            TrashCapability.class);
085    
086                    FileEntry fileEntry = localRepository.getFileEntry(fileEntryId);
087    
088                    trashCapability.restoreFileEntryFromTrash(userId, fileEntry);
089            }
090    
091    }