001    /**
002     * Copyright (c) 2000-2012 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.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
021    import com.liferay.portal.kernel.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    import com.liferay.portal.kernel.repository.Repository;
024    import com.liferay.portal.kernel.repository.model.FileEntry;
025    import com.liferay.portal.kernel.repository.model.FileVersion;
026    import com.liferay.portal.kernel.repository.model.Folder;
027    import com.liferay.portal.kernel.search.Hits;
028    import com.liferay.portal.kernel.search.Query;
029    import com.liferay.portal.kernel.search.SearchContext;
030    import com.liferay.portal.kernel.search.SearchException;
031    import com.liferay.portal.kernel.util.FileUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.TempFileUtil;
037    import com.liferay.portal.kernel.workflow.WorkflowConstants;
038    import com.liferay.portal.model.Lock;
039    import com.liferay.portal.security.permission.ActionKeys;
040    import com.liferay.portal.service.ServiceContext;
041    import com.liferay.portal.spring.transaction.TransactionCommitCallbackUtil;
042    import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
043    import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
044    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
045    import com.liferay.portlet.documentlibrary.service.base.DLAppServiceBaseImpl;
046    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
047    import com.liferay.portlet.documentlibrary.util.DLProcessorRegistryUtil;
048    import com.liferay.portlet.documentlibrary.util.comparator.RepositoryModelModifiedDateComparator;
049    
050    import java.io.File;
051    import java.io.IOException;
052    import java.io.InputStream;
053    
054    import java.util.ArrayList;
055    import java.util.LinkedList;
056    import java.util.List;
057    import java.util.Queue;
058    import java.util.concurrent.Callable;
059    
060    /**
061     * The document library remote service. All portlets should interact with the
062     * document library through this class or through {@link DLAppLocalServiceImpl},
063     * rather than through the individual document library service classes.
064     *
065     * <p>
066     * This class provides a unified interface to all Liferay and third party
067     * repositories. While the method signatures are universal for all repositories.
068     * Additional implementation-specific parameters may be specified in the
069     * serviceContext.
070     * </p>
071     *
072     * <p>
073     * The <code>repositoryId</code> parameter used by most of the methods is the
074     * primary key of the specific repository. If the repository is a default
075     * Liferay repository, the <code>repositoryId</code> is the <code>groupId</code>
076     * or <code>scopeGroupId</code>. Otherwise, the <code>repositoryId</code> will
077     * correspond to values obtained from {@link RepositoryServiceUtil}.
078     * </p>
079     *
080     * @author Alexander Chow
081     * @author Mika Koivisto
082     * @author Shuyang Zhou
083     * @see    DLAppLocalServiceImpl
084     */
085    public class DLAppServiceImpl extends DLAppServiceBaseImpl {
086    
087            /**
088             * Adds a file entry and associated metadata. It is created based on a byte
089             * array.
090             *
091             * <p>
092             * This method takes two file names, the <code>sourceFileName</code> and the
093             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
094             * name of the actual file being uploaded. The <code>title</code>
095             * corresponds to a name the client wishes to assign this file after it has
096             * been uploaded to the portal. If it is <code>null</code>, the <code>
097             * sourceFileName</code> will be used.
098             * </p>
099             *
100             * @param  repositoryId the primary key of the repository
101             * @param  folderId the primary key of the file entry's parent folder
102             * @param  sourceFileName the original file's name
103             * @param  mimeType the file's MIME type
104             * @param  title the name to be assigned to the file (optionally <code>null
105             *         </code>)
106             * @param  description the file's description
107             * @param  changeLog the file's version change log
108             * @param  bytes the file's data (optionally <code>null</code>)
109             * @param  serviceContext the service context to be applied. Can set the
110             *         asset category IDs, asset tag names, and expando bridge
111             *         attributes for the file entry. In a Liferay repository, it may
112             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
113             *         type </li> <li> fieldsMap - mapping for fields associated with a
114             *         custom file entry type </li> </ul>
115             * @return the file entry
116             * @throws PortalException if the parent folder could not be found or if the
117             *         file entry's information was invalid
118             * @throws SystemException if a system exception occurred
119             */
120            public FileEntry addFileEntry(
121                            long repositoryId, long folderId, String sourceFileName,
122                            String mimeType, String title, String description, String changeLog,
123                            byte[] bytes, ServiceContext serviceContext)
124                    throws PortalException, SystemException {
125    
126                    File file = null;
127    
128                    try {
129                            if ((bytes != null) && (bytes.length > 0)) {
130                                    file = FileUtil.createTempFile(bytes);
131                            }
132    
133                            return addFileEntry(
134                                    repositoryId, folderId, sourceFileName, mimeType, title,
135                                    description, changeLog, file, serviceContext);
136                    }
137                    catch (IOException ioe) {
138                            throw new SystemException("Unable to write temporary file", ioe);
139                    }
140                    finally {
141                            FileUtil.delete(file);
142                    }
143            }
144    
145            /**
146             * Adds a file entry and associated metadata. It is created based on a
147             * {@link File} object.
148             *
149             * <p>
150             * This method takes two file names, the <code>sourceFileName</code> and the
151             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
152             * name of the actual file being uploaded. The <code>title</code>
153             * corresponds to a name the client wishes to assign this file after it has
154             * been uploaded to the portal. If it is <code>null</code>, the <code>
155             * sourceFileName</code> will be used.
156             * </p>
157             *
158             * @param  repositoryId the primary key of the repository
159             * @param  folderId the primary key of the file entry's parent folder
160             * @param  sourceFileName the original file's name
161             * @param  mimeType the file's MIME type
162             * @param  title the name to be assigned to the file (optionally <code>null
163             *         </code>)
164             * @param  description the file's description
165             * @param  changeLog the file's version change log
166             * @param  file the file's data (optionally <code>null</code>)
167             * @param  serviceContext the service context to be applied. Can set the
168             *         asset category IDs, asset tag names, and expando bridge
169             *         attributes for the file entry. In a Liferay repository, it may
170             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
171             *         type </li> <li> fieldsMap - mapping for fields associated with a
172             *         custom file entry type </li> </ul>
173             * @return the file entry
174             * @throws PortalException if the parent folder could not be found or if the
175             *         file entry's information was invalid
176             * @throws SystemException if a system exception occurred
177             */
178            public FileEntry addFileEntry(
179                            long repositoryId, long folderId, String sourceFileName,
180                            String mimeType, String title, String description, String changeLog,
181                            File file, ServiceContext serviceContext)
182                    throws PortalException, SystemException {
183    
184                    if ((file == null) || !file.exists() || (file.length() == 0)) {
185                            return addFileEntry(
186                                    repositoryId, folderId, sourceFileName, mimeType, title,
187                                    description, changeLog, null, 0, serviceContext);
188                    }
189    
190                    Repository repository = getRepository(repositoryId);
191    
192                    FileEntry fileEntry = repository.addFileEntry(
193                            folderId, sourceFileName, mimeType, title, description, changeLog,
194                            file, serviceContext);
195    
196                    dlAppHelperLocalService.addFileEntry(
197                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
198    
199                    return fileEntry;
200            }
201    
202            /**
203             * Adds a file entry and associated metadata. It is created based on a
204             * {@link InputStream} object.
205             *
206             * <p>
207             * This method takes two file names, the <code>sourceFileName</code> and the
208             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
209             * name of the actual file being uploaded. The <code>title</code>
210             * corresponds to a name the client wishes to assign this file after it has
211             * been uploaded to the portal. If it is <code>null</code>, the <code>
212             * sourceFileName</code> will be used.
213             * </p>
214             *
215             * @param  repositoryId the primary key of the repository
216             * @param  folderId the primary key of the file entry's parent folder
217             * @param  sourceFileName the original file's name
218             * @param  mimeType the file's MIME type
219             * @param  title the name to be assigned to the file (optionally <code>null
220             *         </code>)
221             * @param  description the file's description
222             * @param  changeLog the file's version change log
223             * @param  is the file's data (optionally <code>null</code>)
224             * @param  size the file's size (optionally <code>0</code>)
225             * @param  serviceContext the service context to be applied. Can set the
226             *         asset category IDs, asset tag names, and expando bridge
227             *         attributes for the file entry. In a Liferay repository, it may
228             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
229             *         type </li> <li> fieldsMap - mapping for fields associated with a
230             *         custom file entry type </li> </ul>
231             * @return the file entry
232             * @throws PortalException if the parent folder could not be found or if the
233             *         file entry's information was invalid
234             * @throws SystemException if a system exception occurred
235             */
236            public FileEntry addFileEntry(
237                            long repositoryId, long folderId, String sourceFileName,
238                            String mimeType, String title, String description, String changeLog,
239                            InputStream is, long size, ServiceContext serviceContext)
240                    throws PortalException, SystemException {
241    
242                    if (is == null) {
243                            is = new UnsyncByteArrayInputStream(new byte[0]);
244                            size = 0;
245                    }
246    
247                    Repository repository = getRepository(repositoryId);
248    
249                    FileEntry fileEntry = repository.addFileEntry(
250                            folderId, sourceFileName, mimeType, title, description, changeLog,
251                            is, size, serviceContext);
252    
253                    dlAppHelperLocalService.addFileEntry(
254                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
255    
256                    return fileEntry;
257            }
258    
259            /**
260             * Adds a file shortcut to the existing file entry. This method is only
261             * supported by the Liferay repository.
262             *
263             * @param  repositoryId the primary key of the repository
264             * @param  folderId the primary key of the file shortcut's parent folder
265             * @param  toFileEntryId the primary key of the file shortcut's file entry
266             * @param  serviceContext the service context to be applied. Can set the
267             *         asset category IDs, asset tag names, and expando bridge
268             *         attributes for the file entry.
269             * @return the file shortcut
270             * @throws PortalException if the parent folder or file entry could not be
271             *         found, or if the file shortcut's information was invalid
272             * @throws SystemException if a system exception occurred
273             */
274            public DLFileShortcut addFileShortcut(
275                            long repositoryId, long folderId, long toFileEntryId,
276                            ServiceContext serviceContext)
277                    throws PortalException, SystemException {
278    
279                    return dlFileShortcutService.addFileShortcut(
280                            repositoryId, folderId, toFileEntryId, serviceContext);
281            }
282    
283            /**
284             * Adds a folder.
285             *
286             * @param  repositoryId the primary key of the repository
287             * @param  parentFolderId the primary key of the folder's parent folder
288             * @param  name the folder's name
289             * @param  description the folder's description
290             * @param  serviceContext the service context to be applied. In a Liferay
291             *         repository, it may include boolean mountPoint specifying whether
292             *         folder is a facade for mounting a third-party repository
293             * @return the folder
294             * @throws PortalException if the parent folder could not be found or if the
295             *         new folder's information was invalid
296             * @throws SystemException if a system exception occurred
297             */
298            public Folder addFolder(
299                            long repositoryId, long parentFolderId, String name,
300                            String description, ServiceContext serviceContext)
301                    throws PortalException, SystemException {
302    
303                    Repository repository = getRepository(repositoryId);
304    
305                    return repository.addFolder(
306                            parentFolderId, name, description, serviceContext);
307            }
308    
309            /**
310             * Adds a temporary file entry.
311             *
312             * <p>
313             * This allows a client to upload a file into a temporary location and
314             * manipulate its metadata prior to making it available for public usage.
315             * This is different from checking in and checking out a file entry.
316             * </p>
317             *
318             * @param  groupId the primary key of the group
319             * @param  folderId the primary key of the folder where the file entry will
320             *         eventually reside
321             * @param  fileName the file's original name
322             * @param  tempFolderName the temporary folder's name
323             * @param  file Name the file's original name
324             * @return the file's name
325             * @throws IOException if a problem occurred in the access or storage of the
326             *         file
327             * @throws PortalException if the file name was invalid
328             * @throws SystemException if a system exception occurred
329             * @see    com.liferay.portal.kernel.util.TempFileUtil
330             */
331            public String addTempFileEntry(
332                            long groupId, long folderId, String fileName, String tempFolderName,
333                            File file)
334                    throws IOException, PortalException, SystemException {
335    
336                    DLFolderPermission.check(
337                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
338    
339                    return TempFileUtil.addTempFile(
340                            getUserId(), fileName, tempFolderName, file);
341            }
342    
343            public String addTempFileEntry(
344                            long groupId, long folderId, String fileName, String tempFolderName,
345                            InputStream inputStream)
346                    throws IOException, PortalException, SystemException {
347    
348                    DLFolderPermission.check(
349                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
350    
351                    return TempFileUtil.addTempFile(
352                            getUserId(), fileName, tempFolderName, inputStream);
353            }
354    
355            /**
356             * Cancels the check out of the file entry. If a user has not checked out
357             * the specified file entry, invoking this method will result in no changes.
358             *
359             * <p>
360             * When a file entry is checked out, a PWC (private working copy) is created
361             * and the original file entry is locked. A client can make as many changes
362             * to the PWC as he desires without those changes being visible to other
363             * users. If the user is satisfied with the changes, he may elect to check
364             * in his changes, resulting in a new file version based on the PWC; the PWC
365             * will be removed and the file entry will be unlocked. If the user is not
366             * satisfied with the changes, he may elect to cancel his check out; this
367             * results in the deletion of the PWC and unlocking of the file entry.
368             * </p>
369             *
370             * @param  fileEntryId the primary key of the file entry to cancel the
371             *         checkout
372             * @throws PortalException if the file entry could not be found
373             * @throws SystemException if a system exception occurred
374             * @see    #checkInFileEntry(long, boolean, String, ServiceContext)
375             * @see    #checkOutFileEntry(long)
376             */
377            public void cancelCheckOut(long fileEntryId)
378                    throws PortalException, SystemException {
379    
380                    Repository repository = getRepository(0, fileEntryId, 0);
381    
382                    FileEntry fileEntry = repository.getFileEntry(fileEntryId);
383    
384                    DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
385    
386                    repository.cancelCheckOut(fileEntryId);
387    
388                    ServiceContext serviceContext = new ServiceContext();
389    
390                    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
391    
392                    dlAppHelperLocalService.updateFileEntry(
393                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
394            }
395    
396            /**
397             * Checks in the file entry. If a user has not checked out the specified
398             * file entry, invoking this method will result in no changes.
399             *
400             * <p>
401             * When a file entry is checked out, a PWC (private working copy) is created
402             * and the original file entry is locked. A client can make as many changes
403             * to the PWC as he desires without those changes being visible to other
404             * users. If the user is satisfied with the changes, he may elect to check
405             * in his changes, resulting in a new file version based on the PWC; the PWC
406             * will be removed and the file entry will be unlocked. If the user is not
407             * satisfied with the changes, he may elect to cancel his check out; this
408             * results in the deletion of the PWC and unlocking of the file entry.
409             * </p>
410             *
411             * @param  fileEntryId the primary key of the file entry to check in
412             * @param  majorVersion whether the new file version is a major version
413             * @param  changeLog the file's version change log
414             * @param  serviceContext the service context to be applied
415             * @throws PortalException if the file entry could not be found
416             * @throws SystemException if a system exception occurred
417             * @see    #cancelCheckOut(long)
418             * @see    #checkOutFileEntry(long)
419             */
420            public void checkInFileEntry(
421                            long fileEntryId, boolean majorVersion, String changeLog,
422                            ServiceContext serviceContext)
423                    throws PortalException, SystemException {
424    
425                    Repository repository = getRepository(0, fileEntryId, 0);
426    
427                    repository.checkInFileEntry(
428                            fileEntryId, majorVersion, changeLog, serviceContext);
429    
430                    FileEntry fileEntry = getFileEntry(fileEntryId);
431    
432                    FileVersion fileVersion = fileEntry.getLatestFileVersion();
433    
434                    dlAppHelperLocalService.updateFileEntry(
435                            getUserId(), fileEntry, fileVersion,
436                            fileVersion.getFileVersionId());
437            }
438    
439            /**
440             * Checks in the file entry using the lock's UUID. If a user has not checked
441             * out the specified file entry, invoking this method will result in no
442             * changes. This method is primarily used by WebDAV.
443             *
444             * <p>
445             * When a file entry is checked out, a PWC (private working copy) is created
446             * and the original file entry is locked. A client can make as many changes
447             * to the PWC as he desires without those changes being visible to other
448             * users. If the user is satisfied with the changes, he may elect to check
449             * in his changes, resulting in a new file version based on the PWC; the PWC
450             * will be removed and the file entry will be unlocked. If the user is not
451             * satisfied with the changes, he may elect to cancel his check out; this
452             * results in the deletion of the PWC and unlocking of the file entry.
453             * </p>
454             *
455             * @param  fileEntryId the primary key of the file entry to check in
456             * @param  lockUuid the lock's universally unique identifier
457             * @throws PortalException if the file entry could not be found
458             * @throws SystemException if a system exception occurred
459             * @see    #cancelCheckOut(long)
460             * @see    #checkOutFileEntry(long, String, long)
461             */
462            public void checkInFileEntry(long fileEntryId, String lockUuid)
463                    throws PortalException, SystemException {
464    
465                    Repository repository = getRepository(0, fileEntryId, 0);
466    
467                    repository.checkInFileEntry(fileEntryId, lockUuid);
468    
469                    FileEntry fileEntry = getFileEntry(fileEntryId);
470    
471                    FileVersion fileVersion = fileEntry.getLatestFileVersion();
472    
473                    dlAppHelperLocalService.updateFileEntry(
474                            getUserId(), fileEntry, fileVersion,
475                            fileVersion.getFileVersionId());
476            }
477    
478            /**
479             * Check out a file entry.
480             *
481             * <p>
482             * When a file entry is checked out, a PWC (private working copy) is created
483             * and the original file entry is locked. A client can make as many changes
484             * to the PWC as he desires without those changes being visible to other
485             * users. If the user is satisfied with the changes, he may elect to check
486             * in his changes, resulting in a new file version based on the PWC; the PWC
487             * will be removed and the file entry will be unlocked. If the user is not
488             * satisfied with the changes, he may elect to cancel his check out; this
489             * results in the deletion of the PWC and unlocking of the file entry.
490             * </p>
491             *
492             * @param  fileEntryId the file entry to check out
493             * @param  serviceContext the service context to be applied
494             * @throws PortalException if the file entry could not be found
495             * @throws SystemException if a system exception occurred
496             * @see    #cancelCheckOut(long)
497             * @see    #checkInFileEntry(long, boolean, String, ServiceContext)
498             */
499            public void checkOutFileEntry(
500                            long fileEntryId, ServiceContext serviceContext)
501                    throws PortalException, SystemException {
502    
503                    Repository repository = getRepository(0, fileEntryId, 0);
504    
505                    FileEntry fileEntry = repository.checkOutFileEntry(
506                            fileEntryId, serviceContext);
507    
508                    FileVersion fileVersion = fileEntry.getLatestFileVersion();
509    
510                    dlAppHelperLocalService.updateFileEntry(
511                            getUserId(), fileEntry, fileVersion, fileEntryId);
512            }
513    
514            /**
515             * Checks out the file entry. 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 file entry to check out
529             * @param  owner the owner string for the checkout (optionally
530             *         <code>null</code>)
531             * @param  expirationTime the time in milliseconds before the lock expires.
532             *         If the value is <code>0</code>, the default expiration time will
533             *         be used from <code>portal.properties>.
534             * @param  serviceContext the service context to be applied
535             * @return the file entry
536             * @throws PortalException if the file entry could not be found
537             * @throws SystemException if a system exception occurred
538             * @see    #cancelCheckOut(long)
539             * @see    #checkInFileEntry(long, String)
540             */
541            public FileEntry checkOutFileEntry(
542                            long fileEntryId, String owner, long expirationTime,
543                            ServiceContext serviceContext)
544                    throws PortalException, SystemException {
545    
546                    Repository repository = getRepository(0, fileEntryId, 0);
547    
548                    FileEntry fileEntry = repository.checkOutFileEntry(
549                            fileEntryId, owner, expirationTime, serviceContext);
550    
551                    FileVersion fileVersion = fileEntry.getLatestFileVersion();
552    
553                    dlAppHelperLocalService.updateFileEntry(
554                            getUserId(), fileEntry, fileVersion, fileEntryId);
555    
556                    return fileEntry;
557            }
558    
559            /**
560             * Performs a deep copy of the folder.
561             *
562             * @param  repositoryId the primary key of the repository
563             * @param  sourceFolderId the primary key of the folder to copy
564             * @param  parentFolderId the primary key of the new folder's parent folder
565             * @param  name the new folder's name
566             * @param  description the new folder's description
567             * @param  serviceContext the service context to be applied
568             * @return the folder
569             * @throws PortalException if the source folder or the new parent folder
570             *         could not be found or if the new folder's information was invalid
571             * @throws SystemException if a system exception occurred
572             */
573            public Folder copyFolder(
574                            long repositoryId, long sourceFolderId, long parentFolderId,
575                            String name, String description, ServiceContext serviceContext)
576                    throws PortalException, SystemException {
577    
578                    Repository repository = getRepository(repositoryId);
579    
580                    Folder srcFolder = repository.getFolder(sourceFolderId);
581    
582                    Folder destFolder = repository.addFolder(
583                            parentFolderId, name, description, serviceContext);
584    
585                    copyFolder(repository, srcFolder, destFolder, serviceContext);
586    
587                    return destFolder;
588            }
589    
590            /**
591             * Deletes the file entry with the primary key.
592             *
593             * @param  fileEntryId the primary key of the file entry
594             * @throws PortalException if the file entry could not be found
595             * @throws SystemException if a system exception occurred
596             */
597            public void deleteFileEntry(long fileEntryId)
598                    throws PortalException, SystemException {
599    
600                    Repository repository = getRepository(0, fileEntryId, 0);
601    
602                    FileEntry fileEntry = repository.getFileEntry(fileEntryId);
603    
604                    dlAppHelperLocalService.deleteFileEntry(fileEntry);
605    
606                    repository.deleteFileEntry(fileEntryId);
607            }
608    
609            /**
610             * Deletes the file entry with the title in the folder.
611             *
612             * @param  repositoryId the primary key of the repository
613             * @param  folderId the primary key of the file entry's parent folder
614             * @param  title the file entry's title
615             * @throws PortalException if the file entry could not be found
616             * @throws SystemException if a system exception occurred
617             */
618            public void deleteFileEntryByTitle(
619                            long repositoryId, long folderId, String title)
620                    throws PortalException, SystemException {
621    
622                    Repository repository = getRepository(repositoryId);
623    
624                    FileEntry fileEntry = repository.getFileEntry(folderId, title);
625    
626                    dlAppHelperLocalService.deleteFileEntry(fileEntry);
627    
628                    repository.deleteFileEntry(folderId, title);
629            }
630    
631            /**
632             * Deletes the file shortcut with the primary key. This method is only
633             * supported by the Liferay repository.
634             *
635             * @param  fileShortcutId the primary key of the file shortcut
636             * @throws PortalException if the file shortcut could not be found
637             * @throws SystemException if a system exception occurred
638             */
639            public void deleteFileShortcut(long fileShortcutId)
640                    throws PortalException, SystemException {
641    
642                    dlFileShortcutService.deleteFileShortcut(fileShortcutId);
643            }
644    
645            /**
646             * Deletes the folder with the primary key and all of its subfolders and
647             * file entries.
648             *
649             * @param  folderId the primary key of the folder
650             * @throws PortalException if the folder could not be found
651             * @throws SystemException if a system exception occurred
652             */
653            public void deleteFolder(long folderId)
654                    throws PortalException, SystemException {
655    
656                    Repository repository = getRepository(folderId, 0, 0);
657    
658                    repository.deleteFolder(folderId);
659            }
660    
661            /**
662             * Deletes the folder with the name in the parent folder and all of its
663             * subfolders and file entries.
664             *
665             * @param  repositoryId the primary key of the repository
666             * @param  parentFolderId the primary key of the folder's parent folder
667             * @param  name the folder's name
668             * @throws PortalException if the folder could not be found
669             * @throws SystemException if a system exception occurred
670             */
671            public void deleteFolder(
672                            long repositoryId, long parentFolderId, String name)
673                    throws PortalException, SystemException {
674    
675                    Repository repository = getRepository(repositoryId);
676    
677                    repository.deleteFolder(parentFolderId, name);
678            }
679    
680            /**
681             * Deletes the temporary file entry.
682             *
683             * @param  groupId the primary key of the group
684             * @param  folderId the primary key of the folder where the file entry was
685             *         eventually to reside
686             * @param  fileName the file's original name
687             * @param  tempFolderName the temporary folder's name
688             * @throws PortalException if the file name was invalid
689             * @throws SystemException if a system exception occurred
690             * @see    com.liferay.portal.kernel.util.TempFileUtil
691             */
692            public void deleteTempFileEntry(
693                            long groupId, long folderId, String fileName, String tempFolderName)
694                    throws PortalException, SystemException {
695    
696                    DLFolderPermission.check(
697                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
698    
699                    TempFileUtil.deleteTempFile(getUserId(), fileName, tempFolderName);
700            }
701    
702            /**
703             * Returns all the file entries in the folder.
704             *
705             * @param  repositoryId the primary key of the file entry's repository
706             * @param  folderId the primary key of the file entry's folder
707             * @return the file entries in the folder
708             * @throws PortalException if the folder could not be found
709             * @throws SystemException if a system exception occurred
710             */
711            public List<FileEntry> getFileEntries(long repositoryId, long folderId)
712                    throws PortalException, SystemException {
713    
714                    return getFileEntries(
715                            repositoryId, folderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
716            }
717    
718            /**
719             * Returns a range of all the file entries in the folder.
720             *
721             * <p>
722             * Useful when paginating results. Returns a maximum of <code>end -
723             * start</code> instances. <code>start</code> and <code>end</code> are not
724             * primary keys, they are indexes in the result set. Thus, <code>0</code>
725             * refers to the first result in the set. Setting both <code>start</code>
726             * and <code>end</code> to {@link
727             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
728             * result set.
729             * </p>
730             *
731             * @param  repositoryId the primary key of the file entry's repository
732             * @param  folderId the primary key of the file entry's folder
733             * @param  start the lower bound of the range of results
734             * @param  end the upper bound of the range of results (not inclusive)
735             * @return the range of file entries in the folder
736             * @throws PortalException if the folder could not be found
737             * @throws SystemException if a system exception occurred
738             */
739            public List<FileEntry> getFileEntries(
740                            long repositoryId, long folderId, int start, int end)
741                    throws PortalException, SystemException {
742    
743                    return getFileEntries(repositoryId, folderId, start, end, null);
744            }
745    
746            /**
747             * Returns an ordered range of all the file entries in the folder.
748             *
749             * <p>
750             * Useful when paginating results. Returns a maximum of <code>end -
751             * start</code> instances. <code>start</code> and <code>end</code> are not
752             * primary keys, they are indexes in the result set. Thus, <code>0</code>
753             * refers to the first result in the set. Setting both <code>start</code>
754             * and <code>end</code> to {@link
755             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
756             * result set.
757             * </p>
758             *
759             * @param  repositoryId the primary key of the file entry's repository
760             * @param  folderId the primary key of the file entry's folder
761             * @param  start the lower bound of the range of results
762             * @param  end the upper bound of the range of results (not inclusive)
763             * @param  obc the comparator to order the file entries (optionally
764             *         <code>null</code>)
765             * @return the range of file entries in the folder ordered by comparator
766             *         <code>obc</code>
767             * @throws PortalException if the folder could not be found
768             * @throws SystemException if a system exception occurred
769             */
770            public List<FileEntry> getFileEntries(
771                            long repositoryId, long folderId, int start, int end,
772                            OrderByComparator obc)
773                    throws PortalException, SystemException {
774    
775                    Repository repository = getRepository(repositoryId);
776    
777                    return repository.getFileEntries(folderId, start, end, obc);
778            }
779    
780            /**
781             * Returns the file entries with the file entry type in the folder.
782             *
783             * @param  repositoryId the primary key of the file entry's repository
784             * @param  folderId the primary key of the file entry's folder
785             * @param  fileEntryTypeId the primary key of the file entry type
786             * @return the file entries with the file entry type in the folder
787             * @throws PortalException if the folder could not be found
788             * @throws SystemException if a system exception occurred
789             */
790            public List<FileEntry> getFileEntries(
791                            long repositoryId, long folderId, long fileEntryTypeId)
792                    throws PortalException, SystemException {
793    
794                    return getFileEntries(
795                            repositoryId, folderId, fileEntryTypeId, QueryUtil.ALL_POS,
796                            QueryUtil.ALL_POS);
797            }
798    
799            /**
800             * Returns a range of all the file entries with the file entry type in the
801             * folder.
802             *
803             * @param  repositoryId the primary key of the file entry's repository
804             * @param  folderId the primary key of the file entry's folder
805             * @param  fileEntryTypeId the primary key of the file entry type
806             * @param  start the lower bound of the range of results
807             * @param  end the upper bound of the range of results (not inclusive)
808             * @return the file entries in the folder
809             * @throws PortalException if the folder could not be found
810             * @throws SystemException if a system exception occurred
811             */
812            public List<FileEntry> getFileEntries(
813                            long repositoryId, long folderId, long fileEntryTypeId, int start,
814                            int end)
815                    throws PortalException, SystemException {
816    
817                    return getFileEntries(
818                            repositoryId, folderId, fileEntryTypeId, start, end, null);
819            }
820    
821            /**
822             * Returns an ordered range of all the file entries with the file entry type
823             * in the folder.
824             *
825             * @param  repositoryId the primary key of the repository
826             * @param  folderId the primary key of the folder
827             * @param  fileEntryTypeId the primary key of the file entry type
828             * @param  start the lower bound of the range of results
829             * @param  end the upper bound of the range of results (not inclusive)
830             * @param  obc the comparator to order the results by (optionally
831             *         <code>null</code>)
832             * @return the range of file entries with the file entry type in the folder
833             *         ordered by <code>null</code>
834             * @throws PortalException if the folder could not be found
835             * @throws SystemException if a system exception occurred
836             */
837            public List<FileEntry> getFileEntries(
838                            long repositoryId, long folderId, long fileEntryTypeId, int start,
839                            int end, OrderByComparator obc)
840                    throws PortalException, SystemException {
841    
842                    Repository repository = getRepository(repositoryId);
843    
844                    return repository.getFileEntries(
845                            folderId, fileEntryTypeId, start, end, obc);
846            }
847    
848            /**
849             * Returns a range of all the file entries and shortcuts in the folder.
850             *
851             * <p>
852             * Useful when paginating results. Returns a maximum of <code>end -
853             * start</code> instances. <code>start</code> and <code>end</code> are not
854             * primary keys, they are indexes in the result set. Thus, <code>0</code>
855             * refers to the first result in the set. Setting both <code>start</code>
856             * and <code>end</code> to {@link
857             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
858             * result set.
859             * </p>
860             *
861             * @param  repositoryId the primary key of the repository
862             * @param  folderId the primary key of the folder
863             * @param  status the workflow status
864             * @param  start the lower bound of the range of results
865             * @param  end the upper bound of the range of results (not inclusive)
866             * @return the range of file entries and shortcuts in the folder
867             * @throws PortalException if the folder could not be found
868             * @throws SystemException if a system exception occurred
869             */
870            public List<Object> getFileEntriesAndFileShortcuts(
871                            long repositoryId, long folderId, int status, int start, int end)
872                    throws PortalException, SystemException {
873    
874                    Repository repository = getRepository(repositoryId);
875    
876                    return repository.getFileEntriesAndFileShortcuts(
877                            folderId, status, start, end);
878            }
879    
880            /**
881             * Returns the number of file entries and shortcuts in the folder.
882             *
883             * @param  repositoryId the primary key of the repository
884             * @param  folderId the primary key of the folder
885             * @param  status the workflow status
886             * @return the number of file entries and shortcuts in the folder
887             * @throws PortalException if the folder ould not be found
888             * @throws SystemException if a system exception occurred
889             */
890            public int getFileEntriesAndFileShortcutsCount(
891                            long repositoryId, long folderId, int status)
892                    throws PortalException, SystemException {
893    
894                    Repository repository = getRepository(repositoryId);
895    
896                    return repository.getFileEntriesAndFileShortcutsCount(folderId, status);
897            }
898    
899            /**
900             * Returns the number of file entries and shortcuts in the folder.
901             *
902             * @param  repositoryId the primary key of the repository
903             * @param  folderId the primary key of the folder
904             * @param  status the workflow status
905             * @param  mimeTypes allowed media types
906             * @return the number of file entries and shortcuts in the folder
907             * @throws PortalException if the folder ould not be found
908             * @throws SystemException if a system exception occurred
909             */
910            public int getFileEntriesAndFileShortcutsCount(
911                            long repositoryId, long folderId, int status, String[] mimeTypes)
912                            throws PortalException, SystemException {
913    
914                    Repository repository = getRepository(repositoryId);
915    
916                    return repository.getFileEntriesAndFileShortcutsCount(
917                            folderId, status, mimeTypes);
918            }
919    
920            /**
921             * Returns the number of file entries in the folder.
922             *
923             * @param  repositoryId the primary key of the file entry's repository
924             * @param  folderId the primary key of the file entry's folder
925             * @return the number of file entries in the folder
926             * @throws PortalException if the folder could not be found
927             * @throws SystemException if a system exception occurred
928             */
929            public int getFileEntriesCount(long repositoryId, long folderId)
930                    throws PortalException, SystemException {
931    
932                    Repository repository = getRepository(repositoryId);
933    
934                    return repository.getFileEntriesCount(folderId);
935            }
936    
937            /**
938             * Returns the number of file entries with the file entry type in the
939             * folder.
940             *
941             * @param  repositoryId the primary key of the file entry's repository
942             * @param  folderId the primary key of the file entry's folder
943             * @param  fileEntryTypeId the primary key of the file entry type
944             * @return the number of file entries with the file entry type in the folder
945             * @throws PortalException if the folder could not be found
946             * @throws SystemException if a system exception occurred
947             */
948            public int getFileEntriesCount(
949                            long repositoryId, long folderId, long fileEntryTypeId)
950                    throws PortalException, SystemException {
951    
952                    Repository repository = getRepository(repositoryId);
953    
954                    return repository.getFileEntriesCount(folderId, fileEntryTypeId);
955            }
956    
957            /**
958             * Returns the file entry with the primary key.
959             *
960             * @param  fileEntryId the primary key of the file entry
961             * @return the file entry with the primary key
962             * @throws PortalException if the file entry could not be found
963             * @throws SystemException if a system exception occurred
964             */
965            public FileEntry getFileEntry(long fileEntryId)
966                    throws PortalException, SystemException {
967    
968                    Repository repository = getRepository(0, fileEntryId, 0);
969    
970                    return repository.getFileEntry(fileEntryId);
971            }
972    
973            /**
974             * Returns the file entry with the title in the folder.
975             *
976             * @param  groupId the primary key of the file entry's group
977             * @param  folderId the primary key of the file entry's folder
978             * @param  title the file entry's title
979             * @return the file entry with the title in the folder
980             * @throws PortalException if the file entry could not be found
981             * @throws SystemException if a system exception occurred
982             */
983            public FileEntry getFileEntry(long groupId, long folderId, String title)
984                    throws PortalException, SystemException {
985    
986                    try {
987                            Repository repository = getRepository(groupId);
988    
989                            return repository.getFileEntry(folderId, title);
990                    }
991                    catch (NoSuchFileEntryException nsfee) {
992                            if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
993                                    Repository repository = getRepository(folderId, 0, 0);
994    
995                                    return repository.getFileEntry(folderId, title);
996                            }
997                            else {
998                                    throw nsfee;
999                            }
1000                    }
1001            }
1002    
1003            /**
1004             * Returns the file entry with the UUID and group.
1005             *
1006             * @param  uuid the file entry's universally unique identifier
1007             * @param  groupId the primary key of the file entry's group
1008             * @return the file entry with the UUID and group
1009             * @throws PortalException if the file entry could not be found
1010             * @throws SystemException if a system exception occurred
1011             */
1012            public FileEntry getFileEntryByUuidAndGroupId(String uuid, long groupId)
1013                    throws PortalException, SystemException {
1014    
1015                    try {
1016                            Repository repository = getRepository(groupId);
1017    
1018                            return repository.getFileEntryByUuid(uuid);
1019                    }
1020                    catch (NoSuchFileEntryException nsfee) {
1021                            List<com.liferay.portal.model.Repository> repositories =
1022                                    repositoryPersistence.findByGroupId(groupId);
1023    
1024                            for (int i = 0; i < repositories.size(); i++) {
1025                                    try {
1026                                            long repositoryId = repositories.get(i).getRepositoryId();
1027    
1028                                            Repository repository = getRepository(repositoryId);
1029    
1030                                            return repository.getFileEntryByUuid(uuid);
1031                                    }
1032                                    catch (NoSuchFileEntryException nsfee2) {
1033                                    }
1034                            }
1035                    }
1036    
1037                    StringBundler msg = new StringBundler(6);
1038    
1039                    msg.append("No DLFileEntry exists with the key {");
1040                    msg.append("uuid=");
1041                    msg.append(uuid);
1042                    msg.append(", groupId=");
1043                    msg.append(groupId);
1044                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1045    
1046                    throw new NoSuchFileEntryException(msg.toString());
1047            }
1048    
1049            /**
1050             * Returns the file shortcut with the primary key. This method is only
1051             * supported by the Liferay repository.
1052             *
1053             * @param  fileShortcutId the primary key of the file shortcut
1054             * @return the file shortcut with the primary key
1055             * @throws PortalException if the file shortcut could not be found
1056             * @throws SystemException if a system exception occurred
1057             */
1058            public DLFileShortcut getFileShortcut(long fileShortcutId)
1059                    throws PortalException, SystemException {
1060    
1061                    return dlFileShortcutService.getFileShortcut(fileShortcutId);
1062            }
1063    
1064            /**
1065             * Returns the folder with the primary key.
1066             *
1067             * @param  folderId the primary key of the folder
1068             * @return the folder with the primary key
1069             * @throws PortalException if the folder could not be found
1070             * @throws SystemException if a system exception occurred
1071             */
1072            public Folder getFolder(long folderId)
1073                    throws PortalException, SystemException {
1074    
1075                    Repository repository = getRepository(folderId, 0, 0);
1076    
1077                    return repository.getFolder(folderId);
1078            }
1079    
1080            /**
1081             * Returns the folder with the name in the parent folder.
1082             *
1083             * @param  repositoryId the primary key of the folder's repository
1084             * @param  parentFolderId the primary key of the folder's parent folder
1085             * @param  name the folder's name
1086             * @return the folder with the name in the parent folder
1087             * @throws PortalException if the folder could not be found
1088             * @throws SystemException if a system exception occurred
1089             */
1090            public Folder getFolder(long repositoryId, long parentFolderId, String name)
1091                    throws PortalException, SystemException {
1092    
1093                    Repository repository = getRepository(repositoryId);
1094    
1095                    return repository.getFolder(parentFolderId, name);
1096            }
1097    
1098            /**
1099             * Returns all immediate subfolders of the parent folder.
1100             *
1101             * @param  repositoryId the primary key of the folder's repository
1102             * @param  parentFolderId the primary key of the folder's parent folder
1103             * @return the immediate subfolders of the parent folder
1104             * @throws PortalException if the parent folder could not be found
1105             * @throws SystemException if a system exception occurred
1106             */
1107            public List<Folder> getFolders(long repositoryId, long parentFolderId)
1108                    throws PortalException, SystemException {
1109    
1110                    return getFolders(
1111                            repositoryId, parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1112            }
1113    
1114            /**
1115             * Returns all immediate subfolders of the parent folder, optionally
1116             * including mount folders for third-party repositories.
1117             *
1118             * @param  repositoryId the primary key of the folder's repository
1119             * @param  parentFolderId the primary key of the folder's parent folder
1120             * @param  includeMountFolders whether to include mount folders for
1121             *         third-party repositories
1122             * @return the immediate subfolders of the parent folder
1123             * @throws PortalException if the parent folder could not be found
1124             * @throws SystemException if a system exception occurred
1125             */
1126            public List<Folder> getFolders(
1127                            long repositoryId, long parentFolderId, boolean includeMountFolders)
1128                    throws PortalException, SystemException {
1129    
1130                    return getFolders(
1131                            repositoryId, parentFolderId, includeMountFolders,
1132                            QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1133            }
1134    
1135            /**
1136             * Returns a range of all the immediate subfolders of the parent folder,
1137             * optionally including mount folders for third-party repositories.
1138             *
1139             * <p>
1140             * Useful when paginating results. Returns a maximum of <code>end -
1141             * start</code> instances. <code>start</code> and <code>end</code> are not
1142             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1143             * refers to the first result in the set. Setting both <code>start</code>
1144             * and <code>end</code> to {@link
1145             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1146             * result set.
1147             * </p>
1148             *
1149             * @param  repositoryId the primary key of the folder's repository
1150             * @param  parentFolderId the primary key of the folder's parent folder
1151             * @param  includeMountFolders whether to include mount folders for
1152             *         third-party repositories
1153             * @param  start the lower bound of the range of results
1154             * @param  end the upper bound of the range of results (not inclusive)
1155             * @return the range of immediate subfolders of the parent folder
1156             * @throws PortalException if the parent folder could not be found
1157             * @throws SystemException if a system exception occurred
1158             */
1159            public List<Folder> getFolders(
1160                            long repositoryId, long parentFolderId, boolean includeMountFolders,
1161                            int start, int end)
1162                    throws PortalException, SystemException {
1163    
1164                    return getFolders(
1165                            repositoryId, parentFolderId, includeMountFolders, start, end,
1166                            null);
1167            }
1168    
1169            /**
1170             * Returns an ordered range of all the immediate subfolders of the parent
1171             * folder.
1172             *
1173             * <p>
1174             * Useful when paginating results. Returns a maximum of <code>end -
1175             * start</code> instances. <code>start</code> and <code>end</code> are not
1176             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1177             * refers to the first result in the set. Setting both <code>start</code>
1178             * and <code>end</code> to {@link
1179             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1180             * result set.
1181             * </p>
1182             *
1183             * @param  repositoryId the primary key of the folder's repository
1184             * @param  parentFolderId the primary key of the folder's parent folder
1185             * @param  includeMountFolders whether to include mount folders for
1186             *         third-party repositories
1187             * @param  start the lower bound of the range of results
1188             * @param  end the upper bound of the range of results (not inclusive)
1189             * @param  obc the comparator to order the folders (optionally
1190             *         <code>null</code>)
1191             * @return the range of immediate subfolders of the parent folder ordered by
1192             *         comparator <code>obc</code>
1193             * @throws PortalException if the parent folder could not be found
1194             * @throws SystemException if a system exception occurred
1195             */
1196            public List<Folder> getFolders(
1197                            long repositoryId, long parentFolderId, boolean includeMountFolders,
1198                            int start, int end, OrderByComparator obc)
1199                    throws PortalException, SystemException {
1200    
1201                    Repository repository = getRepository(repositoryId);
1202    
1203                    return repository.getFolders(
1204                            parentFolderId, includeMountFolders, start, end, obc);
1205            }
1206    
1207            /**
1208             * Returns a range of all the immediate subfolders of the parent folder.
1209             *
1210             * <p>
1211             * Useful when paginating results. Returns a maximum of <code>end -
1212             * start</code> instances. <code>start</code> and <code>end</code> are not
1213             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1214             * refers to the first result in the set. Setting both <code>start</code>
1215             * and <code>end</code> to {@link
1216             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1217             * result set.
1218             * </p>
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  start the lower bound of the range of results
1223             * @param  end the upper bound of the range of results (not inclusive)
1224             * @return the range of immediate subfolders of the parent folder
1225             * @throws PortalException if the parent folder could not be found
1226             * @throws SystemException if a system exception occurred
1227             */
1228            public List<Folder> getFolders(
1229                            long repositoryId, long parentFolderId, int start, int end)
1230                    throws PortalException, SystemException {
1231    
1232                    return getFolders(repositoryId, parentFolderId, start, end, null);
1233            }
1234    
1235            /**
1236             * Returns an ordered range of all the immediate subfolders of the parent
1237             * folder.
1238             *
1239             * <p>
1240             * Useful when paginating results. Returns a maximum of <code>end -
1241             * start</code> instances. <code>start</code> and <code>end</code> are not
1242             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1243             * refers to the first result in the set. Setting both <code>start</code>
1244             * and <code>end</code> to {@link
1245             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1246             * result set.
1247             * </p>
1248             *
1249             * @param  repositoryId the primary key of the folder's repository
1250             * @param  parentFolderId the primary key of the folder's parent folder
1251             * @param  start the lower bound of the range of results
1252             * @param  end the upper bound of the range of results (not inclusive)
1253             * @param  obc the comparator to order the folders (optionally
1254             *         <code>null</code>)
1255             * @return the range of immediate subfolders of the parent folder ordered by
1256             *         comparator <code>obc</code>
1257             * @throws PortalException if the parent folder could not be found
1258             * @throws SystemException if a system exception occurred
1259             */
1260            public List<Folder> getFolders(
1261                            long repositoryId, long parentFolderId, int start, int end,
1262                            OrderByComparator obc)
1263                    throws PortalException, SystemException {
1264    
1265                    Repository repository = getRepository(repositoryId);
1266    
1267                    return repository.getFolders(parentFolderId, true, start, end, obc);
1268            }
1269    
1270            /**
1271             * Returns a range of all the immediate subfolders, file entries, and file
1272             * shortcuts in the parent folder.
1273             *
1274             * <p>
1275             * Useful when paginating results. Returns a maximum of <code>end -
1276             * start</code> instances. <code>start</code> and <code>end</code> are not
1277             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1278             * refers to the first result in the set. Setting both <code>start</code>
1279             * and <code>end</code> to {@link
1280             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1281             * result set.
1282             * </p>
1283             *
1284             * @param  repositoryId the primary key of the repository
1285             * @param  folderId the primary key of the parent folder
1286             * @param  status the workflow status
1287             * @param  includeMountFolders whether to include mount folders for
1288             *         third-party repositories
1289             * @param  start the lower bound of the range of results
1290             * @param  end the upper bound of the range of results (not inclusive)
1291             * @return the range of immediate subfolders, file entries, and file
1292             *         shortcuts in the parent folder ordered by comparator
1293             *         <code>obc</code>
1294             * @throws PortalException if the parent folder could not be found
1295             * @throws SystemException if a system exception occurred
1296             */
1297            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
1298                            long repositoryId, long folderId, int status,
1299                            boolean includeMountFolders, int start, int end)
1300                    throws PortalException, SystemException {
1301    
1302                    return getFoldersAndFileEntriesAndFileShortcuts(
1303                            repositoryId, folderId, status, includeMountFolders, start, end,
1304                            null);
1305            }
1306    
1307            /**
1308             * Returns an ordered range of all the immediate subfolders, file entries,
1309             * and file shortcuts in the parent folder.
1310             *
1311             * <p>
1312             * Useful when paginating results. Returns a maximum of <code>end -
1313             * start</code> instances. <code>start</code> and <code>end</code> are not
1314             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1315             * refers to the first result in the set. Setting both <code>start</code>
1316             * and <code>end</code> to {@link
1317             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1318             * result set.
1319             * </p>
1320             *
1321             * @param  repositoryId the primary key of the repository
1322             * @param  folderId the primary key of the parent folder
1323             * @param  status the workflow status
1324             * @param  includeMountFolders whether to include mount folders for
1325             *         third-party repositories
1326             * @param  start the lower bound of the range of results
1327             * @param  end the upper bound of the range of results (not inclusive)
1328             * @param  obc the comparator to order the results (optionally
1329             *         <code>null</code>)
1330             * @return the range of immediate subfolders, file entries, and file
1331             *         shortcuts in the parent folder ordered by comparator
1332             *         <code>obc</code>
1333             * @throws PortalException if the parent folder could not be found
1334             * @throws SystemException if a system exception occurred
1335             */
1336            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
1337                            long repositoryId, long folderId, int status,
1338                            boolean includeMountFolders, int start, int end,
1339                            OrderByComparator obc)
1340                    throws PortalException, SystemException {
1341    
1342                    return getFoldersAndFileEntriesAndFileShortcuts(
1343                            repositoryId, folderId, status, null, includeMountFolders, start,
1344                            end, obc);
1345            }
1346    
1347            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
1348                            long repositoryId, long folderId, int status, String[] mimeTypes,
1349                            boolean includeMountFolders, int start, int end,
1350                            OrderByComparator obc)
1351                    throws PortalException, SystemException {
1352    
1353                    Repository repository = getRepository(repositoryId);
1354    
1355                    return repository.getFoldersAndFileEntriesAndFileShortcuts(
1356                            folderId, status, mimeTypes, includeMountFolders, start, end, obc);
1357            }
1358    
1359            /**
1360             * Returns the number of immediate subfolders, file entries, and file
1361             * shortcuts in the parent folder.
1362             *
1363             * @param  repositoryId the primary key of the repository
1364             * @param  folderId the primary key of the parent folder
1365             * @param  status the workflow status
1366             * @param  includeMountFolders whether to include mount folders for
1367             *         third-party repositories
1368             * @return the number of immediate subfolders, file entries, and file
1369             *         shortcuts in the parent folder
1370             * @throws PortalException if the folder could not be found
1371             * @throws SystemException if a system exception occurred
1372             */
1373            public int getFoldersAndFileEntriesAndFileShortcutsCount(
1374                            long repositoryId, long folderId, int status,
1375                            boolean includeMountFolders)
1376                    throws PortalException, SystemException {
1377    
1378                    return getFoldersAndFileEntriesAndFileShortcutsCount(
1379                            repositoryId, folderId, status, null, includeMountFolders);
1380            }
1381    
1382            public int getFoldersAndFileEntriesAndFileShortcutsCount(
1383                            long repositoryId, long folderId, int status, String[] mimeTypes,
1384                            boolean includeMountFolders)
1385                    throws PortalException, SystemException {
1386    
1387                    Repository repository = getRepository(repositoryId);
1388    
1389                    return repository.getFoldersAndFileEntriesAndFileShortcutsCount(
1390                            folderId, status, mimeTypes, includeMountFolders);
1391            }
1392    
1393            /**
1394             * Returns the number of immediate subfolders of the parent folder.
1395             *
1396             * @param  repositoryId the primary key of the folder's repository
1397             * @param  parentFolderId the primary key of the folder's parent folder
1398             * @return the number of immediate subfolders of the parent folder
1399             * @throws PortalException if the parent folder could not be found
1400             * @throws SystemException if a system exception occurred
1401             */
1402            public int getFoldersCount(long repositoryId, long parentFolderId)
1403                    throws PortalException, SystemException {
1404    
1405                    return getFoldersCount(repositoryId, parentFolderId, true);
1406            }
1407    
1408            /**
1409             * Returns the number of immediate subfolders of the parent folder,
1410             * optionally including mount folders for third-party repositories.
1411             *
1412             * @param  repositoryId the primary key of the folder's repository
1413             * @param  parentFolderId the primary key of the folder's parent folder
1414             * @param  includeMountFolders whether to include mount folders for
1415             *         third-party repositories
1416             * @return the number of immediate subfolders of the parent folder
1417             * @throws PortalException if the parent folder could not be found
1418             * @throws SystemException if a system exception occurred
1419             */
1420            public int getFoldersCount(
1421                            long repositoryId, long parentFolderId, boolean includeMountFolders)
1422                    throws PortalException, SystemException {
1423    
1424                    Repository repository = getRepository(repositoryId);
1425    
1426                    return repository.getFoldersCount(parentFolderId, includeMountFolders);
1427            }
1428    
1429            /**
1430             * Returns the number of immediate subfolders and file entries across the
1431             * folders.
1432             *
1433             * @param  repositoryId the primary key of the repository
1434             * @param  folderIds the primary keys of folders from which to count
1435             *         immediate subfolders and file entries
1436             * @param  status the workflow status
1437             * @return the number of immediate subfolders and file entries across the
1438             *         folders
1439             * @throws PortalException if the repository could not be found
1440             * @throws SystemException if a system exception occurred
1441             */
1442            public int getFoldersFileEntriesCount(
1443                            long repositoryId, List<Long> folderIds, int status)
1444                    throws PortalException, SystemException {
1445    
1446                    Repository repository = getRepository(repositoryId);
1447    
1448                    return repository.getFoldersFileEntriesCount(folderIds, status);
1449            }
1450    
1451            /**
1452             * Returns an ordered range of all the file entries in the group starting at
1453             * the repository default parent folder that are stored within the Liferay
1454             * repository. This method is primarily used to search for recently modified
1455             * file entries. It can be limited to the file entries modified by a given
1456             * user.
1457             *
1458             * <p>
1459             * Useful when paginating results. Returns a maximum of <code>end -
1460             * start</code> instances. <code>start</code> and <code>end</code> are not
1461             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1462             * refers to the first result in the set. Setting both <code>start</code>
1463             * and <code>end</code> to {@link
1464             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1465             * result set.
1466             * </p>
1467             *
1468             * @param  groupId the primary key of the group
1469             * @param  userId the primary key of the user who created the file
1470             *         (optionally <code>0</code>)
1471             * @param  start the lower bound of the range of results
1472             * @param  end the upper bound of the range of results (not inclusive)
1473             * @return the range of matching file entries ordered by date modified
1474             * @throws PortalException if the group could not be found
1475             * @throws SystemException if a system exception occurred
1476             */
1477            public List<FileEntry> getGroupFileEntries(
1478                            long groupId, long userId, int start, int end)
1479                    throws PortalException, SystemException {
1480    
1481                    return getGroupFileEntries(
1482                            groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, start,
1483                            end, new RepositoryModelModifiedDateComparator());
1484            }
1485    
1486            /**
1487             * Returns an ordered range of all the file entries in the group that are
1488             * stored within the Liferay repository. This method is primarily used to
1489             * search for recently modified file entries. It can be limited to the file
1490             * entries modified by a given user.
1491             *
1492             * <p>
1493             * Useful when paginating results. Returns a maximum of <code>end -
1494             * start</code> instances. <code>start</code> and <code>end</code> are not
1495             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1496             * refers to the first result in the set. Setting both <code>start</code>
1497             * and <code>end</code> to {@link
1498             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1499             * result set.
1500             * </p>
1501             *
1502             * @param  groupId the primary key of the group
1503             * @param  userId the primary key of the user who created the file
1504             *         (optionally <code>0</code>)
1505             * @param  start the lower bound of the range of results
1506             * @param  end the upper bound of the range of results (not inclusive)
1507             * @param  obc the comparator to order the file entries (optionally
1508             *         <code>null</code>)
1509             * @return the range of matching file entries ordered by comparator
1510             *         <code>obc</code>
1511             * @throws PortalException if the group could not be found
1512             * @throws SystemException if a system exception occurred
1513             */
1514            public List<FileEntry> getGroupFileEntries(
1515                            long groupId, long userId, int start, int end,
1516                            OrderByComparator obc)
1517                    throws PortalException, SystemException {
1518    
1519                    return getGroupFileEntries(
1520                            groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, start,
1521                            end, obc);
1522            }
1523    
1524            /**
1525             * Returns an ordered range of all the file entries in the group starting at
1526             * the root folder that are stored within the Liferay repository. This
1527             * method is primarily used to search for recently modified file entries. It
1528             * can be limited to the file entries modified by a given user.
1529             *
1530             * <p>
1531             * Useful when paginating results. Returns a maximum of <code>end -
1532             * start</code> instances. <code>start</code> and <code>end</code> are not
1533             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1534             * refers to the first result in the set. Setting both <code>start</code>
1535             * and <code>end</code> to {@link
1536             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1537             * result set.
1538             * </p>
1539             *
1540             * @param  groupId the primary key of the group
1541             * @param  userId the primary key of the user who created the file
1542             *         (optionally <code>0</code>)
1543             * @param  rootFolderId the primary key of the root folder to begin the
1544             *         search
1545             * @param  start the lower bound of the range of results
1546             * @param  end the upper bound of the range of results (not inclusive)
1547             * @return the range of matching file entries ordered by date modified
1548             * @throws PortalException if the group could not be found
1549             * @throws SystemException if a system exception occurred
1550             */
1551            public List<FileEntry> getGroupFileEntries(
1552                            long groupId, long userId, long rootFolderId, int start, int end)
1553                    throws PortalException, SystemException {
1554    
1555                    return getGroupFileEntries(
1556                            groupId, userId, rootFolderId, start, end,
1557                            new RepositoryModelModifiedDateComparator());
1558            }
1559    
1560            /**
1561             * Returns an ordered range of all the file entries in the group starting at
1562             * the root folder that are stored within the Liferay repository. This
1563             * method is primarily used to search for recently modified file entries. It
1564             * can be limited to the file entries modified by a given user.
1565             *
1566             * <p>
1567             * Useful when paginating results. Returns a maximum of <code>end -
1568             * start</code> instances. <code>start</code> and <code>end</code> are not
1569             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1570             * refers to the first result in the set. Setting both <code>start</code>
1571             * and <code>end</code> to {@link
1572             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1573             * result set.
1574             * </p>
1575             *
1576             * @param  groupId the primary key of the group
1577             * @param  userId the primary key of the user who created the file
1578             *         (optionally <code>0</code>)
1579             * @param  rootFolderId the primary key of the root folder to begin the
1580             *         search
1581             * @param  start the lower bound of the range of results
1582             * @param  end the upper bound of the range of results (not inclusive)
1583             * @param  obc the comparator to order the file entries (optionally
1584             *         <code>null</code>)
1585             * @return the range of matching file entries ordered by comparator
1586             *         <code>obc</code>
1587             * @throws PortalException if the group could not be found
1588             * @throws SystemException if a system exception occurred
1589             */
1590            public List<FileEntry> getGroupFileEntries(
1591                            long groupId, long userId, long rootFolderId, int start, int end,
1592                            OrderByComparator obc)
1593                    throws PortalException, SystemException {
1594    
1595                    Repository repository = getRepository(groupId);
1596    
1597                    return repository.getRepositoryFileEntries(
1598                            userId, rootFolderId, start, end, obc);
1599            }
1600    
1601            public List<FileEntry> getGroupFileEntries(
1602                            long groupId, long userId, long rootFolderId, String[] mimeTypes,
1603                            int status, int start, int end, OrderByComparator obc)
1604                    throws PortalException, SystemException {
1605    
1606                    Repository repository = getRepository(groupId);
1607    
1608                    return repository.getRepositoryFileEntries(
1609                            userId, rootFolderId, mimeTypes, status, start, end, obc);
1610            }
1611    
1612            /**
1613             * Returns the number of file entries in a group starting at the repository
1614             * default parent folder that are stored within the Liferay repository. This
1615             * method is primarily used to search for recently modified file entries. It
1616             * can be limited to the file entries modified by a given user.
1617             *
1618             * @param  groupId the primary key of the group
1619             * @param  userId the primary key of the user who created the file
1620             *         (optionally <code>0</code>)
1621             * @return the number of matching file entries
1622             * @throws PortalException if the group could not be found
1623             * @throws SystemException if a system exception occurred
1624             */
1625            public int getGroupFileEntriesCount(long groupId, long userId)
1626                    throws PortalException, SystemException {
1627    
1628                    return getGroupFileEntriesCount(
1629                            groupId, userId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
1630            }
1631    
1632            /**
1633             * Returns the number of file entries in a group starting at the root folder
1634             * that are stored within the Liferay repository. This method is primarily
1635             * used to search for recently modified file entries. It can be limited to
1636             * the file entries modified by a given user.
1637             *
1638             * @param  groupId the primary key of the group
1639             * @param  userId the primary key of the user who created the file
1640             *         (optionally <code>0</code>)
1641             * @param  rootFolderId the primary key of the root folder to begin the
1642             *         search
1643             * @return the number of matching file entries
1644             * @throws PortalException if the group could not be found
1645             * @throws SystemException if a system exception occurred
1646             */
1647            public int getGroupFileEntriesCount(
1648                            long groupId, long userId, long rootFolderId)
1649                    throws PortalException, SystemException {
1650    
1651                    Repository repository = getRepository(groupId);
1652    
1653                    return repository.getRepositoryFileEntriesCount(userId, rootFolderId);
1654            }
1655    
1656            public int getGroupFileEntriesCount(
1657                            long groupId, long userId, long rootFolderId, String[] mimeTypes,
1658                            int status)
1659                    throws PortalException, SystemException {
1660    
1661                    Repository repository = getRepository(groupId);
1662    
1663                    return repository.getRepositoryFileEntriesCount(
1664                            userId, rootFolderId, mimeTypes, status);
1665            }
1666    
1667            /**
1668             * Returns all immediate subfolders of the parent folder that are used for
1669             * mounting third-party repositories. This method is only supported by the
1670             * Liferay repository.
1671             *
1672             * @param  repositoryId the primary key of the folder's repository
1673             * @param  parentFolderId the primary key of the folder's parent folder
1674             * @return the immediate subfolders of the parent folder that are used for
1675             *         mounting third-party repositories
1676             * @throws PortalException if the repository or parent folder could not be
1677             *         found
1678             * @throws SystemException if a system exception occurred
1679             */
1680            public List<Folder> getMountFolders(long repositoryId, long parentFolderId)
1681                    throws PortalException, SystemException {
1682    
1683                    return getMountFolders(
1684                            repositoryId, parentFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1685            }
1686    
1687            /**
1688             * Returns a range of all the immediate subfolders of the parent folder that
1689             * are used for mounting third-party repositories. This method is only
1690             * supported by the Liferay repository.
1691             *
1692             * <p>
1693             * Useful when paginating results. Returns a maximum of <code>end -
1694             * start</code> instances. <code>start</code> and <code>end</code> are not
1695             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1696             * refers to the first result in the set. Setting both <code>start</code>
1697             * and <code>end</code> to {@link
1698             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1699             * result set.
1700             * </p>
1701             *
1702             * @param  repositoryId the primary key of the repository
1703             * @param  parentFolderId the primary key of the parent folder
1704             * @param  start the lower bound of the range of results
1705             * @param  end the upper bound of the range of results (not inclusive)
1706             * @return the range of immediate subfolders of the parent folder that are
1707             *         used for mounting third-party repositories
1708             * @throws PortalException if the repository or parent folder could not be
1709             *         found
1710             * @throws SystemException if a system exception occurred
1711             */
1712            public List<Folder> getMountFolders(
1713                            long repositoryId, long parentFolderId, int start, int end)
1714                    throws PortalException, SystemException {
1715    
1716                    return getMountFolders(repositoryId, parentFolderId, start, end, null);
1717            }
1718    
1719            /**
1720             * Returns an ordered range of all the immediate subfolders of the parent
1721             * folder that are used for mounting third-party repositories. This method
1722             * is only supported by the Liferay repository.
1723             *
1724             * <p>
1725             * Useful when paginating results. Returns a maximum of <code>end -
1726             * start</code> instances. <code>start</code> and <code>end</code> are not
1727             * primary keys, they are indexes in the result set. Thus, <code>0</code>
1728             * refers to the first result in the set. Setting both <code>start</code>
1729             * and <code>end</code> to {@link
1730             * com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full
1731             * result set.
1732             * </p>
1733             *
1734             * @param  repositoryId the primary key of the folder's repository
1735             * @param  parentFolderId the primary key of the folder's parent folder
1736             * @param  start the lower bound of the range of results
1737             * @param  end the upper bound of the range of results (not inclusive)
1738             * @param  obc the comparator to order the folders (optionally
1739             *         <code>null</code>)
1740             * @return the range of immediate subfolders of the parent folder that are
1741             *         used for mounting third-party repositories ordered by comparator
1742             *         <code>obc</code>
1743             * @throws PortalException if the repository or parent folder could not be
1744             *         found
1745             * @throws SystemException if a system exception occurred
1746             */
1747            public List<Folder> getMountFolders(
1748                            long repositoryId, long parentFolderId, int start, int end,
1749                            OrderByComparator obc)
1750                    throws PortalException, SystemException {
1751    
1752                    Repository repository = getRepository(repositoryId);
1753    
1754                    return repository.getMountFolders(parentFolderId, start, end, obc);
1755            }
1756    
1757            /**
1758             * Returns the number of immediate subfolders of the parent folder that are
1759             * used for mounting third-party repositories. This method is only supported
1760             * by the Liferay repository.
1761             *
1762             * @param  repositoryId the primary key of the repository
1763             * @param  parentFolderId the primary key of the parent folder
1764             * @return the number of folders of the parent folder that are used for
1765             *         mounting third-party repositories
1766             * @throws PortalException if the repository or parent folder could not be
1767             *         found
1768             * @throws SystemException if a system exception occurred
1769             */
1770            public int getMountFoldersCount(long repositoryId, long parentFolderId)
1771                    throws PortalException, SystemException {
1772    
1773                    Repository repository = getRepository(repositoryId);
1774    
1775                    return repository.getMountFoldersCount(parentFolderId);
1776            }
1777    
1778            public void getSubfolderIds(
1779                            long repositoryId, List<Long> folderIds, long folderId)
1780                    throws PortalException, SystemException {
1781    
1782                    Repository repository = getRepository(repositoryId);
1783    
1784                    repository.getSubfolderIds(folderIds, folderId);
1785            }
1786    
1787            /**
1788             * Returns all the descendant folders of the folder with the primary key.
1789             *
1790             * @param  repositoryId the primary key of the repository
1791             * @param  folderId the primary key of the folder
1792             * @return the descendant folders of the folder with the primary key
1793             * @throws PortalException if the repository or parent folder could not be
1794             *         found
1795             * @throws SystemException if a system exception occurred
1796             */
1797            public List<Long> getSubfolderIds(long repositoryId, long folderId)
1798                    throws PortalException, SystemException {
1799    
1800                    return getSubfolderIds(repositoryId, folderId, true);
1801            }
1802    
1803            /**
1804             * Returns descendant folders of the folder with the primary key, optionally
1805             * limiting to one level deep.
1806             *
1807             * @param  repositoryId the primary key of the repository
1808             * @param  folderId the primary key of the folder
1809             * @param  recurse whether to recurse through each subfolder
1810             * @return the descendant folders of the folder with the primary key
1811             * @throws PortalException if the repository or parent folder could not be
1812             *         found
1813             * @throws SystemException if a system exception occurred
1814             */
1815            public List<Long> getSubfolderIds(
1816                            long repositoryId, long folderId, boolean recurse)
1817                    throws PortalException, SystemException {
1818    
1819                    Repository repository = getRepository(repositoryId);
1820    
1821                    return repository.getSubfolderIds(folderId, recurse);
1822            }
1823    
1824            /**
1825             * Returns all the temporary file entry names.
1826             *
1827             * @param  groupId the primary key of the group
1828             * @param  folderId the primary key of the folder where the file entry will
1829             *         eventually reside
1830             * @param  tempFolderName the temporary folder's name
1831             * @return the temporary file entry names
1832             * @throws PortalException if the folder was invalid
1833             * @throws SystemException if a system exception occurred
1834             * @see    #addTempFileEntry(long, long, String, String, File)
1835             * @see    com.liferay.portal.kernel.util.TempFileUtil
1836             */
1837            public String[] getTempFileEntryNames(
1838                            long groupId, long folderId, String tempFolderName)
1839                    throws PortalException, SystemException {
1840    
1841                    DLFolderPermission.check(
1842                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
1843    
1844                    return TempFileUtil.getTempFileEntryNames(getUserId(), tempFolderName);
1845            }
1846    
1847            public Lock lockFileEntry(long fileEntryId)
1848                    throws PortalException, SystemException {
1849    
1850                    Repository repository = getRepository(0, fileEntryId, 0);
1851    
1852                    return repository.lockFileEntry(fileEntryId);
1853            }
1854    
1855            public Lock lockFileEntry(
1856                            long fileEntryId, String owner, long expirationTime)
1857                    throws PortalException, SystemException {
1858    
1859                    Repository repository = getRepository(0, fileEntryId, 0);
1860    
1861                    return repository.lockFileEntry(fileEntryId, owner, expirationTime);
1862            }
1863    
1864            /**
1865             * Locks the folder. This method is primarily used by WebDAV.
1866             *
1867             * @param  repositoryId the primary key of the repository
1868             * @param  folderId the primary key of the folder
1869             * @return the lock object
1870             * @throws PortalException if the repository or folder could not be found
1871             * @throws SystemException if a system exception occurred
1872             */
1873            public Lock lockFolder(long repositoryId, long folderId)
1874                    throws PortalException, SystemException {
1875    
1876                    Repository repository = getRepository(repositoryId);
1877    
1878                    return repository.lockFolder(folderId);
1879            }
1880    
1881            /**
1882             * Locks the folder. This method is primarily used by WebDAV.
1883             *
1884             * @param  repositoryId the primary key of the repository
1885             * @param  folderId the primary key of the folder
1886             * @param  owner the owner string for the checkout (optionally
1887             *         <code>null</code>)
1888             * @param  inheritable whether the lock must propagate to descendants
1889             * @param  expirationTime the time in milliseconds before the lock expires.
1890             *         If the value is <code>0</code>, the default expiration time will
1891             *         be used from <code>portal.properties>.
1892             * @return the lock object
1893             * @throws PortalException if the repository or folder could not be found
1894             * @throws SystemException if a system exception occurred
1895             */
1896            public Lock lockFolder(
1897                            long repositoryId, long folderId, String owner, boolean inheritable,
1898                            long expirationTime)
1899                    throws PortalException, SystemException {
1900    
1901                    Repository repository = getRepository(repositoryId);
1902    
1903                    return repository.lockFolder(
1904                            folderId, owner, inheritable, expirationTime);
1905            }
1906    
1907            /**
1908             * Moves the file entry to the new folder.
1909             *
1910             * @param  fileEntryId the primary key of the file entry
1911             * @param  newFolderId the primary key of the new folder
1912             * @param  serviceContext the service context to be applied
1913             * @return the file entry
1914             * @throws PortalException if the file entry or the new folder could not be
1915             *         found
1916             * @throws SystemException if a system exception occurred
1917             */
1918            public FileEntry moveFileEntry(
1919                            long fileEntryId, long newFolderId, ServiceContext serviceContext)
1920                    throws PortalException, SystemException {
1921    
1922                    Repository fromRepository = getRepository(0, fileEntryId, 0);
1923                    Repository toRepository = getRepository(newFolderId, serviceContext);
1924    
1925                    if (fromRepository.getRepositoryId() ==
1926                                    toRepository.getRepositoryId()) {
1927    
1928                            // Move file entries within repository
1929    
1930                            FileEntry fileEntry = fromRepository.moveFileEntry(
1931                                    fileEntryId, newFolderId, serviceContext);
1932    
1933                            return fileEntry;
1934                    }
1935    
1936                    // Move file entries between repositories
1937    
1938                    return moveFileEntries(
1939                            fileEntryId, newFolderId, fromRepository, toRepository,
1940                            serviceContext);
1941            }
1942    
1943            /**
1944             * Moves the folder to the new parent folder with the primary key.
1945             *
1946             * @param  folderId the primary key of the folder
1947             * @param  parentFolderId the primary key of the new parent folder
1948             * @param  serviceContext the service context to be applied
1949             * @return the file entry
1950             * @throws PortalException if the folder could not be found
1951             * @throws SystemException if a system exception occurred
1952             */
1953            public Folder moveFolder(
1954                            long folderId, long parentFolderId, ServiceContext serviceContext)
1955                    throws PortalException, SystemException {
1956    
1957                    Repository fromRepository = getRepository(folderId, 0, 0);
1958                    Repository toRepository = getRepository(parentFolderId, serviceContext);
1959    
1960                    if (fromRepository.getRepositoryId() ==
1961                                    toRepository.getRepositoryId()) {
1962    
1963                            // Move file entries within repository
1964    
1965                            Folder folder = fromRepository.moveFolder(
1966                                    folderId, parentFolderId, serviceContext);
1967    
1968                            return folder;
1969                    }
1970    
1971                    // Move file entries between repositories
1972    
1973                    return moveFolders(
1974                            folderId, parentFolderId, fromRepository, toRepository,
1975                            serviceContext);
1976            }
1977    
1978            /**
1979             * Refreshes the lock for the file entry. This method is primarily used by
1980             * WebDAV.
1981             *
1982             * @param  lockUuid the lock's universally unique identifier
1983             * @param  expirationTime the time in milliseconds before the lock expires.
1984             *         If the value is <code>0</code>, the default expiration time will
1985             *         be used from <code>portal.properties>.
1986             * @return the lock object
1987             * @throws PortalException if the file entry or lock could not be found
1988             * @throws SystemException if a system exception occurred
1989             */
1990            public Lock refreshFileEntryLock(String lockUuid, long expirationTime)
1991                    throws PortalException, SystemException {
1992    
1993                    Lock lock = lockLocalService.getLockByUuid(lockUuid);
1994    
1995                    long fileEntryId = GetterUtil.getLong(lock.getKey());
1996    
1997                    Repository repository = getRepository(0, fileEntryId, 0);
1998    
1999                    return repository.refreshFileEntryLock(lockUuid, expirationTime);
2000            }
2001    
2002            /**
2003             * Refreshes the lock for the folder. This method is primarily used by
2004             * WebDAV.
2005             *
2006             * @param  lockUuid the lock's universally unique identifier
2007             * @param  expirationTime the time in milliseconds before the lock expires.
2008             *         If the value is <code>0</code>, the default expiration time will
2009             *         be used from <code>portal.properties>.
2010             * @return the lock object
2011             * @throws PortalException if the folder or lock could not be found
2012             * @throws SystemException if a system exception occurred
2013             */
2014            public Lock refreshFolderLock(String lockUuid, long expirationTime)
2015                    throws PortalException, SystemException {
2016    
2017                    Lock lock = lockLocalService.getLockByUuid(lockUuid);
2018    
2019                    long folderId = GetterUtil.getLong(lock.getKey());
2020    
2021                    Repository repository = getRepository(0, folderId, 0);
2022    
2023                    return repository.refreshFolderLock(lockUuid, expirationTime);
2024            }
2025    
2026            /**
2027             * Reverts the file entry to a previous version. A new version will be
2028             * created based on the previous version and metadata.
2029             *
2030             * @param  fileEntryId the primary key of the file entry
2031             * @param  version the version to revert back to
2032             * @param  serviceContext the service context to be applied
2033             * @throws PortalException if the file entry or version could not be found
2034             * @throws SystemException if a system exception occurred
2035             */
2036            public void revertFileEntry(
2037                            long fileEntryId, String version, ServiceContext serviceContext)
2038                    throws PortalException, SystemException {
2039    
2040                    Repository repository = getRepository(0, fileEntryId, 0);
2041    
2042                    repository.revertFileEntry(fileEntryId, version, serviceContext);
2043    
2044                    FileEntry fileEntry = getFileEntry(fileEntryId);
2045    
2046                    dlAppHelperLocalService.updateFileEntry(
2047                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
2048            }
2049    
2050            public Hits search(long repositoryId, SearchContext searchContext)
2051                    throws SearchException {
2052    
2053                    try {
2054                            Repository repository = getRepository(repositoryId);
2055    
2056                            return repository.search(searchContext);
2057                    }
2058                    catch (Exception e) {
2059                            throw new SearchException(e);
2060                    }
2061            }
2062    
2063            public Hits search(
2064                            long repositoryId, SearchContext searchContext, Query query)
2065                    throws SearchException {
2066    
2067                    try {
2068                            Repository repository = getRepository(repositoryId);
2069    
2070                            return repository.search(searchContext, query);
2071                    }
2072                    catch (Exception e) {
2073                            throw new SearchException(e);
2074                    }
2075            }
2076    
2077            public void unlockFileEntry(long fileEntryId)
2078                    throws PortalException, SystemException {
2079    
2080                    Repository repository = getRepository(0, fileEntryId, 0);
2081    
2082                    repository.unlockFileEntry(fileEntryId);
2083            }
2084    
2085            public void unlockFileEntry(long fileEntryId, String lockUuid)
2086                    throws PortalException, SystemException {
2087    
2088                    Repository repository = getRepository(0, fileEntryId, 0);
2089    
2090                    repository.unlockFileEntry(fileEntryId, lockUuid);
2091            }
2092    
2093            /**
2094             * Unlocks the folder. This method is primarily used by WebDAV.
2095             *
2096             * @param  repositoryId the primary key of the repository
2097             * @param  folderId the primary key of the folder
2098             * @param  lockUuid the lock's universally unique identifier
2099             * @throws PortalException if the repository or folder could not be found
2100             * @throws SystemException if a system exception occurred
2101             */
2102            public void unlockFolder(long repositoryId, long folderId, String lockUuid)
2103                    throws PortalException, SystemException {
2104    
2105                    Repository repository = getRepository(repositoryId);
2106    
2107                    repository.unlockFolder(folderId, lockUuid);
2108            }
2109    
2110            /**
2111             * Unlocks the folder. This method is primarily used by WebDAV.
2112             *
2113             * @param  repositoryId the primary key of the repository
2114             * @param  parentFolderId the primary key of the parent folder
2115             * @param  name the folder's name
2116             * @param  lockUuid the lock's universally unique identifier
2117             * @throws PortalException if the repository or folder could not be found
2118             * @throws SystemException if a system exception occurred
2119             */
2120            public void unlockFolder(
2121                            long repositoryId, long parentFolderId, String name,
2122                            String lockUuid)
2123                    throws PortalException, SystemException {
2124    
2125                    Repository repository = getRepository(repositoryId);
2126    
2127                    repository.unlockFolder(parentFolderId, name, lockUuid);
2128            }
2129    
2130            /**
2131             * Updates a file entry and associated metadata based on a byte array
2132             * object. If the file data is <code>null</code>, then only the associated
2133             * metadata (i.e., <code>title</code>, <code>description</code>, and
2134             * parameters in the <code>serviceContext</code>) will be updated.
2135             *
2136             * <p>
2137             * This method takes two file names, the <code>sourceFileName</code> and the
2138             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
2139             * name of the actual file being uploaded. The <code>title</code>
2140             * corresponds to a name the client wishes to assign this file after it has
2141             * been uploaded to the portal.
2142             * </p>
2143             *
2144             * @param  fileEntryId the primary key of the file entry
2145             * @param  sourceFileName the original file's name (optionally
2146             *         <code>null</code>)
2147             * @param  mimeType the file's MIME type (optionally <code>null</code>)
2148             * @param  title the new name to be assigned to the file (optionally <code>
2149             *         <code>null</code></code>)
2150             * @param  description the file's new description
2151             * @param  changeLog the file's version change log (optionally
2152             *         <code>null</code>)
2153             * @param  majorVersion whether the new file version is a major version
2154             * @param  bytes the file's data (optionally <code>null</code>)
2155             * @param  serviceContext the service context to be applied. Can set the
2156             *         asset category IDs, asset tag names, and expando bridge
2157             *         attributes for the file entry. In a Liferay repository, it may
2158             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
2159             *         type </li> <li> fieldsMap - mapping for fields associated with a
2160             *         custom file entry type </li> </ul>
2161             * @return the file entry
2162             * @throws PortalException if the file entry could not be found
2163             * @throws SystemException if a system exception occurred
2164             */
2165            public FileEntry updateFileEntry(
2166                            long fileEntryId, String sourceFileName, String mimeType,
2167                            String title, String description, String changeLog,
2168                            boolean majorVersion, byte[] bytes, ServiceContext serviceContext)
2169                    throws PortalException, SystemException {
2170    
2171                    File file = null;
2172    
2173                    try {
2174                            if ((bytes != null) && (bytes.length > 0)) {
2175                                    file = FileUtil.createTempFile(bytes);
2176                            }
2177    
2178                            return updateFileEntry(
2179                                    fileEntryId, sourceFileName, mimeType, title, description,
2180                                    changeLog, majorVersion, file, serviceContext);
2181                    }
2182                    catch (IOException ioe) {
2183                            throw new SystemException("Unable to write temporary file", ioe);
2184                    }
2185                    finally {
2186                            FileUtil.delete(file);
2187                    }
2188            }
2189    
2190            /**
2191             * Updates a file entry and associated metadata based on a {@link File}
2192             * object. If the file data is <code>null</code>, then only the associated
2193             * metadata (i.e., <code>title</code>, <code>description</code>, and
2194             * parameters in the <code>serviceContext</code>) will be updated.
2195             *
2196             * <p>
2197             * This method takes two file names, the <code>sourceFileName</code> and the
2198             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
2199             * name of the actual file being uploaded. The <code>title</code>
2200             * corresponds to a name the client wishes to assign this file after it has
2201             * been uploaded to the portal.
2202             * </p>
2203             *
2204             * @param  fileEntryId the primary key of the file entry
2205             * @param  sourceFileName the original file's name (optionally
2206             *         <code>null</code>)
2207             * @param  mimeType the file's MIME type (optionally <code>null</code>)
2208             * @param  title the new name to be assigned to the file (optionally <code>
2209             *         <code>null</code></code>)
2210             * @param  description the file's new description
2211             * @param  changeLog the file's version change log (optionally
2212             *         <code>null</code>)
2213             * @param  majorVersion whether the new file version is a major version
2214             * @param  file EntryId the primary key of the file entry
2215             * @param  serviceContext the service context to be applied. Can set the
2216             *         asset category IDs, asset tag names, and expando bridge
2217             *         attributes for the file entry. In a Liferay repository, it may
2218             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
2219             *         type </li> <li> fieldsMap - mapping for fields associated with a
2220             *         custom file entry type </li> </ul>
2221             * @return the file entry
2222             * @throws PortalException if the file entry could not be found
2223             * @throws SystemException if a system exception occurred
2224             */
2225            public FileEntry updateFileEntry(
2226                            long fileEntryId, String sourceFileName, String mimeType,
2227                            String title, String description, String changeLog,
2228                            boolean majorVersion, File file, ServiceContext serviceContext)
2229                    throws PortalException, SystemException {
2230    
2231                    if ((file == null) || !file.exists() || (file.length() == 0)) {
2232                            return updateFileEntry(
2233                                    fileEntryId, sourceFileName, mimeType, title, description,
2234                                    changeLog, majorVersion, null, 0, serviceContext);
2235                    }
2236    
2237                    Repository repository = getRepository(0, fileEntryId, 0);
2238    
2239                    FileEntry fileEntry = repository.updateFileEntry(
2240                            fileEntryId, sourceFileName, mimeType, title, description,
2241                            changeLog, majorVersion, file, serviceContext);
2242    
2243                    DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
2244    
2245                    dlAppHelperLocalService.updateFileEntry(
2246                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
2247    
2248                    return fileEntry;
2249            }
2250    
2251            /**
2252             * Updates a file entry and associated metadata based on an {@link
2253             * InputStream} object. If the file data is <code>null</code>, then only the
2254             * associated metadata (i.e., <code>title</code>, <code>description</code>,
2255             * and parameters in the <code>serviceContext</code>) will be updated.
2256             *
2257             * <p>
2258             * This method takes two file names, the <code>sourceFileName</code> and the
2259             * <code>title</code>. The <code>sourceFileName</code> corresponds to the
2260             * name of the actual file being uploaded. The <code>title</code>
2261             * corresponds to a name the client wishes to assign this file after it has
2262             * been uploaded to the portal.
2263             * </p>
2264             *
2265             * @param  fileEntryId the primary key of the file entry
2266             * @param  sourceFileName the original file's name (optionally
2267             *         <code>null</code>)
2268             * @param  mimeType the file's MIME type (optionally <code>null</code>)
2269             * @param  title the new name to be assigned to the file (optionally <code>
2270             *         <code>null</code></code>)
2271             * @param  description the file's new description
2272             * @param  changeLog the file's version change log (optionally
2273             *         <code>null</code>)
2274             * @param  majorVersion whether the new file version is a major version
2275             * @param  is the file's data (optionally <code>null</code>)
2276             * @param  size the file's size (optionally <code>0</code>)
2277             * @param  serviceContext the service context to be applied. Can set the
2278             *         asset category IDs, asset tag names, and expando bridge
2279             *         attributes for the file entry. In a Liferay repository, it may
2280             *         include:  <ul> <li> fileEntryTypeId - ID for a custom file entry
2281             *         type </li> <li> fieldsMap - mapping for fields associated with a
2282             *         custom file entry type </li> </ul>
2283             * @return the file entry
2284             * @throws PortalException if the file entry could not be found
2285             * @throws SystemException if a system exception occurred
2286             */
2287            public FileEntry updateFileEntry(
2288                            long fileEntryId, String sourceFileName, String mimeType,
2289                            String title, String description, String changeLog,
2290                            boolean majorVersion, InputStream is, long size,
2291                            ServiceContext serviceContext)
2292                    throws PortalException, SystemException {
2293    
2294                    Repository repository = getRepository(0, fileEntryId, 0);
2295    
2296                    FileEntry fileEntry = repository.updateFileEntry(
2297                            fileEntryId, sourceFileName, mimeType, title, description,
2298                            changeLog, majorVersion, is, size, serviceContext);
2299    
2300                    if (is != null) {
2301                            DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
2302                    }
2303    
2304                    dlAppHelperLocalService.updateFileEntry(
2305                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
2306    
2307                    return fileEntry;
2308            }
2309    
2310            public FileEntry updateFileEntryAndCheckIn(
2311                            long fileEntryId, String sourceFileName, String mimeType,
2312                            String title, String description, String changeLog,
2313                            boolean majorVersion, File file, ServiceContext serviceContext)
2314                    throws PortalException, SystemException {
2315    
2316                    if ((file == null) || !file.exists() || (file.length() == 0)) {
2317                            return updateFileEntryAndCheckIn(
2318                                    fileEntryId, sourceFileName, mimeType, title, description,
2319                                    changeLog, majorVersion, null, 0, serviceContext);
2320                    }
2321    
2322                    Repository repository = getRepository(0, fileEntryId, 0);
2323    
2324                    FileEntry fileEntry = repository.updateFileEntry(
2325                            fileEntryId, sourceFileName, mimeType, title, description,
2326                            changeLog, majorVersion, file, serviceContext);
2327    
2328                    DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
2329    
2330                    repository.checkInFileEntry(
2331                            fileEntryId, majorVersion, changeLog, serviceContext);
2332    
2333                    dlAppHelperLocalService.updateFileEntry(
2334                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
2335    
2336                    return fileEntry;
2337            }
2338    
2339            public FileEntry updateFileEntryAndCheckIn(
2340                            long fileEntryId, String sourceFileName, String mimeType,
2341                            String title, String description, String changeLog,
2342                            boolean majorVersion, InputStream is, long size,
2343                            ServiceContext serviceContext)
2344                    throws PortalException, SystemException {
2345    
2346                    Repository repository = getRepository(0, fileEntryId, 0);
2347    
2348                    FileEntry fileEntry = repository.updateFileEntry(
2349                            fileEntryId, sourceFileName, mimeType, title, description,
2350                            changeLog, majorVersion, is, size, serviceContext);
2351    
2352                    if (is != null) {
2353                            DLProcessorRegistryUtil.cleanUp(fileEntry.getLatestFileVersion());
2354                    }
2355    
2356                    repository.checkInFileEntry(
2357                            fileEntryId, majorVersion, changeLog, serviceContext);
2358    
2359                    dlAppHelperLocalService.updateFileEntry(
2360                            getUserId(), fileEntry, fileEntry.getFileVersion(), serviceContext);
2361    
2362                    return fileEntry;
2363            }
2364    
2365            /**
2366             * Updates a file shortcut to the existing file entry. This method is only
2367             * supported by the Liferay repository.
2368             *
2369             * @param  fileShortcutId the primary key of the file shortcut
2370             * @param  folderId the primary key of the file shortcut's parent folder
2371             * @param  toFileEntryId the primary key of the file shortcut's file entry
2372             * @param  serviceContext the service context to be applied. Can set the
2373             *         asset category IDs, asset tag names, and expando bridge
2374             *         attributes for the file entry.
2375             * @return the file shortcut
2376             * @throws PortalException if the file shortcut, folder, or file entry could
2377             *         not be found
2378             * @throws SystemException if a system exception occurred
2379             */
2380            public DLFileShortcut updateFileShortcut(
2381                            long fileShortcutId, long folderId, long toFileEntryId,
2382                            ServiceContext serviceContext)
2383                    throws PortalException, SystemException {
2384    
2385                    return dlFileShortcutService.updateFileShortcut(
2386                            fileShortcutId, folderId, toFileEntryId, serviceContext);
2387            }
2388    
2389            /**
2390             * Updates the folder.
2391             *
2392             * @param  folderId the primary key of the folder
2393             * @param  name the folder's new name
2394             * @param  description the folder's new description
2395             * @param  serviceContext the service context to be applied. In a Liferay
2396             *         repository, it may include:  <ul> <li> defaultFileEntryTypeId -
2397             *         the file entry type to default all Liferay file entries to </li>
2398             *         <li> fileEntryTypeSearchContainerPrimaryKeys - a comma-delimited
2399             *         list of file entry type primary keys allowed in the given folder
2400             *         and all descendants </li> <li> overrideFileEntryTypes - boolean
2401             *         specifying whether to override ancestral folder's restriction of
2402             *         file entry types allowed </li> <li> workflowDefinitionXYZ - the
2403             *         workflow definition name specified per file entry type. The
2404             *         parameter name must be the string <code>workflowDefinition</code>
2405             *         appended by the <code>fileEntryTypeId</code> (optionally
2406             *         <code>0</code>). </li> </ul>
2407             * @return the folder
2408             * @throws PortalException if the current or new parent folder could not be
2409             *         found or if the new parent folder's information was invalid
2410             * @throws SystemException if a system exception occurred
2411             */
2412            public Folder updateFolder(
2413                            long folderId, String name, String description,
2414                            ServiceContext serviceContext)
2415                    throws PortalException, SystemException {
2416    
2417                    Repository repository = null;
2418    
2419                    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
2420                            repository = getRepository(serviceContext.getScopeGroupId());
2421                    }
2422                    else {
2423                            repository = getRepository(folderId, 0, 0);
2424                    }
2425    
2426                    return repository.updateFolder(
2427                            folderId, name, description, serviceContext);
2428            }
2429    
2430            /**
2431             * Returns <code>true</code> if the file entry is checked out. This method
2432             * is primarily used by WebDAV.
2433             *
2434             * @param  repositoryId the primary key for the repository
2435             * @param  fileEntryId the primary key for the file entry
2436             * @param  lockUuid the lock's universally unique identifier
2437             * @return <code>true</code> if the file entry is checked out;
2438             *         <code>false</code> otherwise
2439             * @throws PortalException if the file entry could not be found
2440             * @throws SystemException if a system exception occurred
2441             */
2442            public boolean verifyFileEntryCheckOut(
2443                            long repositoryId, long fileEntryId, String lockUuid)
2444                    throws PortalException, SystemException {
2445    
2446                    Repository repository = getRepository(repositoryId);
2447    
2448                    return repository.verifyFileEntryCheckOut(fileEntryId, lockUuid);
2449            }
2450    
2451            public boolean verifyFileEntryLock(
2452                            long repositoryId, long fileEntryId, String lockUuid)
2453                    throws PortalException, SystemException {
2454    
2455                    Repository repository = getRepository(repositoryId);
2456    
2457                    return repository.verifyFileEntryLock(fileEntryId, lockUuid);
2458            }
2459    
2460            /**
2461             * Returns <code>true</code> if the inheritable lock exists. This method is
2462             * primarily used by WebDAV.
2463             *
2464             * @param  repositoryId the primary key for the repository
2465             * @param  folderId the primary key for the folder
2466             * @param  lockUuid the lock's universally unique identifier
2467             * @return <code>true</code> if the inheritable lock exists;
2468             *         <code>false</code> otherwise
2469             * @throws PortalException if the folder could not be found
2470             * @throws SystemException if a system exception occurred
2471             */
2472            public boolean verifyInheritableLock(
2473                            long repositoryId, long folderId, String lockUuid)
2474                    throws PortalException, SystemException {
2475    
2476                    Repository repository = getRepository(repositoryId);
2477    
2478                    return repository.verifyInheritableLock(folderId, lockUuid);
2479            }
2480    
2481            protected FileEntry copyFileEntry(
2482                            Repository toRepository, FileEntry fileEntry, long newFolderId,
2483                            ServiceContext serviceContext)
2484                    throws PortalException, SystemException {
2485    
2486                    List<FileVersion> fileVersions = fileEntry.getFileVersions(
2487                            WorkflowConstants.STATUS_ANY);
2488    
2489                    FileVersion latestFileVersion = fileVersions.get(
2490                            fileVersions.size() - 1);
2491    
2492                    FileEntry destinationFileEntry = toRepository.addFileEntry(
2493                            newFolderId, fileEntry.getTitle(), latestFileVersion.getMimeType(),
2494                            latestFileVersion.getTitle(), latestFileVersion.getDescription(),
2495                            StringPool.BLANK, latestFileVersion.getContentStream(false),
2496                            latestFileVersion.getSize(), serviceContext);
2497    
2498                    for (int i = fileVersions.size() - 2; i >= 0 ; i--) {
2499                            FileVersion fileVersion = fileVersions.get(i);
2500    
2501                            FileVersion previousFileVersion = fileVersions.get(i + 1);
2502    
2503                            try {
2504                                    destinationFileEntry = toRepository.updateFileEntry(
2505                                            destinationFileEntry.getFileEntryId(), fileEntry.getTitle(),
2506                                            destinationFileEntry.getMimeType(),
2507                                            destinationFileEntry.getTitle(),
2508                                            destinationFileEntry.getDescription(), StringPool.BLANK,
2509                                            isMajorVersion(previousFileVersion, fileVersion),
2510                                            fileVersion.getContentStream(false), fileVersion.getSize(),
2511                                            serviceContext);
2512                            }
2513                            catch (PortalException pe) {
2514                                    toRepository.deleteFileEntry(
2515                                            destinationFileEntry.getFileEntryId());
2516    
2517                                    throw pe;
2518                            }
2519                    }
2520    
2521                    dlAppHelperLocalService.addFileEntry(
2522                            getUserId(), destinationFileEntry,
2523                            destinationFileEntry.getFileVersion(), serviceContext);
2524    
2525                    return destinationFileEntry;
2526            }
2527    
2528            protected void copyFolder(
2529                            Repository repository, Folder srcFolder, Folder destFolder,
2530                            ServiceContext serviceContext)
2531                    throws PortalException, SystemException {
2532    
2533                    Queue<Folder[]> folders = new LinkedList<Folder[]>();
2534                    final List<FileEntry> fileEntries = new ArrayList<FileEntry>();
2535    
2536                    Folder curSrcFolder = srcFolder;
2537                    Folder curDestFolder = destFolder;
2538    
2539                    while (true) {
2540                            List<FileEntry> srcFileEntries = repository.getFileEntries(
2541                                    curSrcFolder.getFolderId(), QueryUtil.ALL_POS,
2542                                    QueryUtil.ALL_POS, null);
2543    
2544                            for (FileEntry srcFileEntry : srcFileEntries) {
2545                                    try {
2546                                            FileEntry fileEntry = repository.copyFileEntry(
2547                                                    curDestFolder.getGroupId(),
2548                                                    srcFileEntry.getFileEntryId(),
2549                                                    curDestFolder.getFolderId(), serviceContext);
2550    
2551                                            dlAppHelperLocalService.addFileEntry(
2552                                                    getUserId(), fileEntry, fileEntry.getFileVersion(),
2553                                                    serviceContext);
2554    
2555                                            fileEntries.add(fileEntry);
2556                                    }
2557                                    catch (Exception e) {
2558                                            _log.error(e, e);
2559    
2560                                            continue;
2561                                    }
2562                            }
2563    
2564                            List<Folder> srcSubfolders = repository.getFolders(
2565                                    curSrcFolder.getFolderId(), false, QueryUtil.ALL_POS,
2566                                    QueryUtil.ALL_POS, null);
2567    
2568                            for (Folder srcSubfolder : srcSubfolders) {
2569                                    Folder destSubfolder = repository.addFolder(
2570                                            curDestFolder.getFolderId(), srcSubfolder.getName(),
2571                                            srcSubfolder.getDescription(), serviceContext);
2572    
2573                                    folders.offer(new Folder[] {srcSubfolder, destSubfolder});
2574                            }
2575    
2576                            Folder[] next = folders.poll();
2577    
2578                            if (next == null) {
2579                                    break;
2580                            }
2581                            else {
2582                                    curSrcFolder = next[0];
2583                                    curDestFolder = next[1];
2584                            }
2585                    }
2586    
2587                    TransactionCommitCallbackUtil.registerCallback(
2588                            new Callable<Void>() {
2589    
2590                                    public Void call() throws Exception {
2591                                            for (FileEntry fileEntry : fileEntries) {
2592                                                    DLProcessorRegistryUtil.trigger(fileEntry);
2593                                            }
2594    
2595                                            return null;
2596                                    }
2597    
2598                            });
2599            }
2600    
2601            protected void deleteFileEntry(
2602                            long oldFileEntryId, long newFileEntryId, Repository fromRepository,
2603                            Repository toRepository)
2604                    throws PortalException, SystemException {
2605    
2606                    try {
2607                            FileEntry fileEntry = fromRepository.getFileEntry(oldFileEntryId);
2608    
2609                            dlAppHelperLocalService.deleteFileEntry(fileEntry);
2610    
2611                            fromRepository.deleteFileEntry(oldFileEntryId);
2612                    }
2613                    catch (PortalException pe) {
2614                            FileEntry fileEntry = toRepository.getFileEntry(newFileEntryId);
2615    
2616                            toRepository.deleteFileEntry(newFileEntryId);
2617    
2618                            dlAppHelperLocalService.deleteFileEntry(fileEntry);
2619    
2620                            throw pe;
2621                    }
2622            }
2623    
2624            protected Repository getRepository(long repositoryId)
2625                    throws PortalException, SystemException {
2626    
2627                    return repositoryService.getRepositoryImpl(repositoryId);
2628            }
2629    
2630            protected Repository getRepository(
2631                            long folderId, long fileEntryId, long fileVersionId)
2632                    throws PortalException, SystemException {
2633    
2634                    return repositoryService.getRepositoryImpl(
2635                            folderId, fileEntryId, fileVersionId);
2636            }
2637    
2638            protected Repository getRepository(
2639                            long folderId, ServiceContext serviceContext)
2640                    throws PortalException, SystemException{
2641    
2642                    Repository repository = null;
2643    
2644                    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
2645                            repository = getRepository(serviceContext.getScopeGroupId());
2646                    }
2647                    else {
2648                            repository = getRepository(folderId, 0, 0);
2649                    }
2650    
2651                    return repository;
2652            }
2653    
2654            protected boolean isMajorVersion(
2655                    FileVersion previousFileVersion, FileVersion currentFileVersion) {
2656    
2657                    long currentVersion = GetterUtil.getLong(
2658                            currentFileVersion.getVersion());
2659                    long previousVersion = GetterUtil.getLong(
2660                            previousFileVersion.getVersion());
2661    
2662                    return (currentVersion - previousVersion) >= 1;
2663            }
2664    
2665            protected FileEntry moveFileEntries(
2666                            long fileEntryId, long newFolderId, Repository fromRepository,
2667                            Repository toRepository, ServiceContext serviceContext)
2668                    throws SystemException, PortalException {
2669    
2670                    FileEntry sourceFileEntry = fromRepository.getFileEntry(fileEntryId);
2671    
2672                    FileEntry destinationFileEntry = copyFileEntry(
2673                            toRepository, sourceFileEntry, newFolderId, serviceContext);
2674    
2675                    deleteFileEntry(
2676                            fileEntryId, destinationFileEntry.getFileEntryId(), fromRepository,
2677                            toRepository);
2678    
2679                    return destinationFileEntry;
2680            }
2681    
2682            protected Folder moveFolders(
2683                            long folderId, long parentFolderId, Repository fromRepository,
2684                            Repository toRepository, ServiceContext serviceContext)
2685                    throws PortalException, SystemException{
2686    
2687                    Folder folder = fromRepository.getFolder(folderId);
2688    
2689                    Folder newFolder = toRepository.addFolder(
2690                            parentFolderId, folder.getName(), folder.getDescription(),
2691                            serviceContext);
2692    
2693                    List<Object> foldersAndFileEntriesAndFileShortcuts =
2694                            getFoldersAndFileEntriesAndFileShortcuts(
2695                                    fromRepository.getRepositoryId(), folderId,
2696                                    WorkflowConstants.STATUS_ANY, true, QueryUtil.ALL_POS,
2697                                    QueryUtil.ALL_POS);
2698    
2699                    try {
2700                            for (Object folderAndFileEntryAndFileShortcut :
2701                                            foldersAndFileEntriesAndFileShortcuts) {
2702    
2703                                    if (folderAndFileEntryAndFileShortcut instanceof FileEntry) {
2704                                            FileEntry fileEntry =
2705                                                    (FileEntry)folderAndFileEntryAndFileShortcut;
2706    
2707                                            copyFileEntry(
2708                                                    toRepository, fileEntry, newFolder.getFolderId(),
2709                                                    serviceContext);
2710                                    }
2711                                    else if (folderAndFileEntryAndFileShortcut instanceof Folder) {
2712                                            Folder currentFolder =
2713                                                    (Folder)folderAndFileEntryAndFileShortcut;
2714    
2715                                            moveFolders(
2716                                                    currentFolder.getFolderId(), newFolder.getFolderId(),
2717                                                    fromRepository, toRepository, serviceContext);
2718    
2719                                    }
2720                                    else if (folderAndFileEntryAndFileShortcut
2721                                                            instanceof DLFileShortcut) {
2722    
2723                                            if (newFolder.isSupportsShortcuts()) {
2724                                                    DLFileShortcut dlFileShorcut =
2725                                                            (DLFileShortcut)folderAndFileEntryAndFileShortcut;
2726    
2727                                                    dlFileShortcutService.addFileShortcut(
2728                                                            dlFileShorcut.getGroupId(), newFolder.getFolderId(),
2729                                                            dlFileShorcut.getToFileEntryId(), serviceContext);
2730                                            }
2731                                    }
2732                            }
2733                    }
2734                    catch (PortalException pe) {
2735                            toRepository.deleteFolder(newFolder.getFolderId());
2736    
2737                            throw pe;
2738                    }
2739    
2740                    try {
2741                            fromRepository.deleteFolder(folderId);
2742                    }
2743                    catch (PortalException pe) {
2744                            toRepository.deleteFolder(newFolder.getFolderId());
2745    
2746                            throw pe;
2747                    }
2748    
2749                    return newFolder;
2750            }
2751    
2752            private static Log _log = LogFactoryUtil.getLog(DLAppServiceImpl.class);
2753    
2754    }