1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.documentlibrary.service.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
20  import com.liferay.portlet.documentlibrary.model.DLFileVersion;
21  import com.liferay.portlet.documentlibrary.service.base.DLFileVersionLocalServiceBaseImpl;
22  import com.liferay.portlet.documentlibrary.util.comparator.FileVersionVersionComparator;
23  
24  import java.util.List;
25  
26  /**
27   * <a href="DLFileVersionLocalServiceImpl.java.html"><b><i>View Source</i></b>
28   * </a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class DLFileVersionLocalServiceImpl
33      extends DLFileVersionLocalServiceBaseImpl {
34  
35      public DLFileVersion getFileVersion(
36              long folderId, String name, double version)
37          throws PortalException, SystemException {
38  
39          return dlFileVersionPersistence.findByF_N_V(folderId, name, version);
40      }
41  
42      public List<DLFileVersion> getFileVersions(long folderId, String name)
43          throws SystemException {
44  
45          return dlFileVersionPersistence.findByF_N(folderId, name);
46      }
47  
48      public DLFileVersion getLatestFileVersion(long folderId, String name)
49          throws PortalException, SystemException {
50  
51          List<DLFileVersion> fileVersions = dlFileVersionPersistence.findByF_N(
52              folderId, name, 0, 1, new FileVersionVersionComparator());
53  
54          if (fileVersions.isEmpty()) {
55              throw new NoSuchFileVersionException();
56          }
57  
58          return fileVersions.get(0);
59      }
60  
61      public DLFileVersion updateDescription(
62              long fileVersionId, String description)
63          throws PortalException, SystemException {
64  
65          DLFileVersion fileVersion = dlFileVersionPersistence.findByPrimaryKey(
66              fileVersionId);
67  
68          fileVersion.setDescription(description);
69  
70          dlFileVersionPersistence.update(fileVersion, false);
71  
72          return fileVersion;
73      }
74  
75  }