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