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.dynamic.data.mapping.kernel.DDMFormValues;
018    import com.liferay.portal.kernel.dao.orm.QueryDefinition;
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.lock.Lock;
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.FileShortcut;
024    import com.liferay.portal.kernel.repository.model.FileVersion;
025    import com.liferay.portal.kernel.repository.model.Folder;
026    import com.liferay.portal.kernel.repository.model.RepositoryEntry;
027    import com.liferay.portal.kernel.search.Hits;
028    import com.liferay.portal.kernel.search.IndexSearcherHelperUtil;
029    import com.liferay.portal.kernel.search.Indexer;
030    import com.liferay.portal.kernel.search.IndexerRegistryUtil;
031    import com.liferay.portal.kernel.search.Query;
032    import com.liferay.portal.kernel.search.SearchContext;
033    import com.liferay.portal.kernel.search.SearchException;
034    import com.liferay.portal.kernel.security.auth.PrincipalThreadLocal;
035    import com.liferay.portal.kernel.util.OrderByComparator;
036    import com.liferay.portal.kernel.util.ParamUtil;
037    import com.liferay.portal.kernel.workflow.WorkflowConstants;
038    import com.liferay.portal.repository.liferayrepository.model.LiferayFileEntry;
039    import com.liferay.portal.repository.liferayrepository.model.LiferayFileShortcut;
040    import com.liferay.portal.repository.liferayrepository.model.LiferayFileVersion;
041    import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
042    import com.liferay.portal.service.RepositoryLocalService;
043    import com.liferay.portal.service.RepositoryService;
044    import com.liferay.portal.service.ResourceLocalService;
045    import com.liferay.portal.service.ServiceContext;
046    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
047    import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
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.DLFileEntryTypeLocalService;
054    import com.liferay.portlet.documentlibrary.service.DLFileShortcutLocalService;
055    import com.liferay.portlet.documentlibrary.service.DLFileShortcutService;
056    import com.liferay.portlet.documentlibrary.service.DLFileVersionLocalService;
057    import com.liferay.portlet.documentlibrary.service.DLFileVersionService;
058    import com.liferay.portlet.documentlibrary.service.DLFolderLocalService;
059    import com.liferay.portlet.documentlibrary.service.DLFolderService;
060    import com.liferay.portlet.documentlibrary.util.DLSearcher;
061    import com.liferay.portlet.documentlibrary.util.RepositoryModelUtil;
062    import com.liferay.portlet.documentlibrary.util.comparator.DLFileEntryOrderByComparator;
063    import com.liferay.portlet.documentlibrary.util.comparator.DLFolderOrderByComparator;
064    
065    import java.io.File;
066    import java.io.InputStream;
067    
068    import java.util.List;
069    import java.util.Map;
070    
071    /**
072     * @author Alexander Chow
073     */
074    public class LiferayRepository
075            extends LiferayRepositoryBase implements Repository {
076    
077            public LiferayRepository(
078                    RepositoryLocalService repositoryLocalService,
079                    RepositoryService repositoryService,
080                    DLAppHelperLocalService dlAppHelperLocalService,
081                    DLFileEntryLocalService dlFileEntryLocalService,
082                    DLFileEntryService dlFileEntryService,
083                    DLFileEntryTypeLocalService dlFileEntryTypeLocalService,
084                    DLFileShortcutLocalService dlFileShortcutLocalService,
085                    DLFileShortcutService dlFileShortcutService,
086                    DLFileVersionLocalService dlFileVersionLocalService,
087                    DLFileVersionService dlFileVersionService,
088                    DLFolderLocalService dlFolderLocalService,
089                    DLFolderService dlFolderService,
090                    ResourceLocalService resourceLocalService, long groupId,
091                    long repositoryId, long dlFolderId) {
092    
093                    super(
094                            repositoryLocalService, repositoryService, dlAppHelperLocalService,
095                            dlFileEntryLocalService, dlFileEntryService,
096                            dlFileEntryTypeLocalService, dlFileShortcutLocalService,
097                            dlFileShortcutService, dlFileVersionLocalService,
098                            dlFileVersionService, dlFolderLocalService, dlFolderService,
099                            resourceLocalService, groupId, repositoryId, dlFolderId);
100            }
101    
102            @Override
103            public FileEntry addFileEntry(
104                            long userId, long folderId, String sourceFileName, String mimeType,
105                            String title, String description, String changeLog, File file,
106                            ServiceContext serviceContext)
107                    throws PortalException {
108    
109                    long fileEntryTypeId = ParamUtil.getLong(
110                            serviceContext, "fileEntryTypeId",
111                            getDefaultFileEntryTypeId(serviceContext, folderId));
112    
113                    Map<String, DDMFormValues> ddmFormValuesMap = getDDMFormValuesMap(
114                            serviceContext, fileEntryTypeId);
115    
116                    long size = 0;
117    
118                    if (file != null) {
119                            size = file.length();
120                    }
121    
122                    DLFileEntry dlFileEntry = dlFileEntryService.addFileEntry(
123                            getGroupId(), getRepositoryId(), toFolderId(folderId),
124                            sourceFileName, mimeType, title, description, changeLog,
125                            fileEntryTypeId, ddmFormValuesMap, file, null, size,
126                            serviceContext);
127    
128                    addFileEntryResources(dlFileEntry, serviceContext);
129    
130                    return new LiferayFileEntry(dlFileEntry);
131            }
132    
133            @Override
134            public FileEntry addFileEntry(
135                            long userId, long folderId, String sourceFileName, String mimeType,
136                            String title, String description, String changeLog, InputStream is,
137                            long size, ServiceContext serviceContext)
138                    throws PortalException {
139    
140                    long fileEntryTypeId = ParamUtil.getLong(
141                            serviceContext, "fileEntryTypeId",
142                            getDefaultFileEntryTypeId(serviceContext, folderId));
143    
144                    Map<String, DDMFormValues> ddmFormValuesMap = getDDMFormValuesMap(
145                            serviceContext, fileEntryTypeId);
146    
147                    DLFileEntry dlFileEntry = dlFileEntryService.addFileEntry(
148                            getGroupId(), getRepositoryId(), toFolderId(folderId),
149                            sourceFileName, mimeType, title, description, changeLog,
150                            fileEntryTypeId, ddmFormValuesMap, null, is, size, serviceContext);
151    
152                    addFileEntryResources(dlFileEntry, serviceContext);
153    
154                    return new LiferayFileEntry(dlFileEntry);
155            }
156    
157            /**
158             * @deprecated As of 7.0.0, see {@link #addFileEntry(long, long, String,
159             *             String, String, String, String, File, ServiceContext)}
160             */
161            @Deprecated
162            @Override
163            public FileEntry addFileEntry(
164                            long folderId, String sourceFileName, String mimeType, String title,
165                            String description, String changeLog, File file,
166                            ServiceContext serviceContext)
167                    throws PortalException {
168    
169                    return addFileEntry(
170                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
171                                    getUserId(),
172                            folderId, sourceFileName, mimeType, title, description, changeLog,
173                            file, serviceContext);
174            }
175    
176            /**
177             * @deprecated As of 7.0.0, see {@link #addFileEntry(long, long, String,
178             *             String, String, String, String, InputStream, long,
179             *             ServiceContext)}
180             */
181            @Deprecated
182            @Override
183            public FileEntry addFileEntry(
184                            long folderId, String sourceFileName, String mimeType, String title,
185                            String description, String changeLog, InputStream is, long size,
186                            ServiceContext serviceContext)
187                    throws PortalException {
188    
189                    return addFileEntry(
190                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
191                                    getUserId(),
192                            folderId, sourceFileName, mimeType, title, description, changeLog,
193                            is, size, serviceContext);
194            }
195    
196            @Override
197            public FileShortcut addFileShortcut(
198                            long userId, long folderId, long toFileEntryId,
199                            ServiceContext serviceContext)
200                    throws PortalException {
201    
202                    DLFileShortcut dlFileShortcut = dlFileShortcutService.addFileShortcut(
203                            getGroupId(), getRepositoryId(), folderId, toFileEntryId,
204                            serviceContext);
205    
206                    return new LiferayFileShortcut(dlFileShortcut);
207            }
208    
209            @Override
210            public Folder addFolder(
211                            long userId, long parentFolderId, String name, String description,
212                            ServiceContext serviceContext)
213                    throws PortalException {
214    
215                    boolean mountPoint = ParamUtil.getBoolean(serviceContext, "mountPoint");
216    
217                    DLFolder dlFolder = dlFolderService.addFolder(
218                            getGroupId(), getRepositoryId(), mountPoint,
219                            toFolderId(parentFolderId), name, description, serviceContext);
220    
221                    return new LiferayFolder(dlFolder);
222            }
223    
224            /**
225             * @deprecated As of 7.0.0, replaced by {@link #addFolder(long, long,
226             *             String, String, ServiceContext)}
227             */
228            @Deprecated
229            @Override
230            public Folder addFolder(
231                            long parentFolderId, String name, String description,
232                            ServiceContext serviceContext)
233                    throws PortalException {
234    
235                    return addFolder(
236                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
237                                    getUserId(),
238                            parentFolderId, name, description, serviceContext);
239            }
240    
241            @Override
242            public FileVersion cancelCheckOut(long fileEntryId) throws PortalException {
243                    DLFileVersion dlFileVersion = dlFileEntryService.cancelCheckOut(
244                            fileEntryId);
245    
246                    if (dlFileVersion != null) {
247                            return new LiferayFileVersion(dlFileVersion);
248                    }
249    
250                    return null;
251            }
252    
253            /**
254             * @deprecated As of 7.0.0, replaced by {@link #checkInFileEntry(long, long,
255             *             boolean, String, ServiceContext)}
256             */
257            @Deprecated
258            @Override
259            public void checkInFileEntry(
260                            long fileEntryId, boolean major, String changeLog,
261                            ServiceContext serviceContext)
262                    throws PortalException {
263    
264                    checkInFileEntry(
265                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
266                                    getUserId(),
267                            fileEntryId, major, changeLog, serviceContext);
268            }
269    
270            @Override
271            public void checkInFileEntry(
272                            long userId, long fileEntryId, boolean major, String changeLog,
273                            ServiceContext serviceContext)
274                    throws PortalException {
275    
276                    dlFileEntryService.checkInFileEntry(
277                            fileEntryId, major, changeLog, serviceContext);
278            }
279    
280            @Override
281            public void checkInFileEntry(
282                            long userId, long fileEntryId, String lockUuid,
283                            ServiceContext serviceContext)
284                    throws PortalException {
285    
286                    dlFileEntryService.checkInFileEntry(
287                            fileEntryId, lockUuid, serviceContext);
288            }
289    
290            /**
291             * @deprecated As of 6.2.0, replaced by {@link #checkInFileEntry(long,
292             *             String, ServiceContext)}
293             */
294            @Deprecated
295            @Override
296            public void checkInFileEntry(long fileEntryId, String lockUuid)
297                    throws PortalException {
298    
299                    checkInFileEntry(fileEntryId, lockUuid, new ServiceContext());
300            }
301    
302            /**
303             * @deprecated As of 7.0.0, replaced by {@link #checkInFileEntry(long, long,
304             *             String, ServiceContext)}
305             */
306            @Deprecated
307            @Override
308            public void checkInFileEntry(
309                            long fileEntryId, String lockUuid, ServiceContext serviceContext)
310                    throws PortalException {
311    
312                    checkInFileEntry(
313                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
314                                    getUserId(),
315                            fileEntryId, lockUuid, serviceContext);
316            }
317    
318            @Override
319            public FileEntry checkOutFileEntry(
320                            long fileEntryId, ServiceContext serviceContext)
321                    throws PortalException {
322    
323                    DLFileEntry dlFileEntry = dlFileEntryService.checkOutFileEntry(
324                            fileEntryId, serviceContext);
325    
326                    return new LiferayFileEntry(dlFileEntry);
327            }
328    
329            @Override
330            public FileEntry checkOutFileEntry(
331                            long fileEntryId, String owner, long expirationTime,
332                            ServiceContext serviceContext)
333                    throws PortalException {
334    
335                    DLFileEntry dlFileEntry = dlFileEntryService.checkOutFileEntry(
336                            fileEntryId, owner, expirationTime, serviceContext);
337    
338                    return new LiferayFileEntry(dlFileEntry);
339            }
340    
341            @Override
342            public FileEntry copyFileEntry(
343                            long userId, long groupId, long fileEntryId, long destFolderId,
344                            ServiceContext serviceContext)
345                    throws PortalException {
346    
347                    DLFileEntry dlFileEntry = dlFileEntryService.copyFileEntry(
348                            groupId, getRepositoryId(), fileEntryId, destFolderId,
349                            serviceContext);
350    
351                    return new LiferayFileEntry(dlFileEntry);
352            }
353    
354            /**
355             * @deprecated As of 7.0.0, replaced by {@link #copyFileEntry(long, long,
356             *             long, long, ServiceContext)}
357             */
358            @Deprecated
359            @Override
360            public FileEntry copyFileEntry(
361                            long groupId, long fileEntryId, long destFolderId,
362                            ServiceContext serviceContext)
363                    throws PortalException {
364    
365                    return copyFileEntry(
366                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
367                                    getUserId(),
368                            groupId, fileEntryId, destFolderId, serviceContext);
369            }
370    
371            @Override
372            public void deleteAll() {
373                    throw new UnsupportedOperationException();
374            }
375    
376            @Override
377            public void deleteFileEntry(long fileEntryId) throws PortalException {
378                    dlFileEntryService.deleteFileEntry(fileEntryId);
379            }
380    
381            @Override
382            public void deleteFileEntry(long folderId, String title)
383                    throws PortalException {
384    
385                    dlFileEntryService.deleteFileEntry(
386                            getGroupId(), toFolderId(folderId), title);
387            }
388    
389            @Override
390            public void deleteFileShortcut(long fileShortcutId) throws PortalException {
391                    dlFileShortcutService.deleteFileShortcut(fileShortcutId);
392            }
393    
394            @Override
395            public void deleteFileShortcuts(long toFileEntryId) throws PortalException {
396                    dlFileShortcutService.deleteFileShortcut(toFileEntryId);
397            }
398    
399            @Override
400            public void deleteFileVersion(long fileEntryId, String version)
401                    throws PortalException {
402    
403                    dlFileEntryService.deleteFileVersion(fileEntryId, version);
404            }
405    
406            @Override
407            public void deleteFolder(long folderId) throws PortalException {
408                    dlFolderService.deleteFolder(folderId);
409            }
410    
411            @Override
412            public void deleteFolder(long parentFolderId, String name)
413                    throws PortalException {
414    
415                    dlFolderService.deleteFolder(
416                            getGroupId(), toFolderId(parentFolderId), name);
417            }
418    
419            @Override
420            public List<FileEntry> getFileEntries(
421                            long folderId, int status, int start, int end,
422                            OrderByComparator<FileEntry> obc)
423                    throws PortalException {
424    
425                    List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
426                            getGroupId(), toFolderId(folderId), status, start, end,
427                            DLFileEntryOrderByComparator.getOrderByComparator(obc));
428    
429                    return RepositoryModelUtil.toFileEntries(dlFileEntries);
430            }
431    
432            @Override
433            public List<FileEntry> getFileEntries(
434                            long folderId, int start, int end, OrderByComparator<FileEntry> obc)
435                    throws PortalException {
436    
437                    List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
438                            getGroupId(), toFolderId(folderId), start, end,
439                            DLFileEntryOrderByComparator.getOrderByComparator(obc));
440    
441                    return RepositoryModelUtil.toFileEntries(dlFileEntries);
442            }
443    
444            @Override
445            public List<FileEntry> getFileEntries(
446                            long folderId, long fileEntryTypeId, int start, int end,
447                            OrderByComparator<FileEntry> obc)
448                    throws PortalException {
449    
450                    List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
451                            getGroupId(), toFolderId(folderId), fileEntryTypeId, start, end,
452                            DLFileEntryOrderByComparator.getOrderByComparator(obc));
453    
454                    return RepositoryModelUtil.toFileEntries(dlFileEntries);
455            }
456    
457            @Override
458            public List<FileEntry> getFileEntries(
459                            long folderId, String[] mimeTypes, int start, int end,
460                            OrderByComparator<FileEntry> obc)
461                    throws PortalException {
462    
463                    List<DLFileEntry> dlFileEntries = dlFileEntryService.getFileEntries(
464                            getGroupId(), toFolderId(folderId), mimeTypes, start, end,
465                            DLFileEntryOrderByComparator.getOrderByComparator(obc));
466    
467                    return RepositoryModelUtil.toFileEntries(dlFileEntries);
468            }
469    
470            @Override
471            public List<RepositoryEntry> getFileEntriesAndFileShortcuts(
472                            long folderId, int status, int start, int end)
473                    throws PortalException {
474    
475                    List<Object> dlFileEntriesAndFileShortcuts =
476                            dlFolderService.getFileEntriesAndFileShortcuts(
477                                    getGroupId(), toFolderId(folderId), status, start, end);
478    
479                    return RepositoryModelUtil.toRepositoryEntries(
480                            dlFileEntriesAndFileShortcuts);
481            }
482    
483            @Override
484            public int getFileEntriesAndFileShortcutsCount(long folderId, int status)
485                    throws PortalException {
486    
487                    return dlFolderService.getFileEntriesAndFileShortcutsCount(
488                            getGroupId(), toFolderId(folderId), status);
489            }
490    
491            @Override
492            public int getFileEntriesAndFileShortcutsCount(
493                            long folderId, int status, String[] mimeTypes)
494                    throws PortalException {
495    
496                    return dlFolderService.getFileEntriesAndFileShortcutsCount(
497                            getGroupId(), toFolderId(folderId), status, mimeTypes);
498            }
499    
500            @Override
501            public int getFileEntriesCount(long folderId) {
502                    return dlFileEntryService.getFileEntriesCount(
503                            getGroupId(), toFolderId(folderId));
504            }
505    
506            @Override
507            public int getFileEntriesCount(long folderId, int status) {
508                    return dlFileEntryService.getFileEntriesCount(
509                            getGroupId(), toFolderId(folderId), status);
510            }
511    
512            @Override
513            public int getFileEntriesCount(long folderId, long fileEntryTypeId) {
514                    return dlFileEntryService.getFileEntriesCount(
515                            getGroupId(), toFolderId(folderId), fileEntryTypeId);
516            }
517    
518            @Override
519            public int getFileEntriesCount(long folderId, String[] mimeTypes) {
520                    return dlFileEntryService.getFileEntriesCount(
521                            getGroupId(), folderId, mimeTypes);
522            }
523    
524            @Override
525            public FileEntry getFileEntry(long fileEntryId) throws PortalException {
526                    DLFileEntry dlFileEntry = dlFileEntryService.getFileEntry(fileEntryId);
527    
528                    return new LiferayFileEntry(dlFileEntry);
529            }
530    
531            @Override
532            public FileEntry getFileEntry(long folderId, String title)
533                    throws PortalException {
534    
535                    DLFileEntry dlFileEntry = dlFileEntryService.getFileEntry(
536                            getGroupId(), toFolderId(folderId), title);
537    
538                    return new LiferayFileEntry(dlFileEntry);
539            }
540    
541            @Override
542            public FileEntry getFileEntryByUuid(String uuid) throws PortalException {
543                    DLFileEntry dlFileEntry =
544                            dlFileEntryService.getFileEntryByUuidAndGroupId(uuid, getGroupId());
545    
546                    return new LiferayFileEntry(dlFileEntry);
547            }
548    
549            public Lock getFileEntryLock(long fileEntryId) {
550                    return dlFileEntryService.getFileEntryLock(fileEntryId);
551            }
552    
553            @Override
554            public FileShortcut getFileShortcut(long fileShortcutId)
555                    throws PortalException {
556    
557                    DLFileShortcut dlFileShortcut = dlFileShortcutService.getFileShortcut(
558                            fileShortcutId);
559    
560                    return new LiferayFileShortcut(dlFileShortcut);
561            }
562    
563            @Override
564            public FileVersion getFileVersion(long fileVersionId)
565                    throws PortalException {
566    
567                    DLFileVersion dlFileVersion = dlFileVersionService.getFileVersion(
568                            fileVersionId);
569    
570                    return new LiferayFileVersion(dlFileVersion);
571            }
572    
573            @Override
574            public Folder getFolder(long folderId) throws PortalException {
575                    DLFolder dlFolder = dlFolderService.getFolder(toFolderId(folderId));
576    
577                    return new LiferayFolder(dlFolder);
578            }
579    
580            @Override
581            public Folder getFolder(long parentFolderId, String name)
582                    throws PortalException {
583    
584                    DLFolder dlFolder = dlFolderService.getFolder(
585                            getGroupId(), toFolderId(parentFolderId), name);
586    
587                    return new LiferayFolder(dlFolder);
588            }
589    
590            @Override
591            public List<Folder> getFolders(
592                            long parentFolderId, boolean includeMountfolders, int start,
593                            int end, OrderByComparator<Folder> obc)
594                    throws PortalException {
595    
596                    return getFolders(
597                            parentFolderId, WorkflowConstants.STATUS_APPROVED,
598                            includeMountfolders, start, end, obc);
599            }
600    
601            @Override
602            public List<Folder> getFolders(
603                            long parentFolderId, int status, boolean includeMountfolders,
604                            int start, int end, OrderByComparator<Folder> obc)
605                    throws PortalException {
606    
607                    List<DLFolder> dlFolders = dlFolderService.getFolders(
608                            getGroupId(), toFolderId(parentFolderId), status,
609                            includeMountfolders, start, end,
610                            DLFolderOrderByComparator.getOrderByComparator(obc));
611    
612                    return RepositoryModelUtil.toFolders(dlFolders);
613            }
614    
615            @Override
616            public List<RepositoryEntry> getFoldersAndFileEntriesAndFileShortcuts(
617                            long folderId, int status, boolean includeMountFolders, int start,
618                            int end, OrderByComparator<?> obc)
619                    throws PortalException {
620    
621                    List<Object> dlFoldersAndDLFileEntriesAndDLFileShortcuts =
622                            dlFolderService.getFoldersAndFileEntriesAndFileShortcuts(
623                                    getGroupId(), toFolderId(folderId), status, includeMountFolders,
624                                    start, end, obc);
625    
626                    return RepositoryModelUtil.toRepositoryEntries(
627                            dlFoldersAndDLFileEntriesAndDLFileShortcuts);
628            }
629    
630            @Override
631            public List<RepositoryEntry> getFoldersAndFileEntriesAndFileShortcuts(
632                            long folderId, int status, String[] mimeTypes,
633                            boolean includeMountFolders, int start, int end,
634                            OrderByComparator<?> obc)
635                    throws PortalException {
636    
637                    QueryDefinition<Object> queryDefinition = new QueryDefinition<>(
638                            status, PrincipalThreadLocal.getUserId(), true, start, end,
639                            (OrderByComparator<Object>)obc);
640    
641                    List<Object> dlFoldersAndDLFileEntriesAndDLFileShortcuts =
642                            dlFolderService.getFoldersAndFileEntriesAndFileShortcuts(
643                                    getGroupId(), toFolderId(folderId), mimeTypes,
644                                    includeMountFolders, queryDefinition);
645    
646                    return RepositoryModelUtil.toRepositoryEntries(
647                            dlFoldersAndDLFileEntriesAndDLFileShortcuts);
648            }
649    
650            @Override
651            public int getFoldersAndFileEntriesAndFileShortcutsCount(
652                            long folderId, int status, boolean includeMountFolders)
653                    throws PortalException {
654    
655                    return dlFolderService.getFoldersAndFileEntriesAndFileShortcutsCount(
656                            getGroupId(), toFolderId(folderId), status, includeMountFolders);
657            }
658    
659            @Override
660            public int getFoldersAndFileEntriesAndFileShortcutsCount(
661                            long folderId, int status, String[] mimeTypes,
662                            boolean includeMountFolders)
663                    throws PortalException {
664    
665                    QueryDefinition<Object> queryDefinition = new QueryDefinition<>(
666                            status, PrincipalThreadLocal.getUserId(), true);
667    
668                    return dlFolderService.getFoldersAndFileEntriesAndFileShortcutsCount(
669                            getGroupId(), toFolderId(folderId), mimeTypes, includeMountFolders,
670                            queryDefinition);
671            }
672    
673            @Override
674            public int getFoldersCount(long parentFolderId, boolean includeMountfolders)
675                    throws PortalException {
676    
677                    return getFoldersCount(
678                            parentFolderId, WorkflowConstants.STATUS_APPROVED,
679                            includeMountfolders);
680            }
681    
682            @Override
683            public int getFoldersCount(
684                            long parentFolderId, int status, boolean includeMountfolders)
685                    throws PortalException {
686    
687                    return dlFolderService.getFoldersCount(
688                            getGroupId(), toFolderId(parentFolderId), status,
689                            includeMountfolders);
690            }
691    
692            @Override
693            public int getFoldersFileEntriesCount(List<Long> folderIds, int status) {
694                    return dlFileEntryService.getFoldersFileEntriesCount(
695                            getGroupId(), toFolderIds(folderIds), status);
696            }
697    
698            @Override
699            public List<Folder> getMountFolders(
700                            long parentFolderId, int start, int end,
701                            OrderByComparator<Folder> obc)
702                    throws PortalException {
703    
704                    List<DLFolder> dlFolders = dlFolderService.getMountFolders(
705                            getGroupId(), toFolderId(parentFolderId), start, end,
706                            DLFolderOrderByComparator.getOrderByComparator(obc));
707    
708                    return RepositoryModelUtil.toFolders(dlFolders);
709            }
710    
711            @Override
712            public int getMountFoldersCount(long parentFolderId)
713                    throws PortalException {
714    
715                    return dlFolderService.getMountFoldersCount(
716                            getGroupId(), toFolderId(parentFolderId));
717            }
718    
719            @Override
720            public List<FileEntry> getRepositoryFileEntries(
721                            long userId, long rootFolderId, int start, int end,
722                            OrderByComparator<FileEntry> obc)
723                    throws PortalException {
724    
725                    List<DLFileEntry> dlFileEntries =
726                            dlFileEntryService.getGroupFileEntries(
727                                    getGroupId(), userId, toFolderId(rootFolderId), start, end,
728                                    DLFileEntryOrderByComparator.getOrderByComparator(obc));
729    
730                    return RepositoryModelUtil.toFileEntries(dlFileEntries);
731            }
732    
733            @Override
734            public List<FileEntry> getRepositoryFileEntries(
735                            long userId, long rootFolderId, String[] mimeTypes, int status,
736                            int start, int end, OrderByComparator<FileEntry> obc)
737                    throws PortalException {
738    
739                    List<DLFileEntry> dlFileEntries =
740                            dlFileEntryService.getGroupFileEntries(
741                                    getGroupId(), userId, getRepositoryId(),
742                                    toFolderId(rootFolderId), mimeTypes, status, start, end,
743                                    DLFileEntryOrderByComparator.getOrderByComparator(obc));
744    
745                    return RepositoryModelUtil.toFileEntries(dlFileEntries);
746            }
747    
748            @Override
749            public int getRepositoryFileEntriesCount(long userId, long rootFolderId)
750                    throws PortalException {
751    
752                    return dlFileEntryService.getGroupFileEntriesCount(
753                            getGroupId(), userId, toFolderId(rootFolderId));
754            }
755    
756            @Override
757            public int getRepositoryFileEntriesCount(
758                            long userId, long rootFolderId, String[] mimeTypes, int status)
759                    throws PortalException {
760    
761                    return dlFileEntryService.getGroupFileEntriesCount(
762                            getGroupId(), userId, getRepositoryId(), toFolderId(rootFolderId),
763                            mimeTypes, status);
764            }
765    
766            @Override
767            public void getSubfolderIds(List<Long> folderIds, long folderId)
768                    throws PortalException {
769    
770                    dlFolderService.getSubfolderIds(
771                            folderIds, getGroupId(), toFolderId(folderId), true);
772            }
773    
774            @Override
775            public List<Long> getSubfolderIds(long folderId, boolean recurse)
776                    throws PortalException {
777    
778                    return dlFolderService.getSubfolderIds(
779                            getGroupId(), toFolderId(folderId), recurse);
780            }
781    
782            @Override
783            public Lock lockFolder(long folderId) throws PortalException {
784                    return dlFolderService.lockFolder(toFolderId(folderId));
785            }
786    
787            @Override
788            public Lock lockFolder(
789                            long folderId, String owner, boolean inheritable,
790                            long expirationTime)
791                    throws PortalException {
792    
793                    return dlFolderService.lockFolder(
794                            toFolderId(folderId), owner, inheritable, expirationTime);
795            }
796    
797            @Override
798            public FileEntry moveFileEntry(
799                            long userId, long fileEntryId, long newFolderId,
800                            ServiceContext serviceContext)
801                    throws PortalException {
802    
803                    DLFileEntry dlFileEntry = dlFileEntryService.moveFileEntry(
804                            fileEntryId, toFolderId(newFolderId), serviceContext);
805    
806                    return new LiferayFileEntry(dlFileEntry);
807            }
808    
809            /**
810             * @deprecated As of 7.0.0, replaced by {@link #moveFileEntry(long, long,
811             *             long, ServiceContext)}
812             */
813            @Deprecated
814            @Override
815            public FileEntry moveFileEntry(
816                            long fileEntryId, long newFolderId, ServiceContext serviceContext)
817                    throws PortalException {
818    
819                    return moveFileEntry(
820                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
821                                    getUserId(),
822                            fileEntryId, newFolderId, serviceContext);
823            }
824    
825            @Override
826            public Folder moveFolder(
827                            long userId, long folderId, long parentFolderId,
828                            ServiceContext serviceContext)
829                    throws PortalException {
830    
831                    DLFolder dlFolder = dlFolderService.moveFolder(
832                            toFolderId(folderId), toFolderId(parentFolderId), serviceContext);
833    
834                    return new LiferayFolder(dlFolder);
835            }
836    
837            /**
838             * @deprecated As of 7.0.0, replaced by {@link #moveFolder(long, long,
839             *             ServiceContext)}
840             */
841            @Deprecated
842            @Override
843            public Folder moveFolder(
844                            long folderId, long newParentFolderId,
845                            ServiceContext serviceContext)
846                    throws PortalException {
847    
848                    return moveFolder(
849                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
850                                    getUserId(),
851                            folderId, newParentFolderId, serviceContext);
852            }
853    
854            @Override
855            public Lock refreshFileEntryLock(
856                            String lockUuid, long companyId, long expirationTime)
857                    throws PortalException {
858    
859                    return dlFileEntryService.refreshFileEntryLock(
860                            lockUuid, companyId, expirationTime);
861            }
862    
863            @Override
864            public Lock refreshFolderLock(
865                            String lockUuid, long companyId, long expirationTime)
866                    throws PortalException {
867    
868                    return dlFolderService.refreshFolderLock(
869                            lockUuid, companyId, expirationTime);
870            }
871    
872            @Override
873            public void revertFileEntry(
874                            long userId, long fileEntryId, String version,
875                            ServiceContext serviceContext)
876                    throws PortalException {
877    
878                    dlFileEntryService.revertFileEntry(
879                            fileEntryId, version, serviceContext);
880            }
881    
882            /**
883             * @deprecated As of 7.0.0, replaced by {@link #revertFileEntry(long, long,
884             *             String, ServiceContext)}
885             */
886            @Deprecated
887            @Override
888            public void revertFileEntry(
889                            long fileEntryId, String version, ServiceContext serviceContext)
890                    throws PortalException {
891    
892                    dlFileEntryService.revertFileEntry(
893                            fileEntryId, version, serviceContext);
894            }
895    
896            @Override
897            public Hits search(long creatorUserId, int status, int start, int end)
898                    throws PortalException {
899    
900                    return dlFileEntryService.search(
901                            getGroupId(), creatorUserId, status, start, end);
902            }
903    
904            @Override
905            public Hits search(
906                            long creatorUserId, long folderId, String[] mimeTypes, int status,
907                            int start, int end)
908                    throws PortalException {
909    
910                    return dlFileEntryService.search(
911                            getGroupId(), creatorUserId, toFolderId(folderId), mimeTypes,
912                            status, start, end);
913            }
914    
915            @Override
916            public Hits search(SearchContext searchContext) throws SearchException {
917                    Indexer<?> indexer = null;
918    
919                    if (searchContext.isIncludeFolders()) {
920                            indexer = DLSearcher.getInstance();
921                    }
922                    else {
923                            indexer = IndexerRegistryUtil.getIndexer(DLFileEntry.class);
924                    }
925    
926                    searchContext.setSearchEngineId(indexer.getSearchEngineId());
927    
928                    return indexer.search(searchContext);
929            }
930    
931            @Override
932            public Hits search(SearchContext searchContext, Query query)
933                    throws SearchException {
934    
935                    return IndexSearcherHelperUtil.search(searchContext, query);
936            }
937    
938            @Override
939            public void unlockFolder(long folderId, String lockUuid)
940                    throws PortalException {
941    
942                    dlFolderService.unlockFolder(toFolderId(folderId), lockUuid);
943            }
944    
945            @Override
946            public void unlockFolder(long parentFolderId, String name, String lockUuid)
947                    throws PortalException {
948    
949                    dlFolderService.unlockFolder(
950                            getGroupId(), toFolderId(parentFolderId), name, lockUuid);
951            }
952    
953            @Override
954            public FileEntry updateFileEntry(
955                            long userId, long fileEntryId, String sourceFileName,
956                            String mimeType, String title, String description, String changeLog,
957                            boolean majorVersion, File file, ServiceContext serviceContext)
958                    throws PortalException {
959    
960                    long fileEntryTypeId = ParamUtil.getLong(
961                            serviceContext, "fileEntryTypeId", -1L);
962    
963                    Map<String, DDMFormValues> ddmFormValuesMap = getDDMFormValuesMap(
964                            serviceContext, fileEntryTypeId);
965    
966                    long size = 0;
967    
968                    if (file != null) {
969                            size = file.length();
970                    }
971    
972                    DLFileEntry dlFileEntry = dlFileEntryService.updateFileEntry(
973                            fileEntryId, sourceFileName, mimeType, title, description,
974                            changeLog, majorVersion, fileEntryTypeId, ddmFormValuesMap, file,
975                            null, size, serviceContext);
976    
977                    return new LiferayFileEntry(dlFileEntry);
978            }
979    
980            @Override
981            public FileEntry updateFileEntry(
982                            long userId, long fileEntryId, String sourceFileName,
983                            String mimeType, String title, String description, String changeLog,
984                            boolean majorVersion, InputStream is, long size,
985                            ServiceContext serviceContext)
986                    throws PortalException {
987    
988                    long fileEntryTypeId = ParamUtil.getLong(
989                            serviceContext, "fileEntryTypeId", -1L);
990    
991                    Map<String, DDMFormValues> ddmFormValuesMap = getDDMFormValuesMap(
992                            serviceContext, fileEntryTypeId);
993    
994                    DLFileEntry dlFileEntry = dlFileEntryService.updateFileEntry(
995                            fileEntryId, sourceFileName, mimeType, title, description,
996                            changeLog, majorVersion, fileEntryTypeId, ddmFormValuesMap, null,
997                            is, size, serviceContext);
998    
999                    return new LiferayFileEntry(dlFileEntry);
1000            }
1001    
1002            /**
1003             * @deprecated As of 7.0.0, replaced by {@link #updateFileEntry(long, long,
1004             *             String, String, String, String, String, boolean, File,
1005             *             ServiceContext)}
1006             */
1007            @Deprecated
1008            @Override
1009            public FileEntry updateFileEntry(
1010                            long fileEntryId, String sourceFileName, String mimeType,
1011                            String title, String description, String changeLog,
1012                            boolean majorVersion, File file, ServiceContext serviceContext)
1013                    throws PortalException {
1014    
1015                    return updateFileEntry(
1016                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
1017                                    getUserId(),
1018                            fileEntryId, sourceFileName, mimeType, title, description,
1019                            changeLog, majorVersion, file, serviceContext);
1020            }
1021    
1022            /**
1023             * @deprecated As of 7.0.0, replaced by {@link #updateFileEntry(long, long,
1024             *             String, String, String, String, String, boolean, InputStream,
1025             *             long, ServiceContext)}
1026             */
1027            @Deprecated
1028            @Override
1029            public FileEntry updateFileEntry(
1030                            long fileEntryId, String sourceFileName, String mimeType,
1031                            String title, String description, String changeLog,
1032                            boolean majorVersion, InputStream is, long size,
1033                            ServiceContext serviceContext)
1034                    throws PortalException {
1035    
1036                    return updateFileEntry(
1037                            com.liferay.portal.kernel.repository.util.RepositoryUserUtil.
1038                                    getUserId(),
1039                            fileEntryId, sourceFileName, mimeType, title, description,
1040                            changeLog, majorVersion, is, size, serviceContext);
1041            }
1042    
1043            @Override
1044            public FileShortcut updateFileShortcut(
1045                            long userId, long fileShortcutId, long folderId, long toFileEntryId,
1046                            ServiceContext serviceContext)
1047                    throws PortalException {
1048    
1049                    DLFileShortcut dlFileShortcut =
1050                            dlFileShortcutService.updateFileShortcut(
1051                                    fileShortcutId, getRepositoryId(), folderId, toFileEntryId,
1052                                    serviceContext);
1053    
1054                    return new LiferayFileShortcut(dlFileShortcut);
1055            }
1056    
1057            @Override
1058            public void updateFileShortcuts(
1059                            long oldToFileEntryId, long newToFileEntryId)
1060                    throws PortalException {
1061    
1062                    dlFileShortcutService.updateFileShortcuts(
1063                            oldToFileEntryId, newToFileEntryId);
1064            }
1065    
1066            @Override
1067            public Folder updateFolder(
1068                            long folderId, long parentFolderId, String name, String description,
1069                            ServiceContext serviceContext)
1070                    throws PortalException {
1071    
1072                    long defaultFileEntryTypeId = ParamUtil.getLong(
1073                            serviceContext, "defaultFileEntryTypeId");
1074                    List<Long> fileEntryTypeIds = getLongList(
1075                            serviceContext, "dlFileEntryTypesSearchContainerPrimaryKeys");
1076                    int restrictionType = ParamUtil.getInteger(
1077                            serviceContext, "restrictionType");
1078    
1079                    DLFolder dlFolder = dlFolderService.updateFolder(
1080                            toFolderId(folderId), toFolderId(parentFolderId), name, description,
1081                            defaultFileEntryTypeId, fileEntryTypeIds, restrictionType,
1082                            serviceContext);
1083    
1084                    return new LiferayFolder(dlFolder);
1085            }
1086    
1087            @Override
1088            public Folder updateFolder(
1089                            long folderId, String name, String description,
1090                            ServiceContext serviceContext)
1091                    throws PortalException {
1092    
1093                    long defaultFileEntryTypeId = ParamUtil.getLong(
1094                            serviceContext, "defaultFileEntryTypeId");
1095                    List<Long> fileEntryTypeIds = getLongList(
1096                            serviceContext, "dlFileEntryTypesSearchContainerPrimaryKeys");
1097                    int restrictionType = ParamUtil.getInteger(
1098                            serviceContext, "restrictionType");
1099    
1100                    DLFolder dlFolder = dlFolderService.updateFolder(
1101                            toFolderId(folderId), name, description, defaultFileEntryTypeId,
1102                            fileEntryTypeIds, restrictionType, serviceContext);
1103    
1104                    return new LiferayFolder(dlFolder);
1105            }
1106    
1107            @Override
1108            public boolean verifyFileEntryCheckOut(long fileEntryId, String lockUuid)
1109                    throws PortalException {
1110    
1111                    return dlFileEntryService.verifyFileEntryCheckOut(
1112                            fileEntryId, lockUuid);
1113            }
1114    
1115            @Override
1116            public boolean verifyFileEntryLock(long fileEntryId, String lockUuid)
1117                    throws PortalException {
1118    
1119                    return dlFileEntryService.verifyFileEntryLock(fileEntryId, lockUuid);
1120            }
1121    
1122            @Override
1123            public boolean verifyInheritableLock(long folderId, String lockUuid)
1124                    throws PortalException {
1125    
1126                    return dlFolderLocalService.verifyInheritableLock(
1127                            toFolderId(folderId), lockUuid);
1128            }
1129    
1130    }