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