001    /**
002     * Copyright (c) 2000-2013 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 com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
021    import com.liferay.portlet.documentlibrary.service.base.DLFileVersionServiceBaseImpl;
022    import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
023    
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class DLFileVersionServiceImpl extends DLFileVersionServiceBaseImpl {
030    
031            @Override
032            public DLFileVersion getFileVersion(long fileVersionId)
033                    throws PortalException, SystemException {
034    
035                    DLFileVersion fileVersion = dlFileVersionLocalService.getFileVersion(
036                            fileVersionId);
037    
038                    DLFileEntryPermission.check(
039                            getPermissionChecker(), fileVersion.getFileEntryId(),
040                            ActionKeys.VIEW);
041    
042                    return fileVersion;
043            }
044    
045            @Override
046            public List<DLFileVersion> getFileVersions(long fileEntryId, int status)
047                    throws PortalException, SystemException {
048    
049                    DLFileEntryPermission.check(
050                            getPermissionChecker(), fileEntryId, ActionKeys.VIEW);
051    
052                    return dlFileVersionLocalService.getFileVersions(fileEntryId, status);
053            }
054    
055            @Override
056            public int getFileVersionsCount(long fileEntryId, int status)
057                    throws PortalException, SystemException {
058    
059                    DLFileEntryPermission.check(
060                            getPermissionChecker(), fileEntryId, ActionKeys.VIEW);
061    
062                    return dlFileVersionPersistence.countByF_S(fileEntryId, status);
063            }
064    
065            @Override
066            public DLFileVersion getLatestFileVersion(long fileEntryId)
067                    throws PortalException, SystemException {
068    
069                    DLFileEntryPermission.check(
070                            getPermissionChecker(), fileEntryId, ActionKeys.VIEW);
071    
072                    return dlFileVersionLocalService.getLatestFileVersion(
073                            getGuestOrUserId(), fileEntryId);
074            }
075    
076    }