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