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