1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.documentlibrary.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portal.kernel.workflow.StatusConstants;
20  import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
21  import com.liferay.portlet.documentlibrary.model.DLFileVersion;
22  import com.liferay.portlet.documentlibrary.service.base.DLFileVersionLocalServiceBaseImpl;
23  import com.liferay.portlet.documentlibrary.util.comparator.FileVersionVersionComparator;
24  
25  import java.util.List;
26  
27  /**
28   * <a href="DLFileVersionLocalServiceImpl.java.html"><b><i>View Source</i></b>
29   * </a>
30   *
31   * @author Brian Wing Shun Chan
32   * @author Bruno Farache
33   */
34  public class DLFileVersionLocalServiceImpl
35      extends DLFileVersionLocalServiceBaseImpl {
36  
37      public DLFileVersion getFileVersion(
38              long groupId, long folderId, String name, String version)
39          throws PortalException, SystemException {
40  
41          return dlFileVersionPersistence.findByG_F_N_V(
42              groupId, folderId, name, version);
43      }
44  
45      public List<DLFileVersion> getFileVersions(
46              long groupId, long folderId, String name, int status)
47          throws SystemException {
48  
49          if (status == StatusConstants.ANY) {
50              return dlFileVersionPersistence.findByG_F_N(
51                  groupId, folderId, name);
52          }
53          else {
54              return dlFileVersionPersistence.findByG_F_N_S(
55                  groupId, folderId, name, status);
56          }
57      }
58  
59      public DLFileVersion getLatestFileVersion(
60              long groupId, long folderId, String name)
61          throws PortalException, SystemException {
62  
63          List<DLFileVersion> fileVersions = dlFileVersionPersistence.findByG_F_N(
64              groupId, folderId, name, 0, 1, new FileVersionVersionComparator());
65  
66          if (fileVersions.isEmpty()) {
67              throw new NoSuchFileVersionException();
68          }
69  
70          return fileVersions.get(0);
71      }
72  
73      public DLFileVersion updateDescription(
74              long fileVersionId, String description)
75          throws PortalException, SystemException {
76  
77          DLFileVersion fileVersion = dlFileVersionPersistence.findByPrimaryKey(
78              fileVersionId);
79  
80          fileVersion.setDescription(description);
81  
82          dlFileVersionPersistence.update(fileVersion, false);
83  
84          return fileVersion;
85      }
86  
87  }