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