001    /**
002     * Copyright (c) 2000-2010 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.kernel.workflow.WorkflowConstants;
020    import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
021    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
022    import com.liferay.portlet.documentlibrary.service.base.DLFileVersionLocalServiceBaseImpl;
023    import com.liferay.portlet.documentlibrary.util.comparator.FileVersionVersionComparator;
024    
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Bruno Farache
030     * @author Jorge Ferrer
031     */
032    public class DLFileVersionLocalServiceImpl
033            extends DLFileVersionLocalServiceBaseImpl {
034    
035            public DLFileVersion getFileVersion(long fileVersionId)
036                    throws PortalException, SystemException {
037    
038                    return dlFileVersionPersistence.findByPrimaryKey(fileVersionId);
039            }
040    
041            public DLFileVersion getFileVersion(
042                            long groupId, long folderId, String name, String version)
043                    throws PortalException, SystemException {
044    
045                    return dlFileVersionPersistence.findByG_F_N_V(
046                            groupId, folderId, name, version);
047            }
048    
049            public List<DLFileVersion> getFileVersions(
050                            long groupId, long folderId, String name, int status)
051                    throws SystemException {
052    
053                    if (status == WorkflowConstants.STATUS_ANY) {
054                            return dlFileVersionPersistence.findByG_F_N(
055                                    groupId, folderId, name);
056                    }
057                    else {
058                            return dlFileVersionPersistence.findByG_F_N_S(
059                                    groupId, folderId, name, status);
060                    }
061            }
062    
063            public DLFileVersion getLatestFileVersion(
064                            long groupId, long folderId, String name)
065                    throws PortalException, SystemException {
066    
067                    List<DLFileVersion> fileVersions = dlFileVersionPersistence.findByG_F_N(
068                            groupId, folderId, name, 0, 1, new FileVersionVersionComparator());
069    
070                    if (fileVersions.isEmpty()) {
071                            throw new NoSuchFileVersionException();
072                    }
073    
074                    return fileVersions.get(0);
075            }
076    
077            public DLFileVersion updateDescription(
078                            long fileVersionId, String description)
079                    throws PortalException, SystemException {
080    
081                    DLFileVersion fileVersion = dlFileVersionPersistence.findByPrimaryKey(
082                            fileVersionId);
083    
084                    fileVersion.setDescription(description);
085    
086                    dlFileVersionPersistence.update(fileVersion, false);
087    
088                    return fileVersion;
089            }
090    
091    }