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