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