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