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