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