001
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
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 }