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