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.portal.repository.liferayrepository;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.repository.Repository;
022    import com.liferay.portal.kernel.repository.model.FileEntry;
023    import com.liferay.portal.kernel.repository.model.FileVersion;
024    import com.liferay.portal.kernel.repository.model.Folder;
025    import com.liferay.portal.kernel.search.Hits;
026    import com.liferay.portal.kernel.search.Indexer;
027    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
028    import com.liferay.portal.kernel.search.Query;
029    import com.liferay.portal.kernel.search.SearchContext;
030    import com.liferay.portal.kernel.search.SearchEngineUtil;
031    import com.liferay.portal.kernel.search.SearchException;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.ParamUtil;
034    import com.liferay.portal.kernel.util.SortedArrayList;
035    import com.liferay.portal.kernel.workflow.WorkflowConstants;
036    import com.liferay.portal.model.Lock;
037    import com.liferay.portal.repository.liferayrepository.model.LiferayFileEntry;
038    import com.liferay.portal.repository.liferayrepository.model.LiferayFileVersion;
039    import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
040    import com.liferay.portal.service.RepositoryLocalService;
041    import com.liferay.portal.service.RepositoryService;
042    import com.liferay.portal.service.ResourceLocalService;
043    import com.liferay.portal.service.ServiceContext;
044    import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
045    import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
046    import com.liferay.portlet.documentlibrary.NoSuchFolderException;
047    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
048    import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
049    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
050    import com.liferay.portlet.documentlibrary.model.DLFolder;
051    import com.liferay.portlet.documentlibrary.service.DLAppHelperLocalService;
052    import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService;
053    import com.liferay.portlet.documentlibrary.service.DLFileEntryService;
054    import com.liferay.portlet.documentlibrary.service.DLFileVersionLocalService;
055    import com.liferay.portlet.documentlibrary.service.DLFileVersionService;
056    import com.liferay.portlet.documentlibrary.service.DLFolderLocalService;
057    import com.liferay.portlet.documentlibrary.service.DLFolderService;
058    import com.liferay.portlet.dynamicdatamapping.storage.Fields;
059    
060    import java.io.File;
061    import java.io.InputStream;
062    
063    import java.util.List;
064    import java.util.Map;
065    
066    /**
067     * @author Alexander Chow
068     */
069    public class LiferayRepository
070            extends LiferayRepositoryBase implements Repository {
071    
072            public LiferayRepository(
073                    RepositoryLocalService repositoryLocalService,
074                    RepositoryService repositoryService,
075                    DLAppHelperLocalService dlAppHelperLocalService,
076                    DLFileEntryLocalService dlFileEntryLocalService,
077                    DLFileEntryService dlFileEntryService,
078                    DLFileVersionLocalService dlFileVersionLocalService,
079                    DLFileVersionService dlFileVersionService,
080                    DLFolderLocalService dlFolderLocalService,
081                    DLFolderService dlFolderService,
082                    ResourceLocalService resourceLocalService, long repositoryId) {
083    
084                    super(
085                            repositoryLocalService, repositoryService, dlAppHelperLocalService,
086                            dlFileEntryLocalService, dlFileEntryService,
087                            dlFileVersionLocalService, dlFileVersionService,
088                            dlFolderLocalService, dlFolderService, resourceLocalService,
089                            repositoryId);
090            }
091    
092            public LiferayRepository(
093                    RepositoryLocalService repositoryLocalService,
094                    RepositoryService repositoryService,
095                    DLAppHelperLocalService dlAppHelperLocalService,
096                    DLFileEntryLocalService dlFileEntryLocalService,
097                    DLFileEntryService dlFileEntryService,
098                    DLFileVersionLocalService dlFileVersionLocalService,
099                    DLFileVersionService dlFileVersionService,
100                    DLFolderLocalService dlFolderLocalService,
101                    DLFolderService dlFolderService,
102                    ResourceLocalService resourceLocalService, long folderId,
103                    long fileEntryId, long fileVersionId) {
104    
105                    super(
106                            repositoryLocalService, repositoryService, dlAppHelperLocalService,
107                            dlFileEntryLocalService, dlFileEntryService,
108                            dlFileVersionLocalService, dlFileVersionService,
109                            dlFolderLocalService, dlFolderService, resourceLocalService,
110                            folderId, fileEntryId, fileVersionId);
111            }
112    
113            public FileEntry addFileEntry(
114                            long folderId, String sourceFileName, String mimeType, String title,
115                            String description, String changeLog, File file,
116                            ServiceContext serviceContext)
117                    throws PortalException, SystemException {
118    
119                    long fileEntryTypeId = ParamUtil.getLong(
120                            serviceContext, "fileEntryTypeId", -1L);
121                    Map<String, Fields> fieldsMap = getFieldsMap(
122                            serviceContext, fileEntryTypeId);
123                    long size = 0;
124    
125                    if (file != null) {
126                            size = file.length();
127                    }
128    
129                    DLFileEntry dlFileEntry = dlFileEntryService.addFileEntry(
130                            getGroupId(), getRepositoryId(), toFolderId(folderId),
131                            sourceFileName, mimeType, title, description, changeLog,
132                            fileEntryTypeId, fieldsMap, file, null, size, serviceContext);
133    
134                    addFileEntryResources(dlFileEntry, serviceContext);
135    
136                    return new LiferayFileEntry(dlFileEntry);
137            }
138    
139            public FileEntry addFileEntry(
140                            long folderId, String sourceFileName, String mimeType, String title,
141                            String description, String changeLog, InputStream is, long size,
142                            ServiceContext serviceContext)
143                    throws PortalException, SystemException {
144    
145                    long fileEntryTypeId = ParamUtil.getLong(
146                            serviceContext, "fileEntryTypeId", -1L);
147                    Map<String, Fields> fieldsMap = getFieldsMap(
148                            serviceContext, fileEntryTypeId);
149    
150                    DLFileEntry dlFileEntry = dlFileEntryService.addFileEntry(
151                            getGroupId(), getRepositoryId(), toFolderId(folderId),
152                            sourceFileName, mimeType, title, description, changeLog,
153                            fileEntryTypeId, fieldsMap, null, is, size, serviceContext);
154    
155                    addFileEntryResources(dlFileEntry, serviceContext);
156    
157                    return new LiferayFileEntry(dlFileEntry);
158            }
159    
160            public Folder addFolder(
161                            long parentFolderId, String title, String description,
162                            ServiceContext serviceContext)
163                    throws PortalException, SystemException {
164    
165                    boolean mountPoint = ParamUtil.getBoolean(serviceContext, "mountPoint");
166    
167                    DLFolder dlFolder = dlFolderService.addFolder(
168                            getGroupId(), getRepositoryId(), mountPoint,
169                            toFolderId(parentFolderId), title, description, serviceContext);
170    
171                    return new LiferayFolder(dlFolder);
172            }
173    
174            public FileVersion cancelCheckOut(long fileEntryId)
175                    throws PortalException, SystemException {
176    
177                    DLFileVersion dlFileVersion = dlFileEntryService.cancelCheckOut(
178                            fileEntryId);
179    
180                    if (dlFileVersion != null) {
181                            return new LiferayFileVersion(dlFileVersion);
182                    }
183    
184                    return null;
185            }
186    
187            public void checkInFileEntry(
188                            long fileEntryId, boolean major, String changeLog,
189                            ServiceContext serviceContext)
190                    throws PortalException, SystemException {
191    
192                    dlFileEntryService.checkInFileEntry(
193                            fileEntryId, major, changeLog, serviceContext);
194            }
195    
196            /**
197             * @deprecated {@link #checkInFileEntry(long, String, ServiceContext)}
198             */
199            public void checkInFileEntry(long fileEntryId, String lockUuid)
200                    throws PortalException, SystemException {
201    
202                    checkInFileEntry(fileEntryId, lockUuid, new ServiceContext());
203            }
204    
205            public void checkInFileEntry(
206                            long fileEntryId, String lockUuid, ServiceContext serviceContext)
207                    throws PortalException, SystemException {
208    
209                    dlFileEntryService.checkInFileEntry(
210                            fileEntryId, lockUuid, serviceContext);
211            }
212    
213            public FileEntry checkOutFileEntry(
214                            long fileEntryId, ServiceContext serviceContext)
215                    throws PortalException, SystemException {
216    
217                    DLFileEntry dlFileEntry = dlFileEntryService.checkOutFileEntry(
218                            fileEntryId, serviceContext);
219    
220                    return new LiferayFileEntry(dlFileEntry);
221            }
222    
223            public FileEntry checkOutFileEntry(
224                            long fileEntryId, String owner, long expirationTime,
225                            ServiceContext serviceContext)
226                    throws PortalException, SystemException {
227    
228                    DLFileEntry dlFileEntry = dlFileEntryService.checkOutFileEntry(
229                            fileEntryId, owner, expirationTime, serviceContext);
230    
231                    return new LiferayFileEntry(dlFileEntry);
232            }
233    
234            public FileEntry copyFileEntry(
235                            long groupId, long fileEntryId, long destFolderId,
236                            ServiceContext serviceContext)
237                    throws PortalException, SystemException {
238    
239                    DLFileEntry dlFileEntry = dlFileEntryService.copyFileEntry(
240                            groupId, getRepositoryId(), fileEntryId, destFolderId,
241                            serviceContext);
242    
243                    return new LiferayFileEntry(dlFileEntry);
244            }
245    
246            public void deleteFileEntry(long fileEntryId)
247                    throws PortalException, SystemException {
248    
249                    dlFileEntryService.deleteFileEntry(fileEntryId);
250            }
251    
252            public void deleteFileEntry(long folderId, String title)
253                    throws PortalException, SystemException {
254    
255                    dlFileEntryService.deleteFileEntry(
256                            getGroupId(), toFolderId(folderId), title);
257            }
258    
259            public void deleteFileVersion(long fileEntryId, String version)
260                    throws PortalException, SystemException {
261    
262                    dlFileEntryService.deleteFileVersion(fileEntryId, version);
263            }
264    
265            public void deleteFolder(long folderId)
266                    throws PortalException, SystemException {
267    
268                    dlFolderService.deleteFolder(folderId);
269            }
270    
271            public void deleteFolder(long parentFolderId, String title)
272                    throws PortalException, SystemException {
273    
274                    dlFolderService.deleteFolder(
275                            getGroupId(), toFolderId(parentFolderId), title);
276            }
277    
278            public List<FileEntry> getFileEntries(
279                            long folderId, int start, int end, OrderByComparator obc)
280                    throws PortalException, SystemException {
281    
282                    List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
283                            getGroupId(), toFolderId(folderId), start, end, obc);
284    
285                    return toFileEntries(dlFileEntries);
286            }
287    
288            public List<FileEntry> getFileEntries(
289                            long folderId, long fileEntryTypeId, int start, int end,
290                            OrderByComparator obc)
291                    throws PortalException, SystemException {
292    
293                    List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
294                            getGroupId(), toFolderId(folderId), fileEntryTypeId, start, end,
295                            obc);
296    
297                    return toFileEntries(dlFileEntries);
298            }
299    
300            public List<FileEntry> getFileEntries(
301                            long folderId, String[] mimeTypes, int start, int end,
302                            OrderByComparator obc)
303                    throws PortalException, SystemException {
304    
305                    List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
306                            getGroupId(), toFolderId(folderId), mimeTypes, start, end, obc);
307    
308                    return toFileEntries(dlFileEntries);
309            }
310    
311            public List<Object> getFileEntriesAndFileShortcuts(
312                            long folderId, int status, int start, int end)
313                    throws PortalException, SystemException {
314    
315                    List<Object> dlFileEntriesAndFileShortcuts =
316                            dlFolderService.getFileEntriesAndFileShortcuts(
317                                    getGroupId(), toFolderId(folderId), status, start, end);
318    
319                    return toFileEntriesAndFolders(dlFileEntriesAndFileShortcuts);
320            }
321    
322            public int getFileEntriesAndFileShortcutsCount(long folderId, int status)
323                    throws SystemException {
324    
325                    return dlFolderService.getFileEntriesAndFileShortcutsCount(
326                            getGroupId(), toFolderId(folderId), status);
327            }
328    
329            public int getFileEntriesAndFileShortcutsCount(
330                            long folderId, int status, String[] mimeTypes)
331                    throws SystemException {
332    
333                    return dlFolderService.getFileEntriesAndFileShortcutsCount(
334                            getGroupId(), toFolderId(folderId), status, mimeTypes);
335            }
336    
337            public int getFileEntriesCount(long folderId) throws SystemException {
338                    return dlFileEntryService.getFileEntriesCount(
339                            getGroupId(), toFolderId(folderId));
340            }
341    
342            public int getFileEntriesCount(long folderId, long fileEntryTypeId)
343                    throws SystemException {
344    
345                    return dlFileEntryService.getFileEntriesCount(
346                            getGroupId(), toFolderId(folderId), fileEntryTypeId);
347            }
348    
349            public int getFileEntriesCount(long folderId, String[] mimeTypes)
350                    throws SystemException {
351    
352                    return dlFileEntryService.getFileEntriesCount(
353                            getGroupId(), folderId, mimeTypes);
354            }
355    
356            public FileEntry getFileEntry(long fileEntryId)
357                    throws PortalException, SystemException {
358    
359                    DLFileEntry dlFileEntry = dlFileEntryService.getFileEntry(fileEntryId);
360    
361                    return new LiferayFileEntry(dlFileEntry);
362            }
363    
364            public FileEntry getFileEntry(long folderId, String title)
365                    throws PortalException, SystemException {
366    
367                    DLFileEntry dlFileEntry = dlFileEntryService.getFileEntry(
368                            getGroupId(), toFolderId(folderId), title);
369    
370                    return new LiferayFileEntry(dlFileEntry);
371            }
372    
373            public FileEntry getFileEntryByUuid(String uuid)
374                    throws PortalException, SystemException {
375    
376                    DLFileEntry dlFileEntry =
377                            dlFileEntryService.getFileEntryByUuidAndGroupId(uuid, getGroupId());
378    
379                    return new LiferayFileEntry(dlFileEntry);
380            }
381    
382            public Lock getFileEntryLock(long fileEntryId) {
383                    return dlFileEntryService.getFileEntryLock(fileEntryId);
384            }
385    
386            public FileVersion getFileVersion(long fileVersionId)
387                    throws PortalException, SystemException {
388    
389                    DLFileVersion dlFileVersion = dlFileVersionService.getFileVersion(
390                            fileVersionId);
391    
392                    return new LiferayFileVersion(dlFileVersion);
393            }
394    
395            public Folder getFolder(long folderId)
396                    throws PortalException, SystemException {
397    
398                    DLFolder dlFolder = dlFolderService.getFolder(toFolderId(folderId));
399    
400                    return new LiferayFolder(dlFolder);
401            }
402    
403            public Folder getFolder(long parentFolderId, String title)
404                    throws PortalException, SystemException {
405    
406                    DLFolder dlFolder = dlFolderService.getFolder(
407                            getGroupId(), toFolderId(parentFolderId), title);
408    
409                    return new LiferayFolder(dlFolder);
410            }
411    
412            public List<Folder> getFolders(
413                            long parentFolderId, boolean includeMountfolders, int start,
414                            int end, OrderByComparator obc)
415                    throws PortalException, SystemException {
416    
417                    return getFolders(
418                            parentFolderId, WorkflowConstants.STATUS_APPROVED,
419                            includeMountfolders, start, end, obc);
420            }
421    
422            public List<Folder> getFolders(
423                            long parentFolderId, int status, boolean includeMountfolders,
424                            int start, int end, OrderByComparator obc)
425                    throws PortalException, SystemException {
426    
427                    List<DLFolder> dlFolders = dlFolderService.getFolders(
428                            getGroupId(), toFolderId(parentFolderId), status,
429                            includeMountfolders, start, end, obc);
430    
431                    return toFolders(dlFolders);
432            }
433    
434            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
435                            long folderId, int status, boolean includeMountFolders, int start,
436                            int end, OrderByComparator obc)
437                    throws PortalException, SystemException {
438    
439                    List<Object> dlFoldersAndFileEntriesAndFileShortcuts =
440                            dlFolderService.getFoldersAndFileEntriesAndFileShortcuts(
441                                    getGroupId(), toFolderId(folderId), status, includeMountFolders,
442                                    start, end, obc);
443    
444                    return toFileEntriesAndFolders(dlFoldersAndFileEntriesAndFileShortcuts);
445            }
446    
447            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
448                            long folderId, int status, String[] mimeTypes,
449                            boolean includeMountFolders, int start, int end,
450                            OrderByComparator obc)
451                    throws PortalException, SystemException {
452    
453                    List<Object> dlFoldersAndFileEntriesAndFileShortcuts =
454                            dlFolderService.getFoldersAndFileEntriesAndFileShortcuts(
455                                    getGroupId(), toFolderId(folderId), status, mimeTypes,
456                                    includeMountFolders, start, end, obc);
457    
458                    return toFileEntriesAndFolders(dlFoldersAndFileEntriesAndFileShortcuts);
459            }
460    
461            public int getFoldersAndFileEntriesAndFileShortcutsCount(
462                            long folderId, int status, boolean includeMountFolders)
463                    throws SystemException {
464    
465                    return dlFolderService.getFoldersAndFileEntriesAndFileShortcutsCount(
466                            getGroupId(), toFolderId(folderId), status, includeMountFolders);
467            }
468    
469            public int getFoldersAndFileEntriesAndFileShortcutsCount(
470                            long folderId, int status, String[] mimeTypes,
471                            boolean includeMountFolders)
472                    throws SystemException {
473    
474                    return dlFolderService.getFoldersAndFileEntriesAndFileShortcutsCount(
475                            getGroupId(), toFolderId(folderId), status, mimeTypes,
476                            includeMountFolders);
477            }
478    
479            public int getFoldersCount(long parentFolderId, boolean includeMountfolders)
480                    throws SystemException {
481    
482                    return getFoldersCount(
483                            parentFolderId, WorkflowConstants.STATUS_APPROVED,
484                            includeMountfolders);
485            }
486    
487            public int getFoldersCount(
488                            long parentFolderId, int status, boolean includeMountfolders)
489                    throws SystemException {
490    
491                    return dlFolderService.getFoldersCount(
492                            getGroupId(), toFolderId(parentFolderId), status,
493                            includeMountfolders);
494            }
495    
496            public int getFoldersFileEntriesCount(List<Long> folderIds, int status)
497                    throws SystemException {
498    
499                    return dlFileEntryService.getFoldersFileEntriesCount(
500                            getGroupId(), toFolderIds(folderIds), status);
501            }
502    
503            public List<Folder> getMountFolders(
504                            long parentFolderId, int start, int end, OrderByComparator obc)
505                    throws PortalException, SystemException {
506    
507                    List<DLFolder> dlFolders = dlFolderService.getMountFolders(
508                            getGroupId(), toFolderId(parentFolderId), start, end, obc);
509    
510                    return toFolders(dlFolders);
511            }
512    
513            public int getMountFoldersCount(long parentFolderId)
514                    throws SystemException {
515    
516                    return dlFolderService.getMountFoldersCount(
517                            getGroupId(), toFolderId(parentFolderId));
518            }
519    
520            public List<FileEntry> getRepositoryFileEntries(
521                            long userId, long rootFolderId, int start, int end,
522                            OrderByComparator obc)
523                    throws PortalException, SystemException {
524    
525                    List<DLFileEntry> dlFileEntries =
526                            dlFileEntryService.getGroupFileEntries(
527                                    getGroupId(), userId, toFolderId(rootFolderId), start, end,
528                                    obc);
529    
530                    return toFileEntries(dlFileEntries);
531            }
532    
533            public List<FileEntry> getRepositoryFileEntries(
534                            long userId, long rootFolderId, String[] mimeTypes, int status,
535                            int start, int end, OrderByComparator obc)
536                    throws PortalException, SystemException {
537    
538                    List<DLFileEntry> dlFileEntries =
539                            dlFileEntryService.getGroupFileEntries(
540                                    getGroupId(), userId, toFolderId(rootFolderId), mimeTypes,
541                                    status, start, end, obc);
542    
543                    return toFileEntries(dlFileEntries);
544            }
545    
546            public int getRepositoryFileEntriesCount(long userId, long rootFolderId)
547                    throws PortalException, SystemException {
548    
549                    return dlFileEntryService.getGroupFileEntriesCount(
550                            getGroupId(), userId, toFolderId(rootFolderId));
551            }
552    
553            public int getRepositoryFileEntriesCount(
554                            long userId, long rootFolderId, String[] mimeTypes, int status)
555                    throws PortalException, SystemException {
556    
557                    return dlFileEntryService.getGroupFileEntriesCount(
558                            getGroupId(), userId, toFolderId(rootFolderId), mimeTypes, status);
559            }
560    
561            public void getSubfolderIds(List<Long> folderIds, long folderId)
562                    throws PortalException, SystemException {
563    
564                    dlFolderService.getSubfolderIds(
565                            folderIds, getGroupId(), toFolderId(folderId));
566            }
567    
568            public List<Long> getSubfolderIds(long folderId, boolean recurse)
569                    throws PortalException, SystemException {
570    
571                    return dlFolderService.getSubfolderIds(
572                            getGroupId(), toFolderId(folderId), recurse);
573            }
574    
575            /**
576             * @deprecated {@link #checkOutFileEntry(long, ServiceContext)}
577             */
578            public Lock lockFileEntry(long fileEntryId)
579                    throws PortalException, SystemException {
580    
581                    FileEntry fileEntry = checkOutFileEntry(
582                            fileEntryId, new ServiceContext());
583    
584                    return fileEntry.getLock();
585            }
586    
587            /**
588             * @deprecated {@link #checkOutFileEntry(long, String, long,
589             *             ServiceContext)}
590             */
591            public Lock lockFileEntry(
592                            long fileEntryId, String owner, long expirationTime)
593                    throws PortalException, SystemException {
594    
595                    FileEntry fileEntry = checkOutFileEntry(
596                            fileEntryId, owner, expirationTime, new ServiceContext());
597    
598                    return fileEntry.getLock();
599            }
600    
601            public Lock lockFolder(long folderId)
602                    throws PortalException, SystemException {
603    
604                    return dlFolderService.lockFolder(toFolderId(folderId));
605            }
606    
607            public Lock lockFolder(
608                            long folderId, String owner, boolean inheritable,
609                            long expirationTime)
610                    throws PortalException, SystemException {
611    
612                    return dlFolderService.lockFolder(
613                            toFolderId(folderId), owner, inheritable, expirationTime);
614            }
615    
616            public FileEntry moveFileEntry(
617                            long fileEntryId, long newFolderId, ServiceContext serviceContext)
618                    throws PortalException, SystemException {
619    
620                    DLFileEntry dlFileEntry = dlFileEntryService.moveFileEntry(
621                            fileEntryId, toFolderId(newFolderId), serviceContext);
622    
623                    return new LiferayFileEntry(dlFileEntry);
624            }
625    
626            public Folder moveFolder(
627                            long folderId, long parentFolderId, ServiceContext serviceContext)
628                    throws PortalException, SystemException {
629    
630                    DLFolder dlFolder = dlFolderService.moveFolder(
631                            toFolderId(folderId), toFolderId(parentFolderId), serviceContext);
632    
633                    return new LiferayFolder(dlFolder);
634            }
635    
636            public Lock refreshFileEntryLock(
637                            String lockUuid, long companyId, long expirationTime)
638                    throws PortalException, SystemException {
639    
640                    return dlFileEntryService.refreshFileEntryLock(
641                            lockUuid, companyId, expirationTime);
642            }
643    
644            public Lock refreshFolderLock(
645                            String lockUuid, long companyId, long expirationTime)
646                    throws PortalException, SystemException {
647    
648                    return dlFolderService.refreshFolderLock(
649                            lockUuid, companyId, expirationTime);
650            }
651    
652            public void revertFileEntry(
653                            long fileEntryId, String version, ServiceContext serviceContext)
654                    throws PortalException, SystemException {
655    
656                    dlFileEntryService.revertFileEntry(
657                            fileEntryId, version, serviceContext);
658            }
659    
660            public Hits search(SearchContext searchContext) throws SearchException {
661                    Indexer indexer = IndexerRegistryUtil.getIndexer(
662                            DLFileEntryConstants.getClassName());
663    
664                    searchContext.setSearchEngineId(indexer.getSearchEngineId());
665    
666                    return indexer.search(searchContext);
667            }
668    
669            public Hits search(SearchContext searchContext, Query query)
670                    throws SearchException {
671    
672                    return SearchEngineUtil.search(searchContext, query);
673            }
674    
675            public void unlockFolder(long folderId, String lockUuid)
676                    throws PortalException, SystemException {
677    
678                    dlFolderService.unlockFolder(
679                            getGroupId(), toFolderId(folderId), lockUuid);
680            }
681    
682            public void unlockFolder(long parentFolderId, String title, String lockUuid)
683                    throws PortalException, SystemException {
684    
685                    dlFolderService.unlockFolder(
686                            getGroupId(), toFolderId(parentFolderId), title, lockUuid);
687            }
688    
689            public FileEntry updateFileEntry(
690                            long fileEntryId, String sourceFileName, String mimeType,
691                            String title, String description, String changeLog,
692                            boolean majorVersion, File file, ServiceContext serviceContext)
693                    throws PortalException, SystemException {
694    
695                    long fileEntryTypeId = ParamUtil.getLong(
696                            serviceContext, "fileEntryTypeId", -1L);
697                    Map<String, Fields> fieldsMap = getFieldsMap(
698                            serviceContext, fileEntryTypeId);
699                    long size = 0;
700    
701                    if (file != null) {
702                            size = file.length();
703                    }
704    
705                    DLFileEntry dlFileEntry = dlFileEntryService.updateFileEntry(
706                            fileEntryId, sourceFileName, mimeType, title, description,
707                            changeLog, majorVersion, fileEntryTypeId, fieldsMap, file, null,
708                            size, serviceContext);
709    
710                    return new LiferayFileEntry(dlFileEntry);
711            }
712    
713            public FileEntry updateFileEntry(
714                            long fileEntryId, String sourceFileName, String mimeType,
715                            String title, String description, String changeLog,
716                            boolean majorVersion, InputStream is, long size,
717                            ServiceContext serviceContext)
718                    throws PortalException, SystemException {
719    
720                    long fileEntryTypeId = ParamUtil.getLong(
721                            serviceContext, "fileEntryTypeId", -1L);
722                    Map<String, Fields> fieldsMap = getFieldsMap(
723                            serviceContext, fileEntryTypeId);
724    
725                    DLFileEntry dlFileEntry = dlFileEntryService.updateFileEntry(
726                            fileEntryId, sourceFileName, mimeType, title, description,
727                            changeLog, majorVersion, fileEntryTypeId, fieldsMap, null, is, size,
728                            serviceContext);
729    
730                    return new LiferayFileEntry(dlFileEntry);
731            }
732    
733            public Folder updateFolder(
734                            long folderId, String title, String description,
735                            ServiceContext serviceContext)
736                    throws PortalException, SystemException {
737    
738                    long defaultFileEntryTypeId = ParamUtil.getLong(
739                            serviceContext, "defaultFileEntryTypeId");
740                    SortedArrayList<Long> fileEntryTypeIds = getLongList(
741                            serviceContext, "dlFileEntryTypesSearchContainerPrimaryKeys");
742                    boolean overrideFileEntryTypes = ParamUtil.getBoolean(
743                            serviceContext, "overrideFileEntryTypes");
744    
745                    DLFolder dlFolder = dlFolderService.updateFolder(
746                            toFolderId(folderId), title, description, defaultFileEntryTypeId,
747                            fileEntryTypeIds, overrideFileEntryTypes, serviceContext);
748    
749                    return new LiferayFolder(dlFolder);
750            }
751    
752            public boolean verifyFileEntryCheckOut(long fileEntryId, String lockUuid)
753                    throws PortalException, SystemException {
754    
755                    return dlFileEntryService.verifyFileEntryCheckOut(
756                            fileEntryId, lockUuid);
757            }
758    
759            public boolean verifyFileEntryLock(long fileEntryId, String lockUuid)
760                    throws PortalException, SystemException {
761    
762                    return dlFileEntryService.verifyFileEntryLock(fileEntryId, lockUuid);
763            }
764    
765            public boolean verifyInheritableLock(long folderId, String lockUuid)
766                    throws PortalException, SystemException {
767    
768                    return dlFolderService.verifyInheritableLock(
769                            toFolderId(folderId), lockUuid);
770            }
771    
772            @Override
773            protected void initByFileEntryId(long fileEntryId) {
774                    try {
775                            DLFileEntry dlFileEntry = dlFileEntryService.getFileEntry(
776                                    fileEntryId);
777    
778                            initByRepositoryId(dlFileEntry.getRepositoryId());
779                    }
780                    catch (Exception e) {
781                            if (_log.isTraceEnabled()) {
782                                    if (e instanceof NoSuchFileEntryException) {
783                                            _log.trace(e.getMessage());
784                                    }
785                                    else {
786                                            _log.trace(e, e);
787                                    }
788                            }
789                    }
790            }
791    
792            @Override
793            protected void initByFileVersionId(long fileVersionId) {
794                    try {
795                            DLFileVersion dlFileVersion = dlFileVersionService.getFileVersion(
796                                    fileVersionId);
797    
798                            initByRepositoryId(dlFileVersion.getRepositoryId());
799                    }
800                    catch (Exception e) {
801                            if (_log.isTraceEnabled()) {
802                                    if (e instanceof NoSuchFileVersionException) {
803                                            _log.trace(e.getMessage());
804                                    }
805                                    else {
806                                            _log.trace(e, e);
807                                    }
808                            }
809                    }
810            }
811    
812            @Override
813            protected void initByFolderId(long folderId) {
814                    try {
815                            DLFolder dlFolder = dlFolderService.getFolder(folderId);
816    
817                            initByRepositoryId(dlFolder.getRepositoryId());
818                    }
819                    catch (Exception e) {
820                            if (_log.isTraceEnabled()) {
821                                    if (e instanceof NoSuchFolderException) {
822                                            _log.trace(e.getMessage());
823                                    }
824                                    else {
825                                            _log.trace(e, e);
826                                    }
827                            }
828                    }
829            }
830    
831            @Override
832            protected void initByRepositoryId(long repositoryId) {
833                    setGroupId(repositoryId);
834                    setRepositoryId(repositoryId);
835    
836                    try {
837                            com.liferay.portal.model.Repository repository =
838                                    repositoryService.getRepository(repositoryId);
839    
840                            setDlFolderId(repository.getDlFolderId());
841                            setGroupId(repository.getGroupId());
842                            setRepositoryId(repository.getRepositoryId());
843                    }
844                    catch (Exception e) {
845                    }
846            }
847    
848            private static Log _log = LogFactoryUtil.getLog(LiferayRepository.class);
849    
850    }