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