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