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.portal.repository.capabilities.util;
016    
017    import com.liferay.portal.kernel.exception.SystemException;
018    import com.liferay.portal.kernel.repository.DocumentRepository;
019    import com.liferay.portal.kernel.repository.model.FileEntry;
020    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
021    
022    /**
023     * @author Iv??n Zaera
024     */
025    public class RepositoryEntryChecker {
026    
027            public RepositoryEntryChecker(DocumentRepository documentRepository) {
028                    _documentRepository = documentRepository;
029            }
030    
031            public DLFileEntry checkDLFileEntry(DLFileEntry dlFileEntry) {
032                    long repositoryId = _documentRepository.getRepositoryId();
033    
034                    if (dlFileEntry.getRepositoryId() != repositoryId) {
035                            throw new SystemException(
036                                    "File entry " + dlFileEntry.getFileEntryId() + " does not " +
037                                            "belong to repository " + repositoryId);
038                    }
039    
040                    return dlFileEntry;
041            }
042    
043            public FileEntry checkFileEntry(FileEntry fileEntry) {
044                    long repositoryId = _documentRepository.getRepositoryId();
045    
046                    if (fileEntry.getRepositoryId() != repositoryId) {
047                            throw new SystemException(
048                                    "File entry " + fileEntry.getFileEntryId() + " does not " +
049                                            "belong to repository " + repositoryId);
050                    }
051    
052                    return fileEntry;
053            }
054    
055            private final DocumentRepository _documentRepository;
056    
057    }