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.InvalidRepositoryException;
018    import com.liferay.portal.NoSuchGroupException;
019    import com.liferay.portal.kernel.dao.orm.QueryUtil;
020    import com.liferay.portal.kernel.exception.PortalException;
021    import com.liferay.portal.kernel.exception.SystemException;
022    import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
023    import com.liferay.portal.kernel.log.Log;
024    import com.liferay.portal.kernel.log.LogFactoryUtil;
025    import com.liferay.portal.kernel.repository.InvalidRepositoryIdException;
026    import com.liferay.portal.kernel.repository.Repository;
027    import com.liferay.portal.kernel.repository.RepositoryException;
028    import com.liferay.portal.kernel.repository.model.FileEntry;
029    import com.liferay.portal.kernel.repository.model.FileVersion;
030    import com.liferay.portal.kernel.repository.model.Folder;
031    import com.liferay.portal.kernel.search.Hits;
032    import com.liferay.portal.kernel.search.Query;
033    import com.liferay.portal.kernel.search.SearchContext;
034    import com.liferay.portal.kernel.search.SearchException;
035    import com.liferay.portal.kernel.transaction.TransactionCommitCallbackRegistryUtil;
036    import com.liferay.portal.kernel.util.ArrayUtil;
037    import com.liferay.portal.kernel.util.ContentTypes;
038    import com.liferay.portal.kernel.util.FileUtil;
039    import com.liferay.portal.kernel.util.GetterUtil;
040    import com.liferay.portal.kernel.util.MimeTypesUtil;
041    import com.liferay.portal.kernel.util.OrderByComparator;
042    import com.liferay.portal.kernel.util.StringBundler;
043    import com.liferay.portal.kernel.util.StringPool;
044    import com.liferay.portal.kernel.util.TempFileUtil;
045    import com.liferay.portal.kernel.util.Validator;
046    import com.liferay.portal.kernel.workflow.WorkflowConstants;
047    import com.liferay.portal.model.Lock;
048    import com.liferay.portal.repository.liferayrepository.LiferayRepository;
049    import com.liferay.portal.security.permission.ActionKeys;
050    import com.liferay.portal.service.ServiceContext;
051    import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
052    import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
053    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
054    import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
055    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
056    import com.liferay.portlet.documentlibrary.service.base.DLAppServiceBaseImpl;
057    import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
058    import com.liferay.portlet.documentlibrary.service.permission.DLFileShortcutPermission;
059    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
060    import com.liferay.portlet.documentlibrary.service.permission.DLPermission;
061    import com.liferay.portlet.documentlibrary.util.DLAppUtil;
062    import com.liferay.portlet.documentlibrary.util.DLProcessorRegistryUtil;
063    import com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelModifiedDateComparator;
064    
065    import java.io.File;
066    import java.io.IOException;
067    import java.io.InputStream;
068    
069    import java.util.ArrayList;
070    import java.util.LinkedList;
071    import java.util.List;
072    import java.util.Queue;
073    import java.util.concurrent.Callable;
074    
075    /**
076     * Provides the remote service for accessing, adding, checking in/out, deleting,
077     * locking/unlocking, moving, subscription handling of, trash handling of,
078     * updating, and verifying document library file entries and folders. Its
079     * methods include permission checks. All portlets should interact with the
080     * document library through this class or through DLAppLocalService, rather than
081     * through the individual document library service classes.
082     *
083     * <p>
084     * This class provides a unified interface to all Liferay and third party
085     * repositories. While the method signatures are universal for all repositories.
086     * Additional implementation-specific parameters may be specified in the
087     * serviceContext.
088     * </p>
089     *
090     * <p>
091     * The <code>repositoryId</code> parameter used by most of the methods is the
092     * primary key of the specific repository. If the repository is a default
093     * Liferay repository, the <code>repositoryId</code> is the <code>groupId</code>
094     * or <code>scopeGroupId</code>. Otherwise, the <code>repositoryId</code> will
095     * correspond to values obtained from {@link
096     * com.liferay.portal.service.RepositoryServiceUtil}.
097     * </p>
098     *
099     * @author Alexander Chow
100     * @author Mika Koivisto
101     * @author Shuyang Zhou
102     * @see    DLAppLocalServiceImpl
103     */
104    public class DLAppServiceImpl extends DLAppServiceBaseImpl {
105    
106            /**
107             * Adds a file entry and associated metadata. It is created based on a byte
108             * array.
109             *
110             * <p>
111             * This method takes two file names, the <code>sourceFileName</code> and the
112             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
113             * name of the actual file being uploaded. The <code>title</code>
114             * corresponds to a name the client wishes to assign this file after it has
115             * been uploaded to the portal. If it is <code>null</code>, the <code>
116             * sourceFileName</code> will be used.
117             * </p>
118             *
119             * @param  repositoryId the primary key of the repository
120             * @param  folderId the primary key of the file entry's parent folder
121             * @param  sourceFileName the original file's name
122             * @param  mimeType the file's MIME type
123             * @param  title the name to be assigned to the file (optionally <code>null
124             *         </code>)
125             * @param  description the file's description
126             * @param  changeLog the file's version change log
127             * @param  bytes the file's data (optionally <code>null</code>)
128             * @param  serviceContext the service context to be applied. Can set the
129             *         asset category IDs, asset tag names, and expando bridge
130             *         attributes for the file entry. In a Liferay repository, it may
131             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
132             *         type </li> <li> fieldsMap - mapping for fields associated with a
133             *         custom file entry type </li> </ul>
134             * @return the file entry
135             * @throws PortalException if the parent folder could not be found or if the
136             *         file entry's information was invalid
137             * @throws SystemException if a system exception occurred
138             */
139            @Override
140            public FileEntry addFileEntry(
141                            long repositoryId, long folderId, String sourceFileName,
142                            String mimeType, String title, String description, String changeLog,
143                            byte[] bytes, ServiceContext serviceContext)
144                    throws PortalException, SystemException {
145    
146                    File file = null;
147    
148                    try {
149                            if (ArrayUtil.isNotEmpty(bytes)) {
150                                    file = FileUtil.createTempFile(bytes);
151                            }
152    
153                            return addFileEntry(
154                                    repositoryId, folderId, sourceFileName, mimeType, title,
155                                    description, changeLog, file, serviceContext);
156                    }
157                    catch (IOException ioe) {
158                            throw new SystemException("Unable to write temporary file", ioe);
159                    }
160                    finally {
161                            FileUtil.delete(file);
162                    }
163            }
164    
165            /**
166             * Adds a file entry and associated metadata. It is created based on a
167             * {@link java.io.File} object.
168             *
169             * <p>
170             * This method takes two file names, the <code>sourceFileName</code> and the
171             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
172             * name of the actual file being uploaded. The <code>title</code>
173             * corresponds to a name the client wishes to assign this file after it has
174             * been uploaded to the portal. If it is <code>null</code>, the <code>
175             * sourceFileName</code> will be used.
176             * </p>
177             *
178             * @param  repositoryId the primary key of the repository
179             * @param  folderId the primary key of the file entry's parent folder
180             * @param  sourceFileName the original file's name
181             * @param  mimeType the file's MIME type
182             * @param  title the name to be assigned to the file (optionally <code>null
183             *         </code>)
184             * @param  description the file's description
185             * @param  changeLog the file's version change log
186             * @param  file the file's data (optionally <code>null</code>)
187             * @param  serviceContext the service context to be applied. Can set the
188             *         asset category IDs, asset tag names, and expando bridge
189             *         attributes for the file entry. In a Liferay repository, it may
190             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
191             *         type </li> <li> fieldsMap - mapping for fields associated with a
192             *         custom file entry type </li> </ul>
193             * @return the file entry
194             * @throws PortalException if the parent folder could not be found or if the
195             *         file entry's information was invalid
196             * @throws SystemException if a system exception occurred
197             */
198            @Override
199            public FileEntry addFileEntry(
200                            long repositoryId, long folderId, String sourceFileName,
201                            String mimeType, String title, String description, String changeLog,
202                            File file, ServiceContext serviceContext)
203                    throws PortalException, SystemException {
204    
205                    if ((file == null) || !file.exists() || (file.length() == 0)) {
206                            return addFileEntry(
207                                    repositoryId, folderId, sourceFileName, mimeType, title,
208                                    description, changeLog, null, 0, serviceContext);
209                    }
210    
211                    mimeType = DLAppUtil.getMimeType(sourceFileName, mimeType, title, file);
212    
213                    Repository repository = getRepository(repositoryId);
214    
215                    FileEntry fileEntry = repository.addFileEntry(
216                            folderId, sourceFileName, mimeType, title, description, changeLog,
217                            file, serviceContext);
218    
219                    dlAppHelperLocalService.addFileEntry(
220                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
221    
222                    return fileEntry;
223            }
224    
225            /**
226             * Adds a file entry and associated metadata. It is created based on a
227             * {@link java.io.InputStream} object.
228             *
229             * <p>
230             * This method takes two file names, the <code>sourceFileName</code> and the
231             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
232             * name of the actual file being uploaded. The <code>title</code>
233             * corresponds to a name the client wishes to assign this file after it has
234             * been uploaded to the portal. If it is <code>null</code>, the <code>
235             * sourceFileName</code> will be used.
236             * </p>
237             *
238             * @param  repositoryId the primary key of the repository
239             * @param  folderId the primary key of the file entry's parent folder
240             * @param  sourceFileName the original file's name
241             * @param  mimeType the file's MIME type
242             * @param  title the name to be assigned to the file (optionally <code>null
243             *         </code>)
244             * @param  description the file's description
245             * @param  changeLog the file's version change log
246             * @param  is the file's data (optionally <code>null</code>)
247             * @param  size the file's size (optionally <code>0</code>)
248             * @param  serviceContext the service context to be applied. Can set the
249             *         asset category IDs, asset tag names, and expando bridge
250             *         attributes for the file entry. In a Liferay repository, it may
251             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
252             *         type </li> <li> fieldsMap - mapping for fields associated with a
253             *         custom file entry type </li> </ul>
254             * @return the file entry
255             * @throws PortalException if the parent folder could not be found or if the
256             *         file entry's information was invalid
257             * @throws SystemException if a system exception occurred
258             */
259            @Override
260            public FileEntry addFileEntry(
261                            long repositoryId, long folderId, String sourceFileName,
262                            String mimeType, String title, String description, String changeLog,
263                            InputStream is, long size, ServiceContext serviceContext)
264                    throws PortalException, SystemException {
265    
266                    if (is == null) {
267                            is = new UnsyncByteArrayInputStream(new byte[0]);
268                            size = 0;
269                    }
270    
271                    if (Validator.isNull(mimeType) ||
272                            mimeType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) {
273    
274                            String extension = DLAppUtil.getExtension(title, sourceFileName);
275    
276                            if (size == 0) {
277                                    mimeType = MimeTypesUtil.getExtensionContentType(extension);
278                            }
279                            else {
280                                    File file = null;
281    
282                                    try {
283                                            file = FileUtil.createTempFile(is);
284    
285                                            return addFileEntry(
286                                                    repositoryId, folderId, sourceFileName, mimeType, title,
287                                                    description, changeLog, file, serviceContext);
288                                    }
289                                    catch (IOException ioe) {
290                                            throw new SystemException(
291                                                    "Unable to write temporary file", ioe);
292                                    }
293                                    finally {
294                                            FileUtil.delete(file);
295                                    }
296                            }
297                    }
298    
299                    Repository repository = getRepository(repositoryId);
300    
301                    FileEntry fileEntry = repository.addFileEntry(
302                            folderId, sourceFileName, mimeType, title, description, changeLog,
303                            is, size, serviceContext);
304    
305                    dlAppHelperLocalService.addFileEntry(
306                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
307    
308                    return fileEntry;
309            }
310    
311            /**
312             * Adds a file shortcut to the existing file entry. This method is only
313             * supported by the Liferay repository.
314             *
315             * @param  repositoryId the primary key of the repository
316             * @param  folderId the primary key of the file shortcut's parent folder
317             * @param  toFileEntryId the primary key of the file shortcut's file entry
318             * @param  serviceContext the service context to be applied. Can set the
319             *         asset category IDs, asset tag names, and expando bridge
320             *         attributes for the file entry.
321             * @return the file shortcut
322             * @throws PortalException if the parent folder or file entry could not be
323             *         found, or if the file shortcut's information was invalid
324             * @throws SystemException if a system exception occurred
325             */
326            @Override
327            public DLFileShortcut addFileShortcut(
328                            long repositoryId, long folderId, long toFileEntryId,
329                            ServiceContext serviceContext)
330                    throws PortalException, SystemException {
331    
332                    return dlFileShortcutService.addFileShortcut(
333                            repositoryId, folderId, toFileEntryId, serviceContext);
334            }
335    
336            /**
337             * Adds a folder.
338             *
339             * @param  repositoryId the primary key of the repository
340             * @param  parentFolderId the primary key of the folder's parent folder
341             * @param  name the folder's name
342             * @param  description the folder's description
343             * @param  serviceContext the service context to be applied. In a Liferay
344             *         repository, it may include boolean mountPoint specifying whether
345             *         folder is a facade for mounting a third-party repository
346             * @return the folder
347             * @throws PortalException if the parent folder could not be found or if the
348             *         new folder's information was invalid
349             * @throws SystemException if a system exception occurred
350             */
351            @Override
352            public Folder addFolder(
353                            long repositoryId, long parentFolderId, String name,
354                            String description, ServiceContext serviceContext)
355                    throws PortalException, SystemException {
356    
357                    Repository repository = getRepository(repositoryId);
358    
359                    return repository.addFolder(
360                            parentFolderId, name, description, serviceContext);
361            }
362    
363            /**
364             * Adds a temporary file entry.
365             *
366             * <p>
367             * This allows a client to upload a file into a temporary location and
368             * manipulate its metadata prior to making it available for public usage.
369             * This is different from checking in and checking out a file entry.
370             * </p>
371             *
372             * @param  groupId the primary key of the group
373             * @param  folderId the primary key of the folder where the file entry will
374             *         eventually reside
375             * @param  fileName the file's original name
376             * @param  tempFolderName the temporary folder's name
377             * @param  file Name the file's original name
378             * @param  mimeType the file's MIME type
379             * @return the file's name
380             * @throws PortalException if the file name was invalid
381             * @throws SystemException if a system exception occurred
382             * @see    com.liferay.portal.kernel.util.TempFileUtil
383             */
384            @Override
385            public FileEntry addTempFileEntry(
386                            long groupId, long folderId, String fileName, String tempFolderName,
387                            File file, String mimeType)
388                    throws PortalException, SystemException {
389    
390                    DLFolderPermission.check(
391                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
392    
393                    return TempFileUtil.addTempFile(
394                            groupId, getUserId(), fileName, tempFolderName, file, mimeType);
395            }
396    
397            @Override
398            public FileEntry addTempFileEntry(
399                            long groupId, long folderId, String fileName, String tempFolderName,
400                            InputStream inputStream, String mimeType)
401                    throws PortalException, SystemException {
402    
403                    DLFolderPermission.check(
404                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
405    
406                    return TempFileUtil.addTempFile(
407                            groupId, getUserId(), fileName, tempFolderName, inputStream,
408                            mimeType);
409            }
410    
411            /**
412             * Cancels the check out of the file entry. If a user has not checked out
413             * the specified file entry, invoking this method will result in no changes.
414             *
415             * <p>
416             * When a file entry is checked out, a PWC (private working copy) is created
417             * and the original file entry is locked. A client can make as many changes
418             * to the PWC as he desires without those changes being visible to other
419             * users. If the user is satisfied with the changes, he may elect to check
420             * in his changes, resulting in a new file version based on the PWC; the PWC
421             * will be removed and the file entry will be unlocked. If the user is not
422             * satisfied with the changes, he may elect to cancel his check out; this
423             * results in the deletion of the PWC and unlocking of the file entry.
424             * </p>
425             *
426             * @param  fileEntryId the primary key of the file entry to cancel the
427             *         checkout
428             * @throws PortalException if the file entry could not be found
429             * @throws SystemException if a system exception occurred
430             * @see    #checkInFileEntry(long, boolean, String, ServiceContext)
431             * @see    #checkOutFileEntry(long, ServiceContext)
432             */
433            @Override
434            public void cancelCheckOut(long fileEntryId)
435                    throws PortalException, SystemException {
436    
437                    Repository repository = getFileEntryRepository(fileEntryId);
438    
439                    FileEntry fileEntry = repository.getFileEntry(fileEntryId);
440    
441                    DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
442    
443                    FileVersion draftFileVersion = repository.cancelCheckOut(fileEntryId);
444    
445                    ServiceContext serviceContext = new ServiceContext();
446    
447                    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
448    
449                    dlAppHelperLocalService.cancelCheckOut(
450                            getUserId(), fileEntry, null, fileEntry.getFileVersion(),
451                            draftFileVersion, serviceContext);
452            }
453    
454            /**
455             * Checks in the file entry. If a user has not checked out the specified
456             * file entry, invoking this method will result in no changes.
457             *
458             * <p>
459             * When a file entry is checked out, a PWC (private working copy) is created
460             * and the original file entry is locked. A client can make as many changes
461             * to the PWC as he desires without those changes being visible to other
462             * users. If the user is satisfied with the changes, he may elect to check
463             * in his changes, resulting in a new file version based on the PWC; the PWC
464             * will be removed and the file entry will be unlocked. If the user is not
465             * satisfied with the changes, he may elect to cancel his check out; this
466             * results in the deletion of the PWC and unlocking of the file entry.
467             * </p>
468             *
469             * @param  fileEntryId the primary key of the file entry to check in
470             * @param  majorVersion whether the new file version is a major version
471             * @param  changeLog the file's version change log
472             * @param  serviceContext the service context to be applied
473             * @throws PortalException if the file entry could not be found
474             * @throws SystemException if a system exception occurred
475             * @see    #cancelCheckOut(long)
476             * @see    #checkOutFileEntry(long, ServiceContext)
477             */
478            @Override
479            public void checkInFileEntry(
480                            long fileEntryId, boolean majorVersion, String changeLog,
481                            ServiceContext serviceContext)
482                    throws PortalException, SystemException {
483    
484                    Repository repository = getFileEntryRepository(fileEntryId);
485    
486                    FileEntry oldFileEntry = repository.getFileEntry(fileEntryId);
487    
488                    FileVersion oldFileVersion = oldFileEntry.getFileVersion();
489    
490                    repository.checkInFileEntry(
491                            fileEntryId, majorVersion, changeLog, serviceContext);
492    
493                    FileEntry fileEntry = getFileEntry(fileEntryId);
494    
495                    FileVersion fileVersion = fileEntry.getLatestFileVersion();
496    
497                    dlAppHelperLocalService.updateFileEntry(
498                            getUserId(), fileEntry, oldFileVersion, fileVersion,
499                            fileVersion.getFileVersionId());
500            }
501    
502            /**
503             * @deprecated As of 6.2.0, replaced by {@link #checkInFileEntry(long,
504             *             String, ServiceContext)}
505             */
506            @Override
507            public void checkInFileEntry(long fileEntryId, String lockUuid)
508                    throws PortalException, SystemException {
509    
510                    checkInFileEntry(fileEntryId, lockUuid, new ServiceContext());
511            }
512    
513            /**
514             * Checks in the file entry using the lock's UUID. If a user has not checked
515             * out the specified file entry, invoking this method will result in no
516             * changes. This method is primarily used by WebDAV.
517             *
518             * <p>
519             * When a file entry is checked out, a PWC (private working copy) is created
520             * and the original file entry is locked. A client can make as many changes
521             * to the PWC as he desires without those changes being visible to other
522             * users. If the user is satisfied with the changes, he may elect to check
523             * in his changes, resulting in a new file version based on the PWC; the PWC
524             * will be removed and the file entry will be unlocked. If the user is not
525             * satisfied with the changes, he may elect to cancel his check out; this
526             * results in the deletion of the PWC and unlocking of the file entry.
527             * </p>
528             *
529             * @param  fileEntryId the primary key of the file entry to check in
530             * @param  lockUuid the lock's UUID
531             * @param  serviceContext the service context to be applied
532             * @throws PortalException if the file entry could not be found
533             * @throws SystemException if a system exception occurred
534             * @see    #cancelCheckOut(long)
535             * @see    #checkOutFileEntry(long, String, long, ServiceContext)
536             */
537            @Override
538            public void checkInFileEntry(
539                            long fileEntryId, String lockUuid, ServiceContext serviceContext)
540                    throws PortalException, SystemException {
541    
542                    Repository repository = getFileEntryRepository(fileEntryId);
543    
544                    FileEntry oldFileEntry = repository.getFileEntry(fileEntryId);
545    
546                    FileVersion oldFileVersion = oldFileEntry.getFileVersion();
547    
548                    repository.checkInFileEntry(fileEntryId, lockUuid, serviceContext);
549    
550                    FileEntry fileEntry = getFileEntry(fileEntryId);
551    
552                    FileVersion fileVersion = fileEntry.getLatestFileVersion();
553    
554                    dlAppHelperLocalService.updateFileEntry(
555                            getUserId(), fileEntry, oldFileVersion, fileVersion,
556                            fileVersion.getFileVersionId());
557            }
558    
559            /**
560             * Check out a file entry.
561             *
562             * <p>
563             * When a file entry is checked out, a PWC (private working copy) is created
564             * and the original file entry is locked. A client can make as many changes
565             * to the PWC as he desires without those changes being visible to other
566             * users. If the user is satisfied with the changes, he may elect to check
567             * in his changes, resulting in a new file version based on the PWC; the PWC
568             * will be removed and the file entry will be unlocked. If the user is not
569             * satisfied with the changes, he may elect to cancel his check out; this
570             * results in the deletion of the PWC and unlocking of the file entry.
571             * </p>
572             *
573             * @param  fileEntryId the file entry to check out
574             * @param  serviceContext the service context to be applied
575             * @throws PortalException if the file entry could not be found
576             * @throws SystemException if a system exception occurred
577             * @see    #cancelCheckOut(long)
578             * @see    #checkInFileEntry(long, boolean, String, ServiceContext)
579             */
580            @Override
581            public void checkOutFileEntry(
582                            long fileEntryId, ServiceContext serviceContext)
583                    throws PortalException, SystemException {
584    
585                    Repository repository = getFileEntryRepository(fileEntryId);
586    
587                    FileEntry oldFileEntry = repository.getFileEntry(fileEntryId);
588    
589                    FileVersion oldFileVersion = oldFileEntry.getFileVersion();
590    
591                    FileEntry fileEntry = repository.checkOutFileEntry(
592                            fileEntryId, serviceContext);
593    
594                    FileVersion fileVersion = fileEntry.getLatestFileVersion();
595    
596                    dlAppHelperLocalService.updateFileEntry(
597                            getUserId(), fileEntry, oldFileVersion, fileVersion, fileEntryId);
598            }
599    
600            /**
601             * Checks out the file entry. This method is primarily used by WebDAV.
602             *
603             * <p>
604             * When a file entry is checked out, a PWC (private working copy) is created
605             * and the original file entry is locked. A client can make as many changes
606             * to the PWC as he desires without those changes being visible to other
607             * users. If the user is satisfied with the changes, he may elect to check
608             * in his changes, resulting in a new file version based on the PWC; the PWC
609             * will be removed and the file entry will be unlocked. If the user is not
610             * satisfied with the changes, he may elect to cancel his check out; this
611             * results in the deletion of the PWC and unlocking of the file entry.
612             * </p>
613             *
614             * @param  fileEntryId the file entry to check out
615             * @param  owner the owner string for the checkout (optionally
616             *         <code>null</code>)
617             * @param  expirationTime the time in milliseconds before the lock expires.
618             *         If the value is <code>0</code>, the default expiration time will
619             *         be used from <code>portal.properties>.
620             * @param  serviceContext the service context to be applied
621             * @return the file entry
622             * @throws PortalException if the file entry could not be found
623             * @throws SystemException if a system exception occurred
624             * @see    #cancelCheckOut(long)
625             * @see    #checkInFileEntry(long, String)
626             */
627            @Override
628            public FileEntry checkOutFileEntry(
629                            long fileEntryId, String owner, long expirationTime,
630                            ServiceContext serviceContext)
631                    throws PortalException, SystemException {
632    
633                    Repository repository = getFileEntryRepository(fileEntryId);
634    
635                    FileEntry oldFileEntry = repository.getFileEntry(fileEntryId);
636    
637                    FileVersion oldFileVersion = oldFileEntry.getFileVersion();
638    
639                    FileEntry fileEntry = repository.checkOutFileEntry(
640                            fileEntryId, owner, expirationTime, serviceContext);
641    
642                    FileVersion fileVersion = fileEntry.getLatestFileVersion();
643    
644                    dlAppHelperLocalService.updateFileEntry(
645                            getUserId(), fileEntry, oldFileVersion, fileVersion, fileEntryId);
646    
647                    return fileEntry;
648            }
649    
650            /**
651             * Performs a deep copy of the folder.
652             *
653             * @param  repositoryId the primary key of the repository
654             * @param  sourceFolderId the primary key of the folder to copy
655             * @param  parentFolderId the primary key of the new folder's parent folder
656             * @param  name the new folder's name
657             * @param  description the new folder's description
658             * @param  serviceContext the service context to be applied
659             * @return the folder
660             * @throws PortalException if the source folder or the new parent folder
661             *         could not be found or if the new folder's information was invalid
662             * @throws SystemException if a system exception occurred
663             */
664            @Override
665            public Folder copyFolder(
666                            long repositoryId, long sourceFolderId, long parentFolderId,
667                            String name, String description, ServiceContext serviceContext)
668                    throws PortalException, SystemException {
669    
670                    Repository repository = getRepository(repositoryId);
671    
672                    Folder srcFolder = repository.getFolder(sourceFolderId);
673    
674                    Folder destFolder = repository.addFolder(
675                            parentFolderId, name, description, serviceContext);
676    
677                    copyFolder(repository, srcFolder, destFolder, serviceContext);
678    
679                    return destFolder;
680            }
681    
682            /**
683             * Deletes the file entry with the primary key.
684             *
685             * @param  fileEntryId the primary key of the file entry
686             * @throws PortalException if the file entry could not be found
687             * @throws SystemException if a system exception occurred
688             */
689            @Override
690            public void deleteFileEntry(long fileEntryId)
691                    throws PortalException, SystemException {
692    
693                    Repository repository = getFileEntryRepository(fileEntryId);
694    
695                    FileEntry fileEntry = repository.getFileEntry(fileEntryId);
696    
697                    dlAppHelperLocalService.deleteFileEntry(fileEntry);
698    
699                    repository.deleteFileEntry(fileEntryId);
700            }
701    
702            /**
703             * Deletes the file entry with the title in the folder.
704             *
705             * @param  repositoryId the primary key of the repository
706             * @param  folderId the primary key of the file entry's parent folder
707             * @param  title the file entry's title
708             * @throws PortalException if the file entry could not be found
709             * @throws SystemException if a system exception occurred
710             */
711            @Override
712            public void deleteFileEntryByTitle(
713                            long repositoryId, long folderId, String title)
714                    throws PortalException, SystemException {
715    
716                    Repository repository = getRepository(repositoryId);
717    
718                    FileEntry fileEntry = repository.getFileEntry(folderId, title);
719    
720                    dlAppHelperLocalService.deleteFileEntry(fileEntry);
721    
722                    repository.deleteFileEntry(folderId, title);
723            }
724    
725            /**
726             * Deletes the file shortcut with the primary key. This method is only
727             * supported by the Liferay repository.
728             *
729             * @param  fileShortcutId the primary key of the file shortcut
730             * @throws PortalException if the file shortcut could not be found
731             * @throws SystemException if a system exception occurred
732             */
733            @Override
734            public void deleteFileShortcut(long fileShortcutId)
735                    throws PortalException, SystemException {
736    
737                    dlFileShortcutService.deleteFileShortcut(fileShortcutId);
738            }
739    
740            /**
741             * Deletes the file version. File versions can only be deleted if it is
742             * approved and there are other approved file versions available. This
743             * method is only supported by the Liferay repository.
744             *
745             * @param  fileEntryId the primary key of the file entry
746             * @param  version the version label of the file version
747             * @throws PortalException if the file version could not be found or invalid
748             * @throws SystemException if a system exception occurred
749             */
750            @Override
751            public void deleteFileVersion(long fileEntryId, String version)
752                    throws PortalException, SystemException {
753    
754                    Repository repository = getFileEntryRepository(fileEntryId);
755    
756                    repository.deleteFileVersion(fileEntryId, version);
757            }
758    
759            /**
760             * Deletes the folder with the primary key and all of its subfolders and
761             * file entries.
762             *
763             * @param  folderId the primary key of the folder
764             * @throws PortalException if the folder could not be found
765             * @throws SystemException if a system exception occurred
766             */
767            @Override
768            public void deleteFolder(long folderId)
769                    throws PortalException, SystemException {
770    
771                    Repository repository = getFolderRepository(folderId);
772    
773                    repository.deleteFolder(folderId);
774            }
775    
776            /**
777             * Deletes the folder with the name in the parent folder and all of its
778             * subfolders and file entries.
779             *
780             * @param  repositoryId the primary key of the repository
781             * @param  parentFolderId the primary key of the folder's parent folder
782             * @param  name the folder's name
783             * @throws PortalException if the folder could not be found
784             * @throws SystemException if a system exception occurred
785             */
786            @Override
787            public void deleteFolder(
788                            long repositoryId, long parentFolderId, String name)
789                    throws PortalException, SystemException {
790    
791                    Repository repository = getRepository(repositoryId);
792    
793                    repository.deleteFolder(parentFolderId, name);
794            }
795    
796            /**
797             * Deletes the temporary file entry.
798             *
799             * @param  groupId the primary key of the group
800             * @param  folderId the primary key of the folder where the file entry was
801             *         eventually to reside
802             * @param  fileName the file's original name
803             * @param  tempFolderName the temporary folder's name
804             * @throws PortalException if the file name was invalid
805             * @throws SystemException if a system exception occurred
806             * @see    com.liferay.portal.kernel.util.TempFileUtil
807             */
808            @Override
809            public void deleteTempFileEntry(
810                            long groupId, long folderId, String fileName, String tempFolderName)
811                    throws PortalException, SystemException {
812    
813                    DLFolderPermission.check(
814                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
815    
816                    TempFileUtil.deleteTempFile(
817                            groupId, getUserId(), fileName, tempFolderName);
818            }
819    
820            /**
821             * Returns all the file entries in the folder.
822             *
823             * @param  repositoryId the primary key of the file entry's repository
824             * @param  folderId the primary key of the file entry's folder
825             * @return the file entries in the folder
826             * @throws PortalException if the folder could not be found
827             * @throws SystemException if a system exception occurred
828             */
829            @Override
830            public List<FileEntry> getFileEntries(long repositoryId, long folderId)
831                    throws PortalException, SystemException {
832    
833                    return getFileEntries(
834                            repositoryId, folderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
835            }
836    
837            /**
838             * Returns a range of all the file entries in the folder.
839             *
840             * <p>
841             * Useful when paginating results. Returns a maximum of <code>end -
842             * start</code> instances. <code>start</code> and <code>end</code> are not
843             * primary keys, they are indexes in the result set. Thus, <code>0</code>
844             * refers to the first result in the set. Setting both <code>start</code>
845             * and <code>end</code> to {@link
846             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
847             * result set.
848             * </p>
849             *
850             * @param  repositoryId the primary key of the file entry's repository
851             * @param  folderId the primary key of the file entry's folder
852             * @param  start the lower bound of the range of results
853             * @param  end the upper bound of the range of results (not inclusive)
854             * @return the range of file entries in the folder
855             * @throws PortalException if the folder could not be found
856             * @throws SystemException if a system exception occurred
857             */
858            @Override
859            public List<FileEntry> getFileEntries(
860                            long repositoryId, long folderId, int start, int end)
861                    throws PortalException, SystemException {
862    
863                    return getFileEntries(repositoryId, folderId, start, end, null);
864            }
865    
866            /**
867             * Returns an ordered range of all the file entries in the folder.
868             *
869             * <p>
870             * Useful when paginating results. Returns a maximum of <code>end -
871             * start</code> instances. <code>start</code> and <code>end</code> are not
872             * primary keys, they are indexes in the result set. Thus, <code>0</code>
873             * refers to the first result in the set. Setting both <code>start</code>
874             * and <code>end</code> to {@link
875             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
876             * result set.
877             * </p>
878             *
879             * @param  repositoryId the primary key of the file entry's repository
880             * @param  folderId the primary key of the file entry's folder
881             * @param  start the lower bound of the range of results
882             * @param  end the upper bound of the range of results (not inclusive)
883             * @param  obc the comparator to order the file entries (optionally
884             *         <code>null</code>)
885             * @return the range of file entries in the folder ordered by comparator
886             *         <code>obc</code>
887             * @throws PortalException if the folder could not be found
888             * @throws SystemException if a system exception occurred
889             */
890            @Override
891            public List<FileEntry> getFileEntries(
892                            long repositoryId, long folderId, int start, int end,
893                            OrderByComparator obc)
894                    throws PortalException, SystemException {
895    
896                    Repository repository = getRepository(repositoryId);
897    
898                    return repository.getFileEntries(folderId, start, end, obc);
899            }
900    
901            /**
902             * Returns the file entries with the file entry type in the folder.
903             *
904             * @param  repositoryId the primary key of the file entry's repository
905             * @param  folderId the primary key of the file entry's folder
906             * @param  fileEntryTypeId the primary key of the file entry type
907             * @return the file entries with the file entry type in the folder
908             * @throws PortalException if the folder could not be found
909             * @throws SystemException if a system exception occurred
910             */
911            @Override
912            public List<FileEntry> getFileEntries(
913                            long repositoryId, long folderId, long fileEntryTypeId)
914                    throws PortalException, SystemException {
915    
916                    return getFileEntries(
917                            repositoryId, folderId, fileEntryTypeId, QueryUtil.ALL_POS,
918                            QueryUtil.ALL_POS);
919            }
920    
921            /**
922             * Returns a range of all the file entries with the file entry type in the
923             * folder.
924             *
925             * @param  repositoryId the primary key of the file entry's repository
926             * @param  folderId the primary key of the file entry's folder
927             * @param  fileEntryTypeId the primary key of the file entry type
928             * @param  start the lower bound of the range of results
929             * @param  end the upper bound of the range of results (not inclusive)
930             * @return the file entries in the folder
931             * @throws PortalException if the folder could not be found
932             * @throws SystemException if a system exception occurred
933             */
934            @Override
935            public List<FileEntry> getFileEntries(
936                            long repositoryId, long folderId, long fileEntryTypeId, int start,
937                            int end)
938                    throws PortalException, SystemException {
939    
940                    return getFileEntries(
941                            repositoryId, folderId, fileEntryTypeId, start, end, null);
942            }
943    
944            /**
945             * Returns an ordered range of all the file entries with the file entry type
946             * in the folder.
947             *
948             * @param  repositoryId the primary key of the repository
949             * @param  folderId the primary key of the folder
950             * @param  fileEntryTypeId the primary key of the file entry type
951             * @param  start the lower bound of the range of results
952             * @param  end the upper bound of the range of results (not inclusive)
953             * @param  obc the comparator to order the results by (optionally
954             *         <code>null</code>)
955             * @return the range of file entries with the file entry type in the folder
956             *         ordered by <code>null</code>
957             * @throws PortalException if the folder could not be found
958             * @throws SystemException if a system exception occurred
959             */
960            @Override
961            public List<FileEntry> getFileEntries(
962                            long repositoryId, long folderId, long fileEntryTypeId, int start,
963                            int end, OrderByComparator obc)
964                    throws PortalException, SystemException {
965    
966                    Repository repository = getRepository(repositoryId);
967    
968                    return repository.getFileEntries(
969                            folderId, fileEntryTypeId, start, end, obc);
970            }
971    
972            @Override
973            public List<FileEntry> getFileEntries(
974                            long repositoryId, long folderId, String[] mimeTypes)
975                    throws PortalException, SystemException {
976    
977                    Repository repository = getRepository(repositoryId);
978    
979                    return repository.getFileEntries(
980                            folderId, mimeTypes, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
981            }
982    
983            /**
984             * Returns a range of all the file entries and shortcuts in the folder.
985             *
986             * <p>
987             * Useful when paginating results. Returns a maximum of <code>end -
988             * start</code> instances. <code>start</code> and <code>end</code> are not
989             * primary keys, they are indexes in the result set. Thus, <code>0</code>
990             * refers to the first result in the set. Setting both <code>start</code>
991             * and <code>end</code> to {@link
992             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
993             * result set.
994             * </p>
995             *
996             * @param  repositoryId the primary key of the repository
997             * @param  folderId the primary key of the folder
998             * @param  status the workflow status
999             * @param  start the lower bound of the range of results
1000             * @param  end the upper bound of the range of results (not inclusive)
1001             * @return the range of file entries and shortcuts in the folder
1002             * @throws PortalException if the folder could not be found
1003             * @throws SystemException if a system exception occurred
1004             */
1005            @Override
1006            public List<Object> getFileEntriesAndFileShortcuts(
1007                            long repositoryId, long folderId, int status, int start, int end)
1008                    throws PortalException, SystemException {
1009    
1010                    Repository repository = getRepository(repositoryId);
1011    
1012                    return repository.getFileEntriesAndFileShortcuts(
1013                            folderId, status, start, end);
1014            }
1015    
1016            /**
1017             * Returns the number of file entries and shortcuts in the folder.
1018             *
1019             * @param  repositoryId the primary key of the repository
1020             * @param  folderId the primary key of the folder
1021             * @param  status the workflow status
1022             * @return the number of file entries and shortcuts in the folder
1023             * @throws PortalException if the folder ould not be found
1024             * @throws SystemException if a system exception occurred
1025             */
1026            @Override
1027            public int getFileEntriesAndFileShortcutsCount(
1028                            long repositoryId, long folderId, int status)
1029                    throws PortalException, SystemException {
1030    
1031                    Repository repository = getRepository(repositoryId);
1032    
1033                    return repository.getFileEntriesAndFileShortcutsCount(folderId, status);
1034            }
1035    
1036            /**
1037             * Returns the number of file entries and shortcuts in the folder.
1038             *
1039             * @param  repositoryId the primary key of the repository
1040             * @param  folderId the primary key of the folder
1041             * @param  status the workflow status
1042             * @param  mimeTypes allowed media types
1043             * @return the number of file entries and shortcuts in the folder
1044             * @throws PortalException if the folder ould not be found
1045             * @throws SystemException if a system exception occurred
1046             */
1047            @Override
1048            public int getFileEntriesAndFileShortcutsCount(
1049                            long repositoryId, long folderId, int status, String[] mimeTypes)
1050                    throws PortalException, SystemException {
1051    
1052                    Repository repository = getRepository(repositoryId);
1053    
1054                    return repository.getFileEntriesAndFileShortcutsCount(
1055                            folderId, status, mimeTypes);
1056            }
1057    
1058            /**
1059             * Returns the number of file entries in the folder.
1060             *
1061             * @param  repositoryId the primary key of the file entry's repository
1062             * @param  folderId the primary key of the file entry's folder
1063             * @return the number of file entries in the folder
1064             * @throws PortalException if the folder could not be found
1065             * @throws SystemException if a system exception occurred
1066             */
1067            @Override
1068            public int getFileEntriesCount(long repositoryId, long folderId)
1069                    throws PortalException, SystemException {
1070    
1071                    Repository repository = getRepository(repositoryId);
1072    
1073                    return repository.getFileEntriesCount(folderId);
1074            }
1075    
1076            /**
1077             * Returns the number of file entries with the file entry type in the
1078             * folder.
1079             *
1080             * @param  repositoryId the primary key of the file entry's repository
1081             * @param  folderId the primary key of the file entry's folder
1082             * @param  fileEntryTypeId the primary key of the file entry type
1083             * @return the number of file entries with the file entry type in the folder
1084             * @throws PortalException if the folder could not be found
1085             * @throws SystemException if a system exception occurred
1086             */
1087            @Override
1088            public int getFileEntriesCount(
1089                            long repositoryId, long folderId, long fileEntryTypeId)
1090                    throws PortalException, SystemException {
1091    
1092                    Repository repository = getRepository(repositoryId);
1093    
1094                    return repository.getFileEntriesCount(folderId, fileEntryTypeId);
1095            }
1096    
1097            /**
1098             * Returns the file entry with the primary key.
1099             *
1100             * @param  fileEntryId the primary key of the file entry
1101             * @return the file entry with the primary key
1102             * @throws PortalException if the file entry could not be found
1103             * @throws SystemException if a system exception occurred
1104             */
1105            @Override
1106            public FileEntry getFileEntry(long fileEntryId)
1107                    throws PortalException, SystemException {
1108    
1109                    Repository repository = getFileEntryRepository(fileEntryId);
1110    
1111                    return repository.getFileEntry(fileEntryId);
1112            }
1113    
1114            /**
1115             * Returns the file entry with the title in the folder.
1116             *
1117             * @param  groupId the primary key of the file entry's group
1118             * @param  folderId the primary key of the file entry's folder
1119             * @param  title the file entry's title
1120             * @return the file entry with the title in the folder
1121             * @throws PortalException if the file entry could not be found
1122             * @throws SystemException if a system exception occurred
1123             */
1124            @Override
1125            public FileEntry getFileEntry(long groupId, long folderId, String title)
1126                    throws PortalException, SystemException {
1127    
1128                    try {
1129                            Repository repository = getRepository(groupId);
1130    
1131                            return repository.getFileEntry(folderId, title);
1132                    }
1133                    catch (NoSuchFileEntryException nsfee) {
1134                            if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
1135                                    Repository repository = getFolderRepository(folderId);
1136    
1137                                    return repository.getFileEntry(folderId, title);
1138                            }
1139                            else {
1140                                    throw nsfee;
1141                            }
1142                    }
1143            }
1144    
1145            /**
1146             * Returns the file entry with the UUID and group.
1147             *
1148             * @param  uuid the file entry's UUID
1149             * @param  groupId the primary key of the file entry's group
1150             * @return the file entry with the UUID and group
1151             * @throws PortalException if the file entry could not be found
1152             * @throws SystemException if a system exception occurred
1153             */
1154            @Override
1155            public FileEntry getFileEntryByUuidAndGroupId(String uuid, long groupId)
1156                    throws PortalException, SystemException {
1157    
1158                    try {
1159                            Repository repository = getRepository(groupId);
1160    
1161                            return repository.getFileEntryByUuid(uuid);
1162                    }
1163                    catch (NoSuchFileEntryException nsfee) {
1164                    }
1165                    catch (RepositoryException re) {
1166                            throw new NoSuchFileEntryException(re);
1167                    }
1168    
1169                    List<com.liferay.portal.model.Repository> repositories =
1170                            repositoryPersistence.findByGroupId(groupId);
1171    
1172                    for (int i = 0; i < repositories.size(); i++) {
1173                            try {
1174                                    long repositoryId = repositories.get(i).getRepositoryId();
1175    
1176                                    Repository repository = getRepository(repositoryId);
1177    
1178                                    return repository.getFileEntryByUuid(uuid);
1179                            }
1180                            catch (NoSuchFileEntryException nsfee) {
1181                            }
1182                    }
1183    
1184                    StringBundler msg = new StringBundler(6);
1185    
1186                    msg.append("No DLFileEntry exists with the key {");
1187                    msg.append("uuid=");
1188                    msg.append(uuid);
1189                    msg.append(", groupId=");
1190                    msg.append(groupId);
1191                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1192    
1193                    throw new NoSuchFileEntryException(msg.toString());
1194            }
1195    
1196            /**
1197             * Returns the file shortcut with the primary key. This method is only
1198             * supported by the Liferay repository.
1199             *
1200             * @param  fileShortcutId the primary key of the file shortcut
1201             * @return the file shortcut with the primary key
1202             * @throws PortalException if the file shortcut could not be found
1203             * @throws SystemException if a system exception occurred
1204             */
1205            @Override
1206            public DLFileShortcut getFileShortcut(long fileShortcutId)
1207                    throws PortalException, SystemException {
1208    
1209                    return dlFileShortcutService.getFileShortcut(fileShortcutId);
1210            }
1211    
1212            /**
1213             * Returns the folder with the primary key.
1214             *
1215             * @param  folderId the primary key of the folder
1216             * @return the folder with the primary key
1217             * @throws PortalException if the folder could not be found
1218             * @throws SystemException if a system exception occurred
1219             */
1220            @Override
1221            public Folder getFolder(long folderId)
1222                    throws PortalException, SystemException {
1223    
1224                    Repository repository = getFolderRepository(folderId);
1225    
1226                    return repository.getFolder(folderId);
1227            }
1228    
1229            /**
1230             * Returns the folder with the name in the parent folder.
1231             *
1232             * @param  repositoryId the primary key of the folder's repository
1233             * @param  parentFolderId the primary key of the folder's parent folder
1234             * @param  name the folder's name
1235             * @return the folder with the name in the parent folder
1236             * @throws PortalException if the folder could not be found
1237             * @throws SystemException if a system exception occurred
1238             */
1239            @Override
1240            public Folder getFolder(long repositoryId, long parentFolderId, String name)
1241                    throws PortalException, SystemException {
1242    
1243                    Repository repository = getRepository(repositoryId);
1244    
1245                    return repository.getFolder(parentFolderId, name);
1246            }
1247    
1248            /**
1249             * Returns all immediate subfolders of the parent folder.
1250             *
1251             * @param  repositoryId the primary key of the folder's repository
1252             * @param  parentFolderId the primary key of the folder's parent folder
1253             * @return the immediate subfolders of the parent folder
1254             * @throws PortalException if the parent folder could not be found
1255             * @throws SystemException if a system exception occurred
1256             */
1257            @Override
1258            public List<Folder> getFolders(long repositoryId, long parentFolderId)
1259                    throws PortalException, SystemException {
1260    
1261                    return getFolders(
1262                            repositoryId, parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1263            }
1264    
1265            /**
1266             * Returns all immediate subfolders of the parent folder, optionally
1267             * including mount folders for third-party repositories.
1268             *
1269             * @param  repositoryId the primary key of the folder's repository
1270             * @param  parentFolderId the primary key of the folder's parent folder
1271             * @param  includeMountFolders whether to include mount folders for
1272             *         third-party repositories
1273             * @return the immediate subfolders of the parent folder
1274             * @throws PortalException if the parent folder could not be found
1275             * @throws SystemException if a system exception occurred
1276             */
1277            @Override
1278            public List<Folder> getFolders(
1279                            long repositoryId, long parentFolderId, boolean includeMountFolders)
1280                    throws PortalException, SystemException {
1281    
1282                    return getFolders(
1283                            repositoryId, parentFolderId, includeMountFolders,
1284                            QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1285            }
1286    
1287            /**
1288             * Returns a range of all the immediate subfolders of the parent folder,
1289             * optionally including mount folders for third-party repositories.
1290             *
1291             * <p>
1292             * Useful when paginating results. Returns a maximum of <code>end -
1293             * start</code> instances. <code>start</code> and <code>end</code> are not
1294             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1295             * refers to the first result in the set. Setting both <code>start</code>
1296             * and <code>end</code> to {@link
1297             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1298             * result set.
1299             * </p>
1300             *
1301             * @param  repositoryId the primary key of the folder's repository
1302             * @param  parentFolderId the primary key of the folder's parent folder
1303             * @param  includeMountFolders whether to include mount folders for
1304             *         third-party repositories
1305             * @param  start the lower bound of the range of results
1306             * @param  end the upper bound of the range of results (not inclusive)
1307             * @return the range of immediate subfolders of the parent folder
1308             * @throws PortalException if the parent folder could not be found
1309             * @throws SystemException if a system exception occurred
1310             */
1311            @Override
1312            public List<Folder> getFolders(
1313                            long repositoryId, long parentFolderId, boolean includeMountFolders,
1314                            int start, int end)
1315                    throws PortalException, SystemException {
1316    
1317                    return getFolders(
1318                            repositoryId, parentFolderId, includeMountFolders, start, end,
1319                            null);
1320            }
1321    
1322            /**
1323             * Returns an ordered range of all the immediate subfolders of the parent
1324             * folder.
1325             *
1326             * <p>
1327             * Useful when paginating results. Returns a maximum of <code>end -
1328             * start</code> instances. <code>start</code> and <code>end</code> are not
1329             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1330             * refers to the first result in the set. Setting both <code>start</code>
1331             * and <code>end</code> to {@link
1332             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1333             * result set.
1334             * </p>
1335             *
1336             * @param  repositoryId the primary key of the folder's repository
1337             * @param  parentFolderId the primary key of the folder's parent folder
1338             * @param  includeMountFolders whether to include mount folders for
1339             *         third-party repositories
1340             * @param  start the lower bound of the range of results
1341             * @param  end the upper bound of the range of results (not inclusive)
1342             * @param  obc the comparator to order the folders (optionally
1343             *         <code>null</code>)
1344             * @return the range of immediate subfolders of the parent folder ordered by
1345             *         comparator <code>obc</code>
1346             * @throws PortalException if the parent folder could not be found
1347             * @throws SystemException if a system exception occurred
1348             */
1349            @Override
1350            public List<Folder> getFolders(
1351                            long repositoryId, long parentFolderId, boolean includeMountFolders,
1352                            int start, int end, OrderByComparator obc)
1353                    throws PortalException, SystemException {
1354    
1355                    Repository repository = getRepository(repositoryId);
1356    
1357                    return repository.getFolders(
1358                            parentFolderId, includeMountFolders, start, end, obc);
1359            }
1360    
1361            /**
1362             * Returns an ordered range of all the immediate subfolders of the parent
1363             * folder.
1364             *
1365             * <p>
1366             * Useful when paginating results. Returns a maximum of <code>end -
1367             * start</code> instances. <code>start</code> and <code>end</code> are not
1368             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1369             * refers to the first result in the set. Setting both <code>start</code>
1370             * and <code>end</code> to {@link
1371             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1372             * result set.
1373             * </p>
1374             *
1375             * @param  repositoryId the primary key of the folder's repository
1376             * @param  parentFolderId the primary key of the folder's parent folder
1377             * @param  status the workflow status
1378             * @param  includeMountFolders whether to include mount folders for
1379             *         third-party repositories
1380             * @param  start the lower bound of the range of results
1381             * @param  end the upper bound of the range of results (not inclusive)
1382             * @param  obc the comparator to order the folders (optionally
1383             *         <code>null</code>)
1384             * @return the range of immediate subfolders of the parent folder ordered by
1385             *         comparator <code>obc</code>
1386             * @throws PortalException if the parent folder could not be found
1387             * @throws SystemException if a system exception occurred
1388             */
1389            @Override
1390            public List<Folder> getFolders(
1391                            long repositoryId, long parentFolderId, int status,
1392                            boolean includeMountFolders, int start, int end,
1393                            OrderByComparator obc)
1394                    throws PortalException, SystemException {
1395    
1396                    Repository repository = getRepository(repositoryId);
1397    
1398                    return repository.getFolders(
1399                            parentFolderId, status, includeMountFolders, start, end, obc);
1400            }
1401    
1402            /**
1403             * Returns a range of all the immediate subfolders of the parent folder.
1404             *
1405             * <p>
1406             * Useful when paginating results. Returns a maximum of <code>end -
1407             * start</code> instances. <code>start</code> and <code>end</code> are not
1408             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1409             * refers to the first result in the set. Setting both <code>start</code>
1410             * and <code>end</code> to {@link
1411             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1412             * result set.
1413             * </p>
1414             *
1415             * @param  repositoryId the primary key of the folder's repository
1416             * @param  parentFolderId the primary key of the folder's parent folder
1417             * @param  start the lower bound of the range of results
1418             * @param  end the upper bound of the range of results (not inclusive)
1419             * @return the range of immediate subfolders of the parent folder
1420             * @throws PortalException if the parent folder could not be found
1421             * @throws SystemException if a system exception occurred
1422             */
1423            @Override
1424            public List<Folder> getFolders(
1425                            long repositoryId, long parentFolderId, int start, int end)
1426                    throws PortalException, SystemException {
1427    
1428                    return getFolders(repositoryId, parentFolderId, start, end, null);
1429            }
1430    
1431            /**
1432             * Returns an ordered range of all the immediate subfolders of the parent
1433             * folder.
1434             *
1435             * <p>
1436             * Useful when paginating results. Returns a maximum of <code>end -
1437             * start</code> instances. <code>start</code> and <code>end</code> are not
1438             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1439             * refers to the first result in the set. Setting both <code>start</code>
1440             * and <code>end</code> to {@link
1441             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1442             * result set.
1443             * </p>
1444             *
1445             * @param  repositoryId the primary key of the folder's repository
1446             * @param  parentFolderId the primary key of the folder's parent folder
1447             * @param  start the lower bound of the range of results
1448             * @param  end the upper bound of the range of results (not inclusive)
1449             * @param  obc the comparator to order the folders (optionally
1450             *         <code>null</code>)
1451             * @return the range of immediate subfolders of the parent folder ordered by
1452             *         comparator <code>obc</code>
1453             * @throws PortalException if the parent folder could not be found
1454             * @throws SystemException if a system exception occurred
1455             */
1456            @Override
1457            public List<Folder> getFolders(
1458                            long repositoryId, long parentFolderId, int start, int end,
1459                            OrderByComparator obc)
1460                    throws PortalException, SystemException {
1461    
1462                    Repository repository = getRepository(repositoryId);
1463    
1464                    return repository.getFolders(parentFolderId, true, start, end, obc);
1465            }
1466    
1467            /**
1468             * Returns a range of all the immediate subfolders, file entries, and file
1469             * shortcuts in the parent folder.
1470             *
1471             * <p>
1472             * Useful when paginating results. Returns a maximum of <code>end -
1473             * start</code> instances. <code>start</code> and <code>end</code> are not
1474             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1475             * refers to the first result in the set. Setting both <code>start</code>
1476             * and <code>end</code> to {@link
1477             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1478             * result set.
1479             * </p>
1480             *
1481             * @param  repositoryId the primary key of the repository
1482             * @param  folderId the primary key of the parent folder
1483             * @param  status the workflow status
1484             * @param  includeMountFolders whether to include mount folders for
1485             *         third-party repositories
1486             * @param  start the lower bound of the range of results
1487             * @param  end the upper bound of the range of results (not inclusive)
1488             * @return the range of immediate subfolders, file entries, and file
1489             *         shortcuts in the parent folder ordered by comparator
1490             *         <code>obc</code>
1491             * @throws PortalException if the parent folder could not be found
1492             * @throws SystemException if a system exception occurred
1493             */
1494            @Override
1495            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
1496                            long repositoryId, long folderId, int status,
1497                            boolean includeMountFolders, int start, int end)
1498                    throws PortalException, SystemException {
1499    
1500                    return getFoldersAndFileEntriesAndFileShortcuts(
1501                            repositoryId, folderId, status, includeMountFolders, start, end,
1502                            null);
1503            }
1504    
1505            /**
1506             * Returns an ordered range of all the immediate subfolders, file entries,
1507             * and file shortcuts in the parent folder.
1508             *
1509             * <p>
1510             * Useful when paginating results. Returns a maximum of <code>end -
1511             * start</code> instances. <code>start</code> and <code>end</code> are not
1512             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1513             * refers to the first result in the set. Setting both <code>start</code>
1514             * and <code>end</code> to {@link
1515             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1516             * result set.
1517             * </p>
1518             *
1519             * @param  repositoryId the primary key of the repository
1520             * @param  folderId the primary key of the parent folder
1521             * @param  status the workflow status
1522             * @param  includeMountFolders whether to include mount folders for
1523             *         third-party repositories
1524             * @param  start the lower bound of the range of results
1525             * @param  end the upper bound of the range of results (not inclusive)
1526             * @param  obc the comparator to order the results (optionally
1527             *         <code>null</code>)
1528             * @return the range of immediate subfolders, file entries, and file
1529             *         shortcuts in the parent folder ordered by comparator
1530             *         <code>obc</code>
1531             * @throws PortalException if the parent folder could not be found
1532             * @throws SystemException if a system exception occurred
1533             */
1534            @Override
1535            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
1536                            long repositoryId, long folderId, int status,
1537                            boolean includeMountFolders, int start, int end,
1538                            OrderByComparator obc)
1539                    throws PortalException, SystemException {
1540    
1541                    return getFoldersAndFileEntriesAndFileShortcuts(
1542                            repositoryId, folderId, status, null, includeMountFolders, start,
1543                            end, obc);
1544            }
1545    
1546            @Override
1547            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
1548                            long repositoryId, long folderId, int status, String[] mimeTypes,
1549                            boolean includeMountFolders, int start, int end,
1550                            OrderByComparator obc)
1551                    throws PortalException, SystemException {
1552    
1553                    Repository repository = getRepository(repositoryId);
1554    
1555                    return repository.getFoldersAndFileEntriesAndFileShortcuts(
1556                            folderId, status, mimeTypes, includeMountFolders, start, end, obc);
1557            }
1558    
1559            /**
1560             * Returns the number of immediate subfolders, file entries, and file
1561             * shortcuts in the parent folder.
1562             *
1563             * @param  repositoryId the primary key of the repository
1564             * @param  folderId the primary key of the parent folder
1565             * @param  status the workflow status
1566             * @param  includeMountFolders whether to include mount folders for
1567             *         third-party repositories
1568             * @return the number of immediate subfolders, file entries, and file
1569             *         shortcuts in the parent folder
1570             * @throws PortalException if the folder could not be found
1571             * @throws SystemException if a system exception occurred
1572             */
1573            @Override
1574            public int getFoldersAndFileEntriesAndFileShortcutsCount(
1575                            long repositoryId, long folderId, int status,
1576                            boolean includeMountFolders)
1577                    throws PortalException, SystemException {
1578    
1579                    return getFoldersAndFileEntriesAndFileShortcutsCount(
1580                            repositoryId, folderId, status, null, includeMountFolders);
1581            }
1582    
1583            @Override
1584            public int getFoldersAndFileEntriesAndFileShortcutsCount(
1585                            long repositoryId, long folderId, int status, String[] mimeTypes,
1586                            boolean includeMountFolders)
1587                    throws PortalException, SystemException {
1588    
1589                    Repository repository = getRepository(repositoryId);
1590    
1591                    return repository.getFoldersAndFileEntriesAndFileShortcutsCount(
1592                            folderId, status, mimeTypes, includeMountFolders);
1593            }
1594    
1595            /**
1596             * Returns the number of immediate subfolders of the parent folder.
1597             *
1598             * @param  repositoryId the primary key of the folder's repository
1599             * @param  parentFolderId the primary key of the folder's parent folder
1600             * @return the number of immediate subfolders of the parent folder
1601             * @throws PortalException if the parent folder could not be found
1602             * @throws SystemException if a system exception occurred
1603             */
1604            @Override
1605            public int getFoldersCount(long repositoryId, long parentFolderId)
1606                    throws PortalException, SystemException {
1607    
1608                    return getFoldersCount(repositoryId, parentFolderId, true);
1609            }
1610    
1611            /**
1612             * Returns the number of immediate subfolders of the parent folder,
1613             * optionally including mount folders for third-party repositories.
1614             *
1615             * @param  repositoryId the primary key of the folder's repository
1616             * @param  parentFolderId the primary key of the folder's parent folder
1617             * @param  includeMountFolders whether to include mount folders for
1618             *         third-party repositories
1619             * @return the number of immediate subfolders of the parent folder
1620             * @throws PortalException if the parent folder could not be found
1621             * @throws SystemException if a system exception occurred
1622             */
1623            @Override
1624            public int getFoldersCount(
1625                            long repositoryId, long parentFolderId, boolean includeMountFolders)
1626                    throws PortalException, SystemException {
1627    
1628                    Repository repository = getRepository(repositoryId);
1629    
1630                    return repository.getFoldersCount(parentFolderId, includeMountFolders);
1631            }
1632    
1633            /**
1634             * Returns the number of immediate subfolders of the parent folder,
1635             * optionally including mount folders for third-party repositories.
1636             *
1637             * @param  repositoryId the primary key of the folder's repository
1638             * @param  parentFolderId the primary key of the folder's parent folder
1639             * @param  status the workflow status
1640             * @param  includeMountFolders whether to include mount folders for
1641             *         third-party repositories
1642             * @return the number of immediate subfolders of the parent folder
1643             * @throws PortalException if the parent folder could not be found
1644             * @throws SystemException if a system exception occurred
1645             */
1646            @Override
1647            public int getFoldersCount(
1648                            long repositoryId, long parentFolderId, int status,
1649                            boolean includeMountFolders)
1650                    throws PortalException, SystemException {
1651    
1652                    Repository repository = getRepository(repositoryId);
1653    
1654                    return repository.getFoldersCount(
1655                            parentFolderId, status, includeMountFolders);
1656            }
1657    
1658            /**
1659             * Returns the number of immediate subfolders and file entries across the
1660             * folders.
1661             *
1662             * @param  repositoryId the primary key of the repository
1663             * @param  folderIds the primary keys of folders from which to count
1664             *         immediate subfolders and file entries
1665             * @param  status the workflow status
1666             * @return the number of immediate subfolders and file entries across the
1667             *         folders
1668             * @throws PortalException if the repository could not be found
1669             * @throws SystemException if a system exception occurred
1670             */
1671            @Override
1672            public int getFoldersFileEntriesCount(
1673                            long repositoryId, List<Long> folderIds, int status)
1674                    throws PortalException, SystemException {
1675    
1676                    Repository repository = getRepository(repositoryId);
1677    
1678                    return repository.getFoldersFileEntriesCount(folderIds, status);
1679            }
1680    
1681            /**
1682             * Returns an ordered range of all the file entries in the group starting at
1683             * the repository default parent folder that are stored within the Liferay
1684             * repository. This method is primarily used to search for recently modified
1685             * file entries. It can be limited to the file entries modified by a given
1686             * user.
1687             *
1688             * <p>
1689             * Useful when paginating results. Returns a maximum of <code>end -
1690             * start</code> instances. <code>start</code> and <code>end</code> are not
1691             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1692             * refers to the first result in the set. Setting both <code>start</code>
1693             * and <code>end</code> to {@link
1694             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1695             * result set.
1696             * </p>
1697             *
1698             * @param  groupId the primary key of the group
1699             * @param  userId the primary key of the user who created the file
1700             *         (optionally <code>0</code>)
1701             * @param  start the lower bound of the range of results
1702             * @param  end the upper bound of the range of results (not inclusive)
1703             * @return the range of matching file entries ordered by date modified
1704             * @throws PortalException if the group could not be found
1705             * @throws SystemException if a system exception occurred
1706             */
1707            @Override
1708            public List<FileEntry> getGroupFileEntries(
1709                            long groupId, long userId, int start, int end)
1710                    throws PortalException, SystemException {
1711    
1712                    return getGroupFileEntries(
1713                            groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, start,
1714                            end, new RepositoryModelModifiedDateComparator());
1715            }
1716    
1717            /**
1718             * Returns an ordered range of all the file entries in the group that are
1719             * stored within the Liferay repository. This method is primarily used to
1720             * search for recently modified file entries. It can be limited to the file
1721             * entries modified by a given user.
1722             *
1723             * <p>
1724             * Useful when paginating results. Returns a maximum of <code>end -
1725             * start</code> instances. <code>start</code> and <code>end</code> are not
1726             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1727             * refers to the first result in the set. Setting both <code>start</code>
1728             * and <code>end</code> to {@link
1729             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1730             * result set.
1731             * </p>
1732             *
1733             * @param  groupId the primary key of the group
1734             * @param  userId the primary key of the user who created the file
1735             *         (optionally <code>0</code>)
1736             * @param  start the lower bound of the range of results
1737             * @param  end the upper bound of the range of results (not inclusive)
1738             * @param  obc the comparator to order the file entries (optionally
1739             *         <code>null</code>)
1740             * @return the range of matching file entries ordered by comparator
1741             *         <code>obc</code>
1742             * @throws PortalException if the group could not be found
1743             * @throws SystemException if a system exception occurred
1744             */
1745            @Override
1746            public List<FileEntry> getGroupFileEntries(
1747                            long groupId, long userId, int start, int end,
1748                            OrderByComparator obc)
1749                    throws PortalException, SystemException {
1750    
1751                    return getGroupFileEntries(
1752                            groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, start,
1753                            end, obc);
1754            }
1755    
1756            /**
1757             * Returns an ordered range of all the file entries in the group starting at
1758             * the root folder that are stored within the Liferay repository. This
1759             * method is primarily used to search for recently modified file entries. It
1760             * can be limited to the file entries modified by a given user.
1761             *
1762             * <p>
1763             * Useful when paginating results. Returns a maximum of <code>end -
1764             * start</code> instances. <code>start</code> and <code>end</code> are not
1765             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1766             * refers to the first result in the set. Setting both <code>start</code>
1767             * and <code>end</code> to {@link
1768             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1769             * result set.
1770             * </p>
1771             *
1772             * @param  groupId the primary key of the group
1773             * @param  userId the primary key of the user who created the file
1774             *         (optionally <code>0</code>)
1775             * @param  rootFolderId the primary key of the root folder to begin the
1776             *         search
1777             * @param  start the lower bound of the range of results
1778             * @param  end the upper bound of the range of results (not inclusive)
1779             * @return the range of matching file entries ordered by date modified
1780             * @throws PortalException if the group could not be found
1781             * @throws SystemException if a system exception occurred
1782             */
1783            @Override
1784            public List<FileEntry> getGroupFileEntries(
1785                            long groupId, long userId, long rootFolderId, int start, int end)
1786                    throws PortalException, SystemException {
1787    
1788                    return getGroupFileEntries(
1789                            groupId, userId, rootFolderId, start, end,
1790                            new RepositoryModelModifiedDateComparator());
1791            }
1792    
1793            /**
1794             * Returns an ordered range of all the file entries in the group starting at
1795             * the root folder that are stored within the Liferay repository. This
1796             * method is primarily used to search for recently modified file entries. It
1797             * can be limited to the file entries modified by a given user.
1798             *
1799             * <p>
1800             * Useful when paginating results. Returns a maximum of <code>end -
1801             * start</code> instances. <code>start</code> and <code>end</code> are not
1802             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1803             * refers to the first result in the set. Setting both <code>start</code>
1804             * and <code>end</code> to {@link
1805             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1806             * result set.
1807             * </p>
1808             *
1809             * @param  groupId the primary key of the group
1810             * @param  userId the primary key of the user who created the file
1811             *         (optionally <code>0</code>)
1812             * @param  rootFolderId the primary key of the root folder to begin the
1813             *         search
1814             * @param  start the lower bound of the range of results
1815             * @param  end the upper bound of the range of results (not inclusive)
1816             * @param  obc the comparator to order the file entries (optionally
1817             *         <code>null</code>)
1818             * @return the range of matching file entries ordered by comparator
1819             *         <code>obc</code>
1820             * @throws PortalException if the group could not be found
1821             * @throws SystemException if a system exception occurred
1822             */
1823            @Override
1824            public List<FileEntry> getGroupFileEntries(
1825                            long groupId, long userId, long rootFolderId, int start, int end,
1826                            OrderByComparator obc)
1827                    throws PortalException, SystemException {
1828    
1829                    Repository repository = getRepository(groupId);
1830    
1831                    return repository.getRepositoryFileEntries(
1832                            userId, rootFolderId, start, end, obc);
1833            }
1834    
1835            @Override
1836            public List<FileEntry> getGroupFileEntries(
1837                            long groupId, long userId, long rootFolderId, String[] mimeTypes,
1838                            int status, int start, int end, OrderByComparator obc)
1839                    throws PortalException, SystemException {
1840    
1841                    Repository repository = getRepository(groupId);
1842    
1843                    return repository.getRepositoryFileEntries(
1844                            userId, rootFolderId, mimeTypes, status, start, end, obc);
1845            }
1846    
1847            /**
1848             * Returns the number of file entries in a group starting at the repository
1849             * default parent folder that are stored within the Liferay repository. This
1850             * method is primarily used to search for recently modified file entries. It
1851             * can be limited to the file entries modified by a given user.
1852             *
1853             * @param  groupId the primary key of the group
1854             * @param  userId the primary key of the user who created the file
1855             *         (optionally <code>0</code>)
1856             * @return the number of matching file entries
1857             * @throws PortalException if the group could not be found
1858             * @throws SystemException if a system exception occurred
1859             */
1860            @Override
1861            public int getGroupFileEntriesCount(long groupId, long userId)
1862                    throws PortalException, SystemException {
1863    
1864                    return getGroupFileEntriesCount(
1865                            groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
1866            }
1867    
1868            /**
1869             * Returns the number of file entries in a group starting at the root folder
1870             * that are stored within the Liferay repository. This method is primarily
1871             * used to search for recently modified file entries. It can be limited to
1872             * the file entries modified by a given user.
1873             *
1874             * @param  groupId the primary key of the group
1875             * @param  userId the primary key of the user who created the file
1876             *         (optionally <code>0</code>)
1877             * @param  rootFolderId the primary key of the root folder to begin the
1878             *         search
1879             * @return the number of matching file entries
1880             * @throws PortalException if the group could not be found
1881             * @throws SystemException if a system exception occurred
1882             */
1883            @Override
1884            public int getGroupFileEntriesCount(
1885                            long groupId, long userId, long rootFolderId)
1886                    throws PortalException, SystemException {
1887    
1888                    Repository repository = getRepository(groupId);
1889    
1890                    return repository.getRepositoryFileEntriesCount(userId, rootFolderId);
1891            }
1892    
1893            @Override
1894            public int getGroupFileEntriesCount(
1895                            long groupId, long userId, long rootFolderId, String[] mimeTypes,
1896                            int status)
1897                    throws PortalException, SystemException {
1898    
1899                    Repository repository = getRepository(groupId);
1900    
1901                    return repository.getRepositoryFileEntriesCount(
1902                            userId, rootFolderId, mimeTypes, status);
1903            }
1904    
1905            /**
1906             * Returns all immediate subfolders of the parent folder that are used for
1907             * mounting third-party repositories. This method is only supported by the
1908             * Liferay repository.
1909             *
1910             * @param  repositoryId the primary key of the folder's repository
1911             * @param  parentFolderId the primary key of the folder's parent folder
1912             * @return the immediate subfolders of the parent folder that are used for
1913             *         mounting third-party repositories
1914             * @throws PortalException if the repository or parent folder could not be
1915             *         found
1916             * @throws SystemException if a system exception occurred
1917             */
1918            @Override
1919            public List<Folder> getMountFolders(long repositoryId, long parentFolderId)
1920                    throws PortalException, SystemException {
1921    
1922                    return getMountFolders(
1923                            repositoryId, parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1924            }
1925    
1926            /**
1927             * Returns a range of all the immediate subfolders of the parent folder that
1928             * are used for mounting third-party repositories. This method is only
1929             * supported by the Liferay repository.
1930             *
1931             * <p>
1932             * Useful when paginating results. Returns a maximum of <code>end -
1933             * start</code> instances. <code>start</code> and <code>end</code> are not
1934             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1935             * refers to the first result in the set. Setting both <code>start</code>
1936             * and <code>end</code> to {@link
1937             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1938             * result set.
1939             * </p>
1940             *
1941             * @param  repositoryId the primary key of the repository
1942             * @param  parentFolderId the primary key of the parent folder
1943             * @param  start the lower bound of the range of results
1944             * @param  end the upper bound of the range of results (not inclusive)
1945             * @return the range of immediate subfolders of the parent folder that are
1946             *         used for mounting third-party repositories
1947             * @throws PortalException if the repository or parent folder could not be
1948             *         found
1949             * @throws SystemException if a system exception occurred
1950             */
1951            @Override
1952            public List<Folder> getMountFolders(
1953                            long repositoryId, long parentFolderId, int start, int end)
1954                    throws PortalException, SystemException {
1955    
1956                    return getMountFolders(repositoryId, parentFolderId, start, end, null);
1957            }
1958    
1959            /**
1960             * Returns an ordered range of all the immediate subfolders of the parent
1961             * folder that are used for mounting third-party repositories. This method
1962             * is only supported by the Liferay repository.
1963             *
1964             * <p>
1965             * Useful when paginating results. Returns a maximum of <code>end -
1966             * start</code> instances. <code>start</code> and <code>end</code> are not
1967             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1968             * refers to the first result in the set. Setting both <code>start</code>
1969             * and <code>end</code> to {@link
1970             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1971             * result set.
1972             * </p>
1973             *
1974             * @param  repositoryId the primary key of the folder's repository
1975             * @param  parentFolderId the primary key of the folder's parent folder
1976             * @param  start the lower bound of the range of results
1977             * @param  end the upper bound of the range of results (not inclusive)
1978             * @param  obc the comparator to order the folders (optionally
1979             *         <code>null</code>)
1980             * @return the range of immediate subfolders of the parent folder that are
1981             *         used for mounting third-party repositories ordered by comparator
1982             *         <code>obc</code>
1983             * @throws PortalException if the repository or parent folder could not be
1984             *         found
1985             * @throws SystemException if a system exception occurred
1986             */
1987            @Override
1988            public List<Folder> getMountFolders(
1989                            long repositoryId, long parentFolderId, int start, int end,
1990                            OrderByComparator obc)
1991                    throws PortalException, SystemException {
1992    
1993                    Repository repository = getRepository(repositoryId);
1994    
1995                    return repository.getMountFolders(parentFolderId, start, end, obc);
1996            }
1997    
1998            /**
1999             * Returns the number of immediate subfolders of the parent folder that are
2000             * used for mounting third-party repositories. This method is only supported
2001             * by the Liferay repository.
2002             *
2003             * @param  repositoryId the primary key of the repository
2004             * @param  parentFolderId the primary key of the parent folder
2005             * @return the number of folders of the parent folder that are used for
2006             *         mounting third-party repositories
2007             * @throws PortalException if the repository or parent folder could not be
2008             *         found
2009             * @throws SystemException if a system exception occurred
2010             */
2011            @Override
2012            public int getMountFoldersCount(long repositoryId, long parentFolderId)
2013                    throws PortalException, SystemException {
2014    
2015                    Repository repository = getRepository(repositoryId);
2016    
2017                    return repository.getMountFoldersCount(parentFolderId);
2018            }
2019    
2020            @Override
2021            public void getSubfolderIds(
2022                            long repositoryId, List<Long> folderIds, long folderId)
2023                    throws PortalException, SystemException {
2024    
2025                    Repository repository = getRepository(repositoryId);
2026    
2027                    repository.getSubfolderIds(folderIds, folderId);
2028            }
2029    
2030            /**
2031             * Returns all the descendant folders of the folder with the primary key.
2032             *
2033             * @param  repositoryId the primary key of the repository
2034             * @param  folderId the primary key of the folder
2035             * @return the descendant folders of the folder with the primary key
2036             * @throws PortalException if the repository or parent folder could not be
2037             *         found
2038             * @throws SystemException if a system exception occurred
2039             */
2040            @Override
2041            public List<Long> getSubfolderIds(long repositoryId, long folderId)
2042                    throws PortalException, SystemException {
2043    
2044                    return getSubfolderIds(repositoryId, folderId, true);
2045            }
2046    
2047            /**
2048             * Returns descendant folders of the folder with the primary key, optionally
2049             * limiting to one level deep.
2050             *
2051             * @param  repositoryId the primary key of the repository
2052             * @param  folderId the primary key of the folder
2053             * @param  recurse whether to recurse through each subfolder
2054             * @return the descendant folders of the folder with the primary key
2055             * @throws PortalException if the repository or parent folder could not be
2056             *         found
2057             * @throws SystemException if a system exception occurred
2058             */
2059            @Override
2060            public List<Long> getSubfolderIds(
2061                            long repositoryId, long folderId, boolean recurse)
2062                    throws PortalException, SystemException {
2063    
2064                    Repository repository = getRepository(repositoryId);
2065    
2066                    return repository.getSubfolderIds(folderId, recurse);
2067            }
2068    
2069            /**
2070             * Returns all the temporary file entry names.
2071             *
2072             * @param  groupId the primary key of the group
2073             * @param  folderId the primary key of the folder where the file entry will
2074             *         eventually reside
2075             * @param  tempFolderName the temporary folder's name
2076             * @return the temporary file entry names
2077             * @throws PortalException if the folder was invalid
2078             * @throws SystemException if a system exception occurred
2079             * @see    #addTempFileEntry(long, long, String, String, File, String)
2080             * @see    com.liferay.portal.kernel.util.TempFileUtil
2081             */
2082            @Override
2083            public String[] getTempFileEntryNames(
2084                            long groupId, long folderId, String tempFolderName)
2085                    throws PortalException, SystemException {
2086    
2087                    DLFolderPermission.check(
2088                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
2089    
2090                    return TempFileUtil.getTempFileEntryNames(
2091                            groupId, getUserId(), tempFolderName);
2092            }
2093    
2094            /**
2095             * @deprecated As of 6.2.0, replaced by {@link #checkOutFileEntry(long,
2096             *             ServiceContext)}
2097             */
2098            @Override
2099            public Lock lockFileEntry(long fileEntryId)
2100                    throws PortalException, SystemException {
2101    
2102                    checkOutFileEntry(fileEntryId, new ServiceContext());
2103    
2104                    FileEntry fileEntry = getFileEntry(fileEntryId);
2105    
2106                    return fileEntry.getLock();
2107            }
2108    
2109            /**
2110             * @deprecated As of 6.2.0, replaced by {@link #checkOutFileEntry(long,
2111             *             String, long, ServiceContext)}
2112             */
2113            @Override
2114            public Lock lockFileEntry(
2115                            long fileEntryId, String owner, long expirationTime)
2116                    throws PortalException, SystemException {
2117    
2118                    FileEntry fileEntry = checkOutFileEntry(
2119                            fileEntryId, owner, expirationTime, new ServiceContext());
2120    
2121                    return fileEntry.getLock();
2122            }
2123    
2124            /**
2125             * Locks the folder. This method is primarily used by WebDAV.
2126             *
2127             * @param  repositoryId the primary key of the repository
2128             * @param  folderId the primary key of the folder
2129             * @return the lock object
2130             * @throws PortalException if the repository or folder could not be found
2131             * @throws SystemException if a system exception occurred
2132             */
2133            @Override
2134            public Lock lockFolder(long repositoryId, long folderId)
2135                    throws PortalException, SystemException {
2136    
2137                    Repository repository = getRepository(repositoryId);
2138    
2139                    return repository.lockFolder(folderId);
2140            }
2141    
2142            /**
2143             * Locks the folder. This method is primarily used by WebDAV.
2144             *
2145             * @param  repositoryId the primary key of the repository
2146             * @param  folderId the primary key of the folder
2147             * @param  owner the owner string for the checkout (optionally
2148             *         <code>null</code>)
2149             * @param  inheritable whether the lock must propagate to descendants
2150             * @param  expirationTime the time in milliseconds before the lock expires.
2151             *         If the value is <code>0</code>, the default expiration time will
2152             *         be used from <code>portal.properties>.
2153             * @return the lock object
2154             * @throws PortalException if the repository or folder could not be found
2155             * @throws SystemException if a system exception occurred
2156             */
2157            @Override
2158            public Lock lockFolder(
2159                            long repositoryId, long folderId, String owner, boolean inheritable,
2160                            long expirationTime)
2161                    throws PortalException, SystemException {
2162    
2163                    Repository repository = getRepository(repositoryId);
2164    
2165                    return repository.lockFolder(
2166                            folderId, owner, inheritable, expirationTime);
2167            }
2168    
2169            /**
2170             * Moves the file entry to the new folder.
2171             *
2172             * @param  fileEntryId the primary key of the file entry
2173             * @param  newFolderId the primary key of the new folder
2174             * @param  serviceContext the service context to be applied
2175             * @return the file entry
2176             * @throws PortalException if the file entry or the new folder could not be
2177             *         found
2178             * @throws SystemException if a system exception occurred
2179             */
2180            @Override
2181            public FileEntry moveFileEntry(
2182                            long fileEntryId, long newFolderId, ServiceContext serviceContext)
2183                    throws PortalException, SystemException {
2184    
2185                    Repository fromRepository = getFileEntryRepository(fileEntryId);
2186                    Repository toRepository = getFolderRepository(
2187                            newFolderId, serviceContext.getScopeGroupId());
2188    
2189                    if (newFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
2190                            Folder toFolder = toRepository.getFolder(newFolderId);
2191    
2192                            if (toFolder.isMountPoint()) {
2193                                    toRepository = getRepository(toFolder.getRepositoryId());
2194                            }
2195                    }
2196    
2197                    if (fromRepository.getRepositoryId() ==
2198                                    toRepository.getRepositoryId()) {
2199    
2200                            // Move file entries within repository
2201    
2202                            FileEntry fileEntry = fromRepository.moveFileEntry(
2203                                    fileEntryId, newFolderId, serviceContext);
2204    
2205                            return fileEntry;
2206                    }
2207    
2208                    // Move file entries between repositories
2209    
2210                    return moveFileEntries(
2211                            fileEntryId, newFolderId, fromRepository, toRepository,
2212                            serviceContext);
2213            }
2214    
2215            /**
2216             * Moves the file entry from a trashed folder to the new folder.
2217             *
2218             * @param  fileEntryId the primary key of the file entry
2219             * @param  newFolderId the primary key of the new folder
2220             * @param  serviceContext the service context to be applied
2221             * @return the file entry
2222             * @throws PortalException if the file entry or the new folder could not be
2223             *         found
2224             * @throws SystemException if a system exception occurred
2225             */
2226            @Override
2227            public FileEntry moveFileEntryFromTrash(
2228                            long fileEntryId, long newFolderId, ServiceContext serviceContext)
2229                    throws PortalException, SystemException {
2230    
2231                    Repository repository = getFileEntryRepository(fileEntryId);
2232    
2233                    if (!(repository instanceof LiferayRepository)) {
2234                            throw new InvalidRepositoryException(
2235                                    "Repository " + repository.getRepositoryId() +
2236                                            " does not support trash operations");
2237                    }
2238    
2239                    FileEntry fileEntry = repository.getFileEntry(fileEntryId);
2240    
2241                    DLFileEntryPermission.check(
2242                            getPermissionChecker(), fileEntry, ActionKeys.UPDATE);
2243    
2244                    return dlAppHelperLocalService.moveFileEntryFromTrash(
2245                            getUserId(), fileEntry, newFolderId, serviceContext);
2246            }
2247    
2248            /**
2249             * Moves the file entry with the primary key to the trash portlet.
2250             *
2251             * @param  fileEntryId the primary key of the file entry
2252             * @return the file entry
2253             * @throws PortalException if the file entry could not be found
2254             * @throws SystemException if a system exception occurred
2255             */
2256            @Override
2257            public FileEntry moveFileEntryToTrash(long fileEntryId)
2258                    throws PortalException, SystemException {
2259    
2260                    Repository repository = getFileEntryRepository(fileEntryId);
2261    
2262                    if (!(repository instanceof LiferayRepository)) {
2263                            throw new InvalidRepositoryException(
2264                                    "Repository " + repository.getRepositoryId() +
2265                                            " does not support trash operations");
2266                    }
2267    
2268                    FileEntry fileEntry = repository.getFileEntry(fileEntryId);
2269    
2270                    DLFileEntryPermission.check(
2271                            getPermissionChecker(), fileEntry, ActionKeys.DELETE);
2272    
2273                    return dlAppHelperLocalService.moveFileEntryToTrash(
2274                            getUserId(), fileEntry);
2275            }
2276    
2277            /**
2278             * Moves the file shortcut from a trashed folder to the new folder.
2279             *
2280             * @param  fileShortcutId the primary key of the file shortcut
2281             * @param  newFolderId the primary key of the new folder
2282             * @param  serviceContext the service context to be applied
2283             * @return the file shortcut
2284             * @throws PortalException if the file entry or the new folder could not be
2285             *         found
2286             * @throws SystemException if a system exception occurred
2287             */
2288            @Override
2289            public DLFileShortcut moveFileShortcutFromTrash(
2290                            long fileShortcutId, long newFolderId,
2291                            ServiceContext serviceContext)
2292                    throws PortalException, SystemException {
2293    
2294                    DLFileShortcut fileShortcut = getFileShortcut(fileShortcutId);
2295    
2296                    DLFileShortcutPermission.check(
2297                            getPermissionChecker(), fileShortcut, ActionKeys.UPDATE);
2298    
2299                    return dlAppHelperLocalService.moveFileShortcutFromTrash(
2300                            getUserId(), fileShortcut, newFolderId, serviceContext);
2301            }
2302    
2303            /**
2304             * Moves the file shortcut with the primary key to the trash portlet.
2305             *
2306             * @param  fileShortcutId the primary key of the file shortcut
2307             * @return the file shortcut
2308             * @throws PortalException if the file shortcut could not be found
2309             * @throws SystemException if a system exception occurred
2310             */
2311            @Override
2312            public DLFileShortcut moveFileShortcutToTrash(long fileShortcutId)
2313                    throws PortalException, SystemException {
2314    
2315                    DLFileShortcut fileShortcut = getFileShortcut(fileShortcutId);
2316    
2317                    DLFileShortcutPermission.check(
2318                            getPermissionChecker(), fileShortcut, ActionKeys.DELETE);
2319    
2320                    return dlAppHelperLocalService.moveFileShortcutToTrash(
2321                            getUserId(), fileShortcut);
2322            }
2323    
2324            /**
2325             * Moves the folder to the new parent folder with the primary key.
2326             *
2327             * @param  folderId the primary key of the folder
2328             * @param  parentFolderId the primary key of the new parent folder
2329             * @param  serviceContext the service context to be applied
2330             * @return the file entry
2331             * @throws PortalException if the folder could not be found
2332             * @throws SystemException if a system exception occurred
2333             */
2334            @Override
2335            public Folder moveFolder(
2336                            long folderId, long parentFolderId, ServiceContext serviceContext)
2337                    throws PortalException, SystemException {
2338    
2339                    Repository fromRepository = getFolderRepository(folderId);
2340                    Repository toRepository = getFolderRepository(
2341                            parentFolderId, serviceContext.getScopeGroupId());
2342    
2343                    if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
2344                            Folder toFolder = toRepository.getFolder(parentFolderId);
2345    
2346                            if (toFolder.isMountPoint()) {
2347                                    toRepository = getRepository(toFolder.getRepositoryId());
2348                            }
2349                    }
2350    
2351                    if (fromRepository.getRepositoryId() ==
2352                                    toRepository.getRepositoryId()) {
2353    
2354                            // Move file entries within repository
2355    
2356                            Folder folder = fromRepository.moveFolder(
2357                                    folderId, parentFolderId, serviceContext);
2358    
2359                            return folder;
2360                    }
2361    
2362                    // Move file entries between repositories
2363    
2364                    return moveFolders(
2365                            folderId, parentFolderId, fromRepository, toRepository,
2366                            serviceContext);
2367            }
2368    
2369            /**
2370             * Moves the folder with the primary key from the trash portlet to the new
2371             * parent folder with the primary key.
2372             *
2373             * @param  folderId the primary key of the folder
2374             * @param  parentFolderId the primary key of the new parent folder
2375             * @param  serviceContext the service context to be applied
2376             * @return the file entry
2377             * @throws PortalException if the folder could not be found
2378             * @throws SystemException if a system exception occurred
2379             */
2380            @Override
2381            public Folder moveFolderFromTrash(
2382                            long folderId, long parentFolderId, ServiceContext serviceContext)
2383                    throws PortalException, SystemException {
2384    
2385                    Repository repository = getFolderRepository(folderId);
2386    
2387                    if (!(repository instanceof LiferayRepository)) {
2388                            throw new InvalidRepositoryException(
2389                                    "Repository " + repository.getRepositoryId() +
2390                                            " does not support trash operations");
2391                    }
2392    
2393                    Folder folder = repository.getFolder(folderId);
2394    
2395                    DLFolderPermission.check(
2396                            getPermissionChecker(), folder, ActionKeys.UPDATE);
2397    
2398                    return dlAppHelperLocalService.moveFolderFromTrash(
2399                            getUserId(), folder, parentFolderId, serviceContext);
2400            }
2401    
2402            /**
2403             * Moves the folder with the primary key to the trash portlet.
2404             *
2405             * @param  folderId the primary key of the folder
2406             * @return the file entry
2407             * @throws PortalException if the folder could not be found
2408             * @throws SystemException if a system exception occurred
2409             */
2410            @Override
2411            public Folder moveFolderToTrash(long folderId)
2412                    throws PortalException, SystemException {
2413    
2414                    Repository repository = getFolderRepository(folderId);
2415    
2416                    if (!(repository instanceof LiferayRepository)) {
2417                            throw new InvalidRepositoryException(
2418                                    "Repository " + repository.getRepositoryId() +
2419                                            " does not support trash operations");
2420                    }
2421    
2422                    Folder folder = repository.getFolder(folderId);
2423    
2424                    DLFolderPermission.check(
2425                            getPermissionChecker(), folder, ActionKeys.DELETE);
2426    
2427                    return dlAppHelperLocalService.moveFolderToTrash(getUserId(), folder);
2428            }
2429    
2430            /**
2431             * Refreshes the lock for the file entry. This method is primarily used by
2432             * WebDAV.
2433             *
2434             * @param  lockUuid the lock's UUID
2435             * @param  companyId the primary key of the file entry's company
2436             * @param  expirationTime the time in milliseconds before the lock expires.
2437             *         If the value is <code>0</code>, the default expiration time will
2438             *         be used from <code>portal.properties>.
2439             * @return the lock object
2440             * @throws PortalException if the file entry or lock could not be found
2441             * @throws SystemException if a system exception occurred
2442             */
2443            @Override
2444            public Lock refreshFileEntryLock(
2445                            String lockUuid, long companyId, long expirationTime)
2446                    throws PortalException, SystemException {
2447    
2448                    Lock lock = lockLocalService.getLockByUuidAndCompanyId(
2449                            lockUuid, companyId);
2450    
2451                    long fileEntryId = GetterUtil.getLong(lock.getKey());
2452    
2453                    Repository repository = getFileEntryRepository(fileEntryId);
2454    
2455                    return repository.refreshFileEntryLock(
2456                            lockUuid, companyId, expirationTime);
2457            }
2458    
2459            /**
2460             * Refreshes the lock for the folder. This method is primarily used by
2461             * WebDAV.
2462             *
2463             * @param  lockUuid the lock's UUID
2464             * @param  companyId the primary key of the file entry's company
2465             * @param  expirationTime the time in milliseconds before the lock expires.
2466             *         If the value is <code>0</code>, the default expiration time will
2467             *         be used from <code>portal.properties>.
2468             * @return the lock object
2469             * @throws PortalException if the folder or lock could not be found
2470             * @throws SystemException if a system exception occurred
2471             */
2472            @Override
2473            public Lock refreshFolderLock(
2474                            String lockUuid, long companyId, long expirationTime)
2475                    throws PortalException, SystemException {
2476    
2477                    Lock lock = lockLocalService.getLockByUuidAndCompanyId(
2478                            lockUuid, companyId);
2479    
2480                    long folderId = GetterUtil.getLong(lock.getKey());
2481    
2482                    Repository repository = getFolderRepository(folderId);
2483    
2484                    return repository.refreshFolderLock(
2485                            lockUuid, companyId, expirationTime);
2486            }
2487    
2488            /**
2489             * Restores the file entry with the primary key from the trash portlet.
2490             *
2491             * @param  fileEntryId the primary key of the file entry
2492             * @throws PortalException if the file entry could not be found
2493             * @throws SystemException if a system exception occurred
2494             */
2495            @Override
2496            public void restoreFileEntryFromTrash(long fileEntryId)
2497                    throws PortalException, SystemException {
2498    
2499                    Repository repository = getFileEntryRepository(fileEntryId);
2500    
2501                    if (!(repository instanceof LiferayRepository)) {
2502                            throw new InvalidRepositoryException(
2503                                    "Repository " + repository.getRepositoryId() +
2504                                            " does not support trash operations");
2505                    }
2506    
2507                    FileEntry fileEntry = repository.getFileEntry(fileEntryId);
2508    
2509                    DLFileEntryPermission.check(
2510                            getPermissionChecker(), fileEntry, ActionKeys.DELETE);
2511    
2512                    dlAppHelperLocalService.restoreFileEntryFromTrash(
2513                            getUserId(), fileEntry);
2514            }
2515    
2516            /**
2517             * Restores the file shortcut with the primary key from the trash portlet.
2518             *
2519             * @param  fileShortcutId the primary key of the file shortcut
2520             * @throws PortalException if the file shortcut could not be found
2521             * @throws SystemException if a system exception occurred
2522             */
2523            @Override
2524            public void restoreFileShortcutFromTrash(long fileShortcutId)
2525                    throws PortalException, SystemException {
2526    
2527                    DLFileShortcut fileShortcut = getFileShortcut(fileShortcutId);
2528    
2529                    DLFileShortcutPermission.check(
2530                            getPermissionChecker(), fileShortcut, ActionKeys.DELETE);
2531    
2532                    dlAppHelperLocalService.restoreFileShortcutFromTrash(
2533                            getUserId(), fileShortcut);
2534            }
2535    
2536            /**
2537             * Restores the folder with the primary key from the trash portlet.
2538             *
2539             * @param  folderId the primary key of the folder
2540             * @throws PortalException if the folder could not be found
2541             * @throws SystemException if a system exception occurred
2542             */
2543            @Override
2544            public void restoreFolderFromTrash(long folderId)
2545                    throws PortalException, SystemException {
2546    
2547                    Repository repository = getFolderRepository(folderId);
2548    
2549                    if (!(repository instanceof LiferayRepository)) {
2550                            throw new InvalidRepositoryException(
2551                                    "Repository " + repository.getRepositoryId() +
2552                                            " does not support trash operations");
2553                    }
2554    
2555                    Folder folder = repository.getFolder(folderId);
2556    
2557                    DLFolderPermission.check(
2558                            getPermissionChecker(), folder, ActionKeys.DELETE);
2559    
2560                    dlAppHelperLocalService.restoreFolderFromTrash(getUserId(), folder);
2561            }
2562    
2563            /**
2564             * Reverts the file entry to a previous version. A new version will be
2565             * created based on the previous version and metadata.
2566             *
2567             * @param  fileEntryId the primary key of the file entry
2568             * @param  version the version to revert back to
2569             * @param  serviceContext the service context to be applied
2570             * @throws PortalException if the file entry or version could not be found
2571             * @throws SystemException if a system exception occurred
2572             */
2573            @Override
2574            public void revertFileEntry(
2575                            long fileEntryId, String version, ServiceContext serviceContext)
2576                    throws PortalException, SystemException {
2577    
2578                    Repository repository = getFileEntryRepository(fileEntryId);
2579    
2580                    repository.revertFileEntry(fileEntryId, version, serviceContext);
2581    
2582                    FileEntry fileEntry = getFileEntry(fileEntryId);
2583    
2584                    dlAppHelperLocalService.updateFileEntry(
2585                            getUserId(), fileEntry, fileEntry.getFileVersion(version),
2586                            fileEntry.getFileVersion(), serviceContext);
2587            }
2588    
2589            @Override
2590            public Hits search(
2591                            long repositoryId, long creatorUserId, int status, int start,
2592                            int end)
2593                    throws PortalException, SystemException {
2594    
2595                    Repository repository = getRepository(repositoryId);
2596    
2597                    return repository.search(creatorUserId, status, start, end);
2598            }
2599    
2600            @Override
2601            public Hits search(
2602                            long repositoryId, long creatorUserId, long folderId,
2603                            String[] mimeTypes, int status, int start, int end)
2604                    throws PortalException, SystemException {
2605    
2606                    Repository repository = getRepository(repositoryId);
2607    
2608                    return repository.search(
2609                            creatorUserId, folderId, mimeTypes, status, start, end);
2610            }
2611    
2612            @Override
2613            public Hits search(long repositoryId, SearchContext searchContext)
2614                    throws SearchException {
2615    
2616                    try {
2617                            Repository repository = getRepository(repositoryId);
2618    
2619                            return repository.search(searchContext);
2620                    }
2621                    catch (Exception e) {
2622                            throw new SearchException(e);
2623                    }
2624            }
2625    
2626            @Override
2627            public Hits search(
2628                            long repositoryId, SearchContext searchContext, Query query)
2629                    throws SearchException {
2630    
2631                    try {
2632                            Repository repository = getRepository(repositoryId);
2633    
2634                            return repository.search(searchContext, query);
2635                    }
2636                    catch (Exception e) {
2637                            throw new SearchException(e);
2638                    }
2639            }
2640    
2641            /**
2642             * Subscribe the user to changes in documents of the file entry type. This
2643             * method is only supported by the Liferay repository.
2644             *
2645             * @param  groupId the primary key of the file entry type's group
2646             * @param  fileEntryTypeId the primary key of the file entry type
2647             * @throws PortalException if the user or group could not be found, or if
2648             *         subscribing was not permissible
2649             * @throws SystemException if a system exception occurred
2650             */
2651            @Override
2652            public void subscribeFileEntryType(long groupId, long fileEntryTypeId)
2653                    throws PortalException, SystemException {
2654    
2655                    DLPermission.check(
2656                            getPermissionChecker(), groupId, ActionKeys.SUBSCRIBE);
2657    
2658                    dlAppLocalService.subscribeFileEntryType(
2659                            getUserId(), groupId, fileEntryTypeId);
2660            }
2661    
2662            /**
2663             * Subscribe the user to document changes in the folder. This method is only
2664             * supported by the Liferay repository.
2665             *
2666             * @param  groupId the primary key of the folder's group
2667             * @param  folderId the primary key of the folder
2668             * @throws PortalException if the user or group could not be found, or if
2669             *         subscribing was not permissible
2670             * @throws SystemException if a system exception occurred
2671             */
2672            @Override
2673            public void subscribeFolder(long groupId, long folderId)
2674                    throws PortalException, SystemException {
2675    
2676                    DLPermission.check(
2677                            getPermissionChecker(), groupId, ActionKeys.SUBSCRIBE);
2678    
2679                    dlAppLocalService.subscribeFolder(getUserId(), groupId, folderId);
2680            }
2681    
2682            /**
2683             * @deprecated As of 6.2.0, replaced by {@link #checkInFileEntry(long,
2684             *             boolean, String, ServiceContext)}.
2685             */
2686            @Override
2687            public void unlockFileEntry(long fileEntryId)
2688                    throws PortalException, SystemException {
2689    
2690                    checkInFileEntry(
2691                            fileEntryId, false, StringPool.BLANK, new ServiceContext());
2692            }
2693    
2694            /**
2695             * @deprecated As of 6.2.0, replaced by {@link #checkInFileEntry(long,
2696             *             String)}.
2697             */
2698            @Override
2699            public void unlockFileEntry(long fileEntryId, String lockUuid)
2700                    throws PortalException, SystemException {
2701    
2702                    checkInFileEntry(fileEntryId, lockUuid);
2703            }
2704    
2705            /**
2706             * Unlocks the folder. This method is primarily used by WebDAV.
2707             *
2708             * @param  repositoryId the primary key of the repository
2709             * @param  folderId the primary key of the folder
2710             * @param  lockUuid the lock's UUID
2711             * @throws PortalException if the repository or folder could not be found
2712             * @throws SystemException if a system exception occurred
2713             */
2714            @Override
2715            public void unlockFolder(long repositoryId, long folderId, String lockUuid)
2716                    throws PortalException, SystemException {
2717    
2718                    Repository repository = getRepository(repositoryId);
2719    
2720                    repository.unlockFolder(folderId, lockUuid);
2721            }
2722    
2723            /**
2724             * Unlocks the folder. This method is primarily used by WebDAV.
2725             *
2726             * @param  repositoryId the primary key of the repository
2727             * @param  parentFolderId the primary key of the parent folder
2728             * @param  name the folder's name
2729             * @param  lockUuid the lock's UUID
2730             * @throws PortalException if the repository or folder could not be found
2731             * @throws SystemException if a system exception occurred
2732             */
2733            @Override
2734            public void unlockFolder(
2735                            long repositoryId, long parentFolderId, String name,
2736                            String lockUuid)
2737                    throws PortalException, SystemException {
2738    
2739                    Repository repository = getRepository(repositoryId);
2740    
2741                    repository.unlockFolder(parentFolderId, name, lockUuid);
2742            }
2743    
2744            /**
2745             * Unsubscribe the user from changes in documents of the file entry type.
2746             * This method is only supported by the Liferay repository.
2747             *
2748             * @param  groupId the primary key of the file entry type's group
2749             * @param  fileEntryTypeId the primary key of the file entry type
2750             * @throws PortalException if the user or group could not be found, or if
2751             *         unsubscribing was not permissible
2752             * @throws SystemException if a system exception occurred
2753             */
2754            @Override
2755            public void unsubscribeFileEntryType(long groupId, long fileEntryTypeId)
2756                    throws PortalException, SystemException {
2757    
2758                    DLPermission.check(
2759                            getPermissionChecker(), groupId, ActionKeys.SUBSCRIBE);
2760    
2761                    dlAppLocalService.unsubscribeFileEntryType(
2762                            getUserId(), groupId, fileEntryTypeId);
2763            }
2764    
2765            /**
2766             * Unsubscribe the user from document changes in the folder. This method is
2767             * only supported by the Liferay repository.
2768             *
2769             * @param  groupId the primary key of the folder's group
2770             * @param  folderId the primary key of the folder
2771             * @throws PortalException if the user or group could not be found, or if
2772             *         unsubscribing was not permissible
2773             * @throws SystemException if a system exception occurred
2774             */
2775            @Override
2776            public void unsubscribeFolder(long groupId, long folderId)
2777                    throws PortalException, SystemException {
2778    
2779                    DLPermission.check(
2780                            getPermissionChecker(), groupId, ActionKeys.SUBSCRIBE);
2781    
2782                    dlAppLocalService.unsubscribeFolder(getUserId(), groupId, folderId);
2783            }
2784    
2785            /**
2786             * Updates a file entry and associated metadata based on a byte array
2787             * object. If the file data is <code>null</code>, then only the associated
2788             * metadata (i.e., <code>title</code>, <code>description</code>, and
2789             * parameters in the <code>serviceContext</code>) will be updated.
2790             *
2791             * <p>
2792             * This method takes two file names, the <code>sourceFileName</code> and the
2793             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
2794             * name of the actual file being uploaded. The <code>title</code>
2795             * corresponds to a name the client wishes to assign this file after it has
2796             * been uploaded to the portal.
2797             * </p>
2798             *
2799             * @param  fileEntryId the primary key of the file entry
2800             * @param  sourceFileName the original file's name (optionally
2801             *         <code>null</code>)
2802             * @param  mimeType the file's MIME type (optionally <code>null</code>)
2803             * @param  title the new name to be assigned to the file (optionally <code>
2804             *         <code>null</code></code>)
2805             * @param  description the file's new description
2806             * @param  changeLog the file's version change log (optionally
2807             *         <code>null</code>)
2808             * @param  majorVersion whether the new file version is a major version
2809             * @param  bytes the file's data (optionally <code>null</code>)
2810             * @param  serviceContext the service context to be applied. Can set the
2811             *         asset category IDs, asset tag names, and expando bridge
2812             *         attributes for the file entry. In a Liferay repository, it may
2813             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
2814             *         type </li> <li> fieldsMap - mapping for fields associated with a
2815             *         custom file entry type </li> </ul>
2816             * @return the file entry
2817             * @throws PortalException if the file entry could not be found
2818             * @throws SystemException if a system exception occurred
2819             */
2820            @Override
2821            public FileEntry updateFileEntry(
2822                            long fileEntryId, String sourceFileName, String mimeType,
2823                            String title, String description, String changeLog,
2824                            boolean majorVersion, byte[] bytes, ServiceContext serviceContext)
2825                    throws PortalException, SystemException {
2826    
2827                    File file = null;
2828    
2829                    try {
2830                            if (ArrayUtil.isNotEmpty(bytes)) {
2831                                    file = FileUtil.createTempFile(bytes);
2832                            }
2833    
2834                            return updateFileEntry(
2835                                    fileEntryId, sourceFileName, mimeType, title, description,
2836                                    changeLog, majorVersion, file, serviceContext);
2837                    }
2838                    catch (IOException ioe) {
2839                            throw new SystemException("Unable to write temporary file", ioe);
2840                    }
2841                    finally {
2842                            FileUtil.delete(file);
2843                    }
2844            }
2845    
2846            /**
2847             * Updates a file entry and associated metadata based on a {@link
2848             * java.io.File} object. If the file data is <code>null</code>, then only
2849             * the associated metadata (i.e., <code>title</code>,
2850             * <code>description</code>, and parameters in the
2851             * <code>serviceContext</code>) will be updated.
2852             *
2853             * <p>
2854             * This method takes two file names, the <code>sourceFileName</code> and the
2855             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
2856             * name of the actual file being uploaded. The <code>title</code>
2857             * corresponds to a name the client wishes to assign this file after it has
2858             * been uploaded to the portal.
2859             * </p>
2860             *
2861             * @param  fileEntryId the primary key of the file entry
2862             * @param  sourceFileName the original file's name (optionally
2863             *         <code>null</code>)
2864             * @param  mimeType the file's MIME type (optionally <code>null</code>)
2865             * @param  title the new name to be assigned to the file (optionally <code>
2866             *         <code>null</code></code>)
2867             * @param  description the file's new description
2868             * @param  changeLog the file's version change log (optionally
2869             *         <code>null</code>)
2870             * @param  majorVersion whether the new file version is a major version
2871             * @param  file EntryId the primary key of the file entry
2872             * @param  serviceContext the service context to be applied. Can set the
2873             *         asset category IDs, asset tag names, and expando bridge
2874             *         attributes for the file entry. In a Liferay repository, it may
2875             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
2876             *         type </li> <li> fieldsMap - mapping for fields associated with a
2877             *         custom file entry type </li> </ul>
2878             * @return the file entry
2879             * @throws PortalException if the file entry could not be found
2880             * @throws SystemException if a system exception occurred
2881             */
2882            @Override
2883            public FileEntry updateFileEntry(
2884                            long fileEntryId, String sourceFileName, String mimeType,
2885                            String title, String description, String changeLog,
2886                            boolean majorVersion, File file, ServiceContext serviceContext)
2887                    throws PortalException, SystemException {
2888    
2889                    if ((file == null) || !file.exists() || (file.length() == 0)) {
2890                            return updateFileEntry(
2891                                    fileEntryId, sourceFileName, mimeType, title, description,
2892                                    changeLog, majorVersion, null, 0, serviceContext);
2893                    }
2894    
2895                    mimeType = DLAppUtil.getMimeType(sourceFileName, mimeType, title, file);
2896    
2897                    Repository repository = getFileEntryRepository(fileEntryId);
2898    
2899                    FileEntry fileEntry = repository.updateFileEntry(
2900                            fileEntryId, sourceFileName, mimeType, title, description,
2901                            changeLog, majorVersion, file, serviceContext);
2902    
2903                    DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
2904    
2905                    dlAppHelperLocalService.updateFileEntry(
2906                            getUserId(), fileEntry, null, fileEntry.getFileVersion(),
2907                            serviceContext);
2908    
2909                    return fileEntry;
2910            }
2911    
2912            /**
2913             * Updates a file entry and associated metadata based on an {@link java.io.
2914             * InputStream} object. If the file data is <code>null</code>, then only the
2915             * associated metadata (i.e., <code>title</code>, <code>description</code>,
2916             * and parameters in the <code>serviceContext</code>) will be updated.
2917             *
2918             * <p>
2919             * This method takes two file names, the <code>sourceFileName</code> and the
2920             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
2921             * name of the actual file being uploaded. The <code>title</code>
2922             * corresponds to a name the client wishes to assign this file after it has
2923             * been uploaded to the portal.
2924             * </p>
2925             *
2926             * @param  fileEntryId the primary key of the file entry
2927             * @param  sourceFileName the original file's name (optionally
2928             *         <code>null</code>)
2929             * @param  mimeType the file's MIME type (optionally <code>null</code>)
2930             * @param  title the new name to be assigned to the file (optionally <code>
2931             *         <code>null</code></code>)
2932             * @param  description the file's new description
2933             * @param  changeLog the file's version change log (optionally
2934             *         <code>null</code>)
2935             * @param  majorVersion whether the new file version is a major version
2936             * @param  is the file's data (optionally <code>null</code>)
2937             * @param  size the file's size (optionally <code>0</code>)
2938             * @param  serviceContext the service context to be applied. Can set the
2939             *         asset category IDs, asset tag names, and expando bridge
2940             *         attributes for the file entry. In a Liferay repository, it may
2941             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
2942             *         type </li> <li> fieldsMap - mapping for fields associated with a
2943             *         custom file entry type </li> </ul>
2944             * @return the file entry
2945             * @throws PortalException if the file entry could not be found
2946             * @throws SystemException if a system exception occurred
2947             */
2948            @Override
2949            public FileEntry updateFileEntry(
2950                            long fileEntryId, String sourceFileName, String mimeType,
2951                            String title, String description, String changeLog,
2952                            boolean majorVersion, InputStream is, long size,
2953                            ServiceContext serviceContext)
2954                    throws PortalException, SystemException {
2955    
2956                    if (Validator.isNull(mimeType) ||
2957                            mimeType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) {
2958    
2959                            String extension = DLAppUtil.getExtension(title, sourceFileName);
2960    
2961                            if (size == 0) {
2962                                    mimeType = MimeTypesUtil.getExtensionContentType(extension);
2963                            }
2964                            else {
2965                                    File file = null;
2966    
2967                                    try {
2968                                            file = FileUtil.createTempFile(is);
2969    
2970                                            return updateFileEntry(
2971                                                    fileEntryId, sourceFileName, mimeType, title,
2972                                                    description, changeLog, majorVersion, file,
2973                                                    serviceContext);
2974                                    }
2975                                    catch (IOException ioe) {
2976                                            throw new SystemException(
2977                                                    "Unable to write temporary file", ioe);
2978                                    }
2979                                    finally {
2980                                            FileUtil.delete(file);
2981                                    }
2982                            }
2983                    }
2984    
2985                    Repository repository = getFileEntryRepository(fileEntryId);
2986    
2987                    FileEntry oldFileEntry = repository.getFileEntry(fileEntryId);
2988    
2989                    FileVersion oldFileVersion = oldFileEntry.getFileVersion();
2990    
2991                    FileEntry fileEntry = repository.updateFileEntry(
2992                            fileEntryId, sourceFileName, mimeType, title, description,
2993                            changeLog, majorVersion, is, size, serviceContext);
2994    
2995                    if (is != null) {
2996                            DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
2997    
2998                            oldFileVersion = null;
2999                    }
3000    
3001                    dlAppHelperLocalService.updateFileEntry(
3002                            getUserId(), fileEntry, oldFileVersion, fileEntry.getFileVersion(),
3003                            serviceContext);
3004    
3005                    return fileEntry;
3006            }
3007    
3008            @Override
3009            public FileEntry updateFileEntryAndCheckIn(
3010                            long fileEntryId, String sourceFileName, String mimeType,
3011                            String title, String description, String changeLog,
3012                            boolean majorVersion, File file, ServiceContext serviceContext)
3013                    throws PortalException, SystemException {
3014    
3015                    if ((file == null) || !file.exists() || (file.length() == 0)) {
3016                            return updateFileEntryAndCheckIn(
3017                                    fileEntryId, sourceFileName, mimeType, title, description,
3018                                    changeLog, majorVersion, null, 0, serviceContext);
3019                    }
3020    
3021                    Repository repository = getFileEntryRepository(fileEntryId);
3022    
3023                    FileEntry fileEntry = repository.updateFileEntry(
3024                            fileEntryId, sourceFileName, mimeType, title, description,
3025                            changeLog, majorVersion, file, serviceContext);
3026    
3027                    DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
3028    
3029                    repository.checkInFileEntry(
3030                            fileEntryId, majorVersion, changeLog, serviceContext);
3031    
3032                    dlAppHelperLocalService.updateFileEntry(
3033                            getUserId(), fileEntry, null, fileEntry.getFileVersion(),
3034                            serviceContext);
3035    
3036                    return fileEntry;
3037            }
3038    
3039            @Override
3040            public FileEntry updateFileEntryAndCheckIn(
3041                            long fileEntryId, String sourceFileName, String mimeType,
3042                            String title, String description, String changeLog,
3043                            boolean majorVersion, InputStream is, long size,
3044                            ServiceContext serviceContext)
3045                    throws PortalException, SystemException {
3046    
3047                    Repository repository = getFileEntryRepository(fileEntryId);
3048    
3049                    FileEntry oldFileEntry = repository.getFileEntry(fileEntryId);
3050    
3051                    FileVersion oldFileVersion = oldFileEntry.getFileVersion();
3052    
3053                    FileEntry fileEntry = repository.updateFileEntry(
3054                            fileEntryId, sourceFileName, mimeType, title, description,
3055                            changeLog, majorVersion, is, size, serviceContext);
3056    
3057                    if (is != null) {
3058                            DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
3059    
3060                            oldFileVersion = null;
3061                    }
3062    
3063                    repository.checkInFileEntry(
3064                            fileEntryId, majorVersion, changeLog, serviceContext);
3065    
3066                    dlAppHelperLocalService.updateFileEntry(
3067                            getUserId(), fileEntry, oldFileVersion, fileEntry.getFileVersion(),
3068                            serviceContext);
3069    
3070                    return fileEntry;
3071            }
3072    
3073            /**
3074             * Updates a file shortcut to the existing file entry. This method is only
3075             * supported by the Liferay repository.
3076             *
3077             * @param  fileShortcutId the primary key of the file shortcut
3078             * @param  folderId the primary key of the file shortcut's parent folder
3079             * @param  toFileEntryId the primary key of the file shortcut's file entry
3080             * @param  serviceContext the service context to be applied. Can set the
3081             *         asset category IDs, asset tag names, and expando bridge
3082             *         attributes for the file entry.
3083             * @return the file shortcut
3084             * @throws PortalException if the file shortcut, folder, or file entry could
3085             *         not be found
3086             * @throws SystemException if a system exception occurred
3087             */
3088            @Override
3089            public DLFileShortcut updateFileShortcut(
3090                            long fileShortcutId, long folderId, long toFileEntryId,
3091                            ServiceContext serviceContext)
3092                    throws PortalException, SystemException {
3093    
3094                    return dlFileShortcutService.updateFileShortcut(
3095                            fileShortcutId, folderId, toFileEntryId, serviceContext);
3096            }
3097    
3098            /**
3099             * Updates the folder.
3100             *
3101             * @param  folderId the primary key of the folder
3102             * @param  name the folder's new name
3103             * @param  description the folder's new description
3104             * @param  serviceContext the service context to be applied. In a Liferay
3105             *         repository, it may include:  <ul> <li> defaultFileEntryTypeId -
3106             *         the file entry type to default all Liferay file entries to </li>
3107             *         <li> dlFileEntryTypesSearchContainerPrimaryKeys - a
3108             *         comma-delimited list of file entry type primary keys allowed in
3109             *         the given folder and all descendants </li> <li>
3110             *         overrideFileEntryTypes - boolean specifying whether to override
3111             *         ancestral folder's restriction of file entry types allowed </li>
3112             *         <li> workflowDefinitionXYZ - the workflow definition name
3113             *         specified per file entry type. The parameter name must be the
3114             *         string <code>workflowDefinition</code> appended by the <code>
3115             *         fileEntryTypeId</code> (optionally <code>0</code>). </li> </ul>
3116             * @return the folder
3117             * @throws PortalException if the current or new parent folder could not be
3118             *         found or if the new parent folder's information was invalid
3119             * @throws SystemException if a system exception occurred
3120             */
3121            @Override
3122            public Folder updateFolder(
3123                            long folderId, String name, String description,
3124                            ServiceContext serviceContext)
3125                    throws PortalException, SystemException {
3126    
3127                    Repository repository = null;
3128    
3129                    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
3130                            repository = getRepository(serviceContext.getScopeGroupId());
3131                    }
3132                    else {
3133                            repository = getFolderRepository(folderId);
3134                    }
3135    
3136                    return repository.updateFolder(
3137                            folderId, name, description, serviceContext);
3138            }
3139    
3140            /**
3141             * Returns <code>true</code> if the file entry is checked out. This method
3142             * is primarily used by WebDAV.
3143             *
3144             * @param  repositoryId the primary key for the repository
3145             * @param  fileEntryId the primary key for the file entry
3146             * @param  lockUuid the lock's UUID
3147             * @return <code>true</code> if the file entry is checked out;
3148             *         <code>false</code> otherwise
3149             * @throws PortalException if the file entry could not be found
3150             * @throws SystemException if a system exception occurred
3151             */
3152            @Override
3153            public boolean verifyFileEntryCheckOut(
3154                            long repositoryId, long fileEntryId, String lockUuid)
3155                    throws PortalException, SystemException {
3156    
3157                    Repository repository = getRepository(repositoryId);
3158    
3159                    return repository.verifyFileEntryCheckOut(fileEntryId, lockUuid);
3160            }
3161    
3162            @Override
3163            public boolean verifyFileEntryLock(
3164                            long repositoryId, long fileEntryId, String lockUuid)
3165                    throws PortalException, SystemException {
3166    
3167                    Repository repository = getRepository(repositoryId);
3168    
3169                    return repository.verifyFileEntryLock(fileEntryId, lockUuid);
3170            }
3171    
3172            /**
3173             * Returns <code>true</code> if the inheritable lock exists. This method is
3174             * primarily used by WebDAV.
3175             *
3176             * @param  repositoryId the primary key for the repository
3177             * @param  folderId the primary key for the folder
3178             * @param  lockUuid the lock's UUID
3179             * @return <code>true</code> if the inheritable lock exists;
3180             *         <code>false</code> otherwise
3181             * @throws PortalException if the folder could not be found
3182             * @throws SystemException if a system exception occurred
3183             */
3184            @Override
3185            public boolean verifyInheritableLock(
3186                            long repositoryId, long folderId, String lockUuid)
3187                    throws PortalException, SystemException {
3188    
3189                    Repository repository = getRepository(repositoryId);
3190    
3191                    return repository.verifyInheritableLock(folderId, lockUuid);
3192            }
3193    
3194            protected FileEntry copyFileEntry(
3195                            Repository toRepository, FileEntry fileEntry, long newFolderId,
3196                            ServiceContext serviceContext)
3197                    throws PortalException, SystemException {
3198    
3199                    List<FileVersion> fileVersions = fileEntry.getFileVersions(
3200                            WorkflowConstants.STATUS_ANY);
3201    
3202                    FileVersion latestFileVersion = fileVersions.get(
3203                            fileVersions.size() - 1);
3204    
3205                    FileEntry destinationFileEntry = toRepository.addFileEntry(
3206                            newFolderId, fileEntry.getTitle(), latestFileVersion.getMimeType(),
3207                            latestFileVersion.getTitle(), latestFileVersion.getDescription(),
3208                            StringPool.BLANK, latestFileVersion.getContentStream(false),
3209                            latestFileVersion.getSize(), serviceContext);
3210    
3211                    FileVersion oldDestinationFileVersion =
3212                            destinationFileEntry.getFileVersion();
3213    
3214                    dlAppHelperLocalService.addFileEntry(
3215                            getUserId(), destinationFileEntry, oldDestinationFileVersion,
3216                            serviceContext);
3217    
3218                    for (int i = fileVersions.size() - 2; i >= 0; i--) {
3219                            FileVersion fileVersion = fileVersions.get(i);
3220    
3221                            FileVersion previousFileVersion = fileVersions.get(i + 1);
3222    
3223                            try {
3224                                    destinationFileEntry = toRepository.updateFileEntry(
3225                                            destinationFileEntry.getFileEntryId(),
3226                                            fileVersion.getTitle(), fileVersion.getMimeType(),
3227                                            fileVersion.getTitle(), fileVersion.getDescription(),
3228                                            StringPool.BLANK,
3229                                            DLAppUtil.isMajorVersion(previousFileVersion, fileVersion),
3230                                            fileVersion.getContentStream(false), fileVersion.getSize(),
3231                                            serviceContext);
3232    
3233                                    FileVersion destinationFileVersion =
3234                                            destinationFileEntry.getFileVersion();
3235    
3236                                    dlAppHelperLocalService.updateFileEntry(
3237                                            getUserId(), destinationFileEntry,
3238                                            oldDestinationFileVersion, destinationFileVersion,
3239                                            serviceContext);
3240    
3241                                    oldDestinationFileVersion = destinationFileVersion;
3242                            }
3243                            catch (PortalException pe) {
3244                                    toRepository.deleteFileEntry(
3245                                            destinationFileEntry.getFileEntryId());
3246    
3247                                    throw pe;
3248                            }
3249                    }
3250    
3251                    return destinationFileEntry;
3252            }
3253    
3254            protected void copyFolder(
3255                            Repository repository, Folder srcFolder, Folder destFolder,
3256                            ServiceContext serviceContext)
3257                    throws PortalException, SystemException {
3258    
3259                    Queue<Folder[]> folders = new LinkedList<Folder[]>();
3260                    final List<FileEntry> fileEntries = new ArrayList<FileEntry>();
3261    
3262                    Folder curSrcFolder = srcFolder;
3263                    Folder curDestFolder = destFolder;
3264    
3265                    while (true) {
3266                            List<FileEntry> srcFileEntries = repository.getFileEntries(
3267                                    curSrcFolder.getFolderId(), QueryUtil.ALL_POS,
3268                                    QueryUtil.ALL_POS, null);
3269    
3270                            for (FileEntry srcFileEntry : srcFileEntries) {
3271                                    try {
3272                                            FileEntry fileEntry = repository.copyFileEntry(
3273                                                    curDestFolder.getGroupId(),
3274                                                    srcFileEntry.getFileEntryId(),
3275                                                    curDestFolder.getFolderId(), serviceContext);
3276    
3277                                            dlAppHelperLocalService.addFileEntry(
3278                                                    getUserId(), fileEntry, fileEntry.getFileVersion(),
3279                                                    serviceContext);
3280    
3281                                            fileEntries.add(fileEntry);
3282                                    }
3283                                    catch (Exception e) {
3284                                            _log.error(e, e);
3285    
3286                                            continue;
3287                                    }
3288                            }
3289    
3290                            List<Folder> srcSubfolders = repository.getFolders(
3291                                    curSrcFolder.getFolderId(), false, QueryUtil.ALL_POS,
3292                                    QueryUtil.ALL_POS, null);
3293    
3294                            for (Folder srcSubfolder : srcSubfolders) {
3295                                    Folder destSubfolder = repository.addFolder(
3296                                            curDestFolder.getFolderId(), srcSubfolder.getName(),
3297                                            srcSubfolder.getDescription(), serviceContext);
3298    
3299                                    folders.offer(new Folder[] {srcSubfolder, destSubfolder});
3300                            }
3301    
3302                            Folder[] next = folders.poll();
3303    
3304                            if (next == null) {
3305                                    break;
3306                            }
3307                            else {
3308                                    curSrcFolder = next[0];
3309                                    curDestFolder = next[1];
3310                            }
3311                    }
3312    
3313                    TransactionCommitCallbackRegistryUtil.registerCallback(
3314                            new Callable<Void>() {
3315    
3316                                    @Override
3317                                    public Void call() throws Exception {
3318                                            for (FileEntry fileEntry : fileEntries) {
3319                                                    DLProcessorRegistryUtil.trigger(fileEntry, null);
3320                                            }
3321    
3322                                            return null;
3323                                    }
3324    
3325                            });
3326            }
3327    
3328            protected void deleteFileEntry(
3329                            long oldFileEntryId, long newFileEntryId, Repository fromRepository,
3330                            Repository toRepository)
3331                    throws PortalException, SystemException {
3332    
3333                    try {
3334                            FileEntry fileEntry = fromRepository.getFileEntry(oldFileEntryId);
3335    
3336                            dlAppHelperLocalService.deleteFileEntry(fileEntry);
3337    
3338                            fromRepository.deleteFileEntry(oldFileEntryId);
3339                    }
3340                    catch (PortalException pe) {
3341                            FileEntry fileEntry = toRepository.getFileEntry(newFileEntryId);
3342    
3343                            toRepository.deleteFileEntry(newFileEntryId);
3344    
3345                            dlAppHelperLocalService.deleteFileEntry(fileEntry);
3346    
3347                            throw pe;
3348                    }
3349            }
3350    
3351            protected Repository getFileEntryRepository(long fileEntryId)
3352                    throws PortalException, SystemException {
3353    
3354                    try {
3355                            return repositoryService.getRepositoryImpl(0, fileEntryId, 0);
3356                    }
3357                    catch (InvalidRepositoryIdException irie) {
3358                            StringBundler sb = new StringBundler(3);
3359    
3360                            sb.append("No FileEntry exists with the key {fileEntryId=");
3361                            sb.append(fileEntryId);
3362                            sb.append("}");
3363    
3364                            throw new NoSuchFileEntryException(sb.toString(), irie);
3365                    }
3366            }
3367    
3368            protected Repository getFileVersionRepository(long fileVersionId)
3369                    throws PortalException, SystemException {
3370    
3371                    try {
3372                            return repositoryService.getRepositoryImpl(0, 0, fileVersionId);
3373                    }
3374                    catch (InvalidRepositoryIdException irie) {
3375                            StringBundler sb = new StringBundler(3);
3376    
3377                            sb.append("No FileVersion exists with the key {fileVersionId=");
3378                            sb.append(fileVersionId);
3379                            sb.append("}");
3380    
3381                            throw new NoSuchFileVersionException(sb.toString(), irie);
3382                    }
3383            }
3384    
3385            protected Repository getFolderRepository(long folderId)
3386                    throws PortalException, SystemException {
3387    
3388                    try {
3389                            return repositoryService.getRepositoryImpl(folderId, 0, 0);
3390                    }
3391                    catch (InvalidRepositoryIdException irie) {
3392                            StringBundler sb = new StringBundler(3);
3393    
3394                            sb.append("No Folder exists with the key {folderId=");
3395                            sb.append(folderId);
3396                            sb.append("}");
3397    
3398                            throw new NoSuchFolderException(sb.toString(), irie);
3399                    }
3400            }
3401    
3402            protected Repository getFolderRepository(long folderId, long groupId)
3403                    throws PortalException, SystemException {
3404    
3405                    Repository repository = null;
3406    
3407                    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
3408                            repository = getRepository(groupId);
3409                    }
3410                    else {
3411                            repository = getFolderRepository(folderId);
3412                    }
3413    
3414                    return repository;
3415            }
3416    
3417            protected Repository getRepository(long repositoryId)
3418                    throws PortalException, SystemException {
3419    
3420                    try {
3421                            return repositoryService.getRepositoryImpl(repositoryId);
3422                    }
3423                    catch (InvalidRepositoryIdException irie) {
3424                            StringBundler sb = new StringBundler(3);
3425    
3426                            sb.append("No Group exists with the key {repositoryId=");
3427                            sb.append(repositoryId);
3428                            sb.append("}");
3429    
3430                            throw new NoSuchGroupException(sb.toString(), irie);
3431                    }
3432            }
3433    
3434            protected FileEntry moveFileEntries(
3435                            long fileEntryId, long newFolderId, Repository fromRepository,
3436                            Repository toRepository, ServiceContext serviceContext)
3437                    throws PortalException, SystemException {
3438    
3439                    FileEntry sourceFileEntry = fromRepository.getFileEntry(fileEntryId);
3440    
3441                    FileEntry destinationFileEntry = copyFileEntry(
3442                            toRepository, sourceFileEntry, newFolderId, serviceContext);
3443    
3444                    deleteFileEntry(
3445                            fileEntryId, destinationFileEntry.getFileEntryId(), fromRepository,
3446                            toRepository);
3447    
3448                    return destinationFileEntry;
3449            }
3450    
3451            protected Folder moveFolders(
3452                            long folderId, long parentFolderId, Repository fromRepository,
3453                            Repository toRepository, ServiceContext serviceContext)
3454                    throws PortalException, SystemException {
3455    
3456                    Folder folder = fromRepository.getFolder(folderId);
3457    
3458                    Folder newFolder = toRepository.addFolder(
3459                            parentFolderId, folder.getName(), folder.getDescription(),
3460                            serviceContext);
3461    
3462                    List<Object> foldersAndFileEntriesAndFileShortcuts =
3463                            getFoldersAndFileEntriesAndFileShortcuts(
3464                                    fromRepository.getRepositoryId(), folderId,
3465                                    WorkflowConstants.STATUS_ANY, true, QueryUtil.ALL_POS,
3466                                    QueryUtil.ALL_POS);
3467    
3468                    try {
3469                            for (Object folderAndFileEntryAndFileShortcut :
3470                                            foldersAndFileEntriesAndFileShortcuts) {
3471    
3472                                    if (folderAndFileEntryAndFileShortcut instanceof FileEntry) {
3473                                            FileEntry fileEntry =
3474                                                    (FileEntry)folderAndFileEntryAndFileShortcut;
3475    
3476                                            copyFileEntry(
3477                                                    toRepository, fileEntry, newFolder.getFolderId(),
3478                                                    serviceContext);
3479                                    }
3480                                    else if (folderAndFileEntryAndFileShortcut instanceof Folder) {
3481                                            Folder currentFolder =
3482                                                    (Folder)folderAndFileEntryAndFileShortcut;
3483    
3484                                            moveFolders(
3485                                                    currentFolder.getFolderId(), newFolder.getFolderId(),
3486                                                    fromRepository, toRepository, serviceContext);
3487                                    }
3488                                    else if (folderAndFileEntryAndFileShortcut
3489                                                            instanceof DLFileShortcut) {
3490    
3491                                            if (newFolder.isSupportsShortcuts()) {
3492                                                    DLFileShortcut dlFileShorcut =
3493                                                            (DLFileShortcut)folderAndFileEntryAndFileShortcut;
3494    
3495                                                    dlFileShortcutService.addFileShortcut(
3496                                                            dlFileShorcut.getGroupId(), newFolder.getFolderId(),
3497                                                            dlFileShorcut.getToFileEntryId(), serviceContext);
3498                                            }
3499                                    }
3500                            }
3501                    }
3502                    catch (PortalException pe) {
3503                            toRepository.deleteFolder(newFolder.getFolderId());
3504    
3505                            throw pe;
3506                    }
3507    
3508                    try {
3509                            fromRepository.deleteFolder(folderId);
3510                    }
3511                    catch (PortalException pe) {
3512                            toRepository.deleteFolder(newFolder.getFolderId());
3513    
3514                            throw pe;
3515                    }
3516    
3517                    return newFolder;
3518            }
3519    
3520            private static Log _log = LogFactoryUtil.getLog(DLAppServiceImpl.class);
3521    
3522    }