001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.impl;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryDefinition;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.lock.Lock;
020    import com.liferay.portal.kernel.lock.LockManagerUtil;
021    import com.liferay.portal.kernel.search.Hits;
022    import com.liferay.portal.kernel.util.ArrayUtil;
023    import com.liferay.portal.kernel.util.OrderByComparator;
024    import com.liferay.portal.kernel.workflow.WorkflowConstants;
025    import com.liferay.portal.security.auth.PrincipalException;
026    import com.liferay.portal.security.permission.ActionKeys;
027    import com.liferay.portal.security.permission.PermissionChecker;
028    import com.liferay.portal.service.ServiceContext;
029    import com.liferay.portal.util.PropsValues;
030    import com.liferay.portlet.documentlibrary.exception.FileEntryLockException;
031    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
032    import com.liferay.portlet.documentlibrary.model.DLFileEntryConstants;
033    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
034    import com.liferay.portlet.documentlibrary.model.DLFolderConstants;
035    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
036    import com.liferay.portlet.documentlibrary.service.base.DLFileEntryServiceBaseImpl;
037    import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
038    import com.liferay.portlet.documentlibrary.service.permission.DLFolderPermission;
039    import com.liferay.portlet.dynamicdatamapping.DDMFormValues;
040    
041    import java.io.File;
042    import java.io.InputStream;
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    import java.util.Map;
049    
050    /**
051     * Provides the remote service for accessing, adding, checking in/out, deleting,
052     * locking/unlocking, moving, reverting, updating, and verifying document
053     * library file entries. Its methods include permission checks.
054     *
055     * @author Brian Wing Shun Chan
056     * @author Alexander Chow
057     */
058    public class DLFileEntryServiceImpl extends DLFileEntryServiceBaseImpl {
059    
060            @Override
061            public DLFileEntry addFileEntry(
062                            long groupId, long repositoryId, long folderId,
063                            String sourceFileName, String mimeType, String title,
064                            String description, String changeLog, long fileEntryTypeId,
065                            Map<String, DDMFormValues> ddmFormValuesMap, File file,
066                            InputStream is, long size, ServiceContext serviceContext)
067                    throws PortalException {
068    
069                    DLFolderPermission.check(
070                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_DOCUMENT);
071    
072                    return dlFileEntryLocalService.addFileEntry(
073                            getUserId(), groupId, repositoryId, folderId, sourceFileName,
074                            mimeType, title, description, changeLog, fileEntryTypeId,
075                            ddmFormValuesMap, file, is, size, serviceContext);
076            }
077    
078            @Override
079            public DLFileVersion cancelCheckOut(long fileEntryId)
080                    throws PortalException {
081    
082                    boolean locked = LockManagerUtil.isLocked(
083                            DLFileEntry.class.getName(), fileEntryId);
084    
085                    if (locked && !hasFileEntryLock(fileEntryId) &&
086                            !_hasOverrideCheckoutPermission(fileEntryId)) {
087    
088                            throw new PrincipalException.MustHavePermission(
089                                    getUserId(), DLFileEntry.class.getName(), fileEntryId,
090                                    ActionKeys.OVERRIDE_CHECKOUT);
091                    }
092    
093                    return dlFileEntryLocalService.cancelCheckOut(getUserId(), fileEntryId);
094            }
095    
096            @Override
097            public void checkInFileEntry(
098                            long fileEntryId, boolean major, String changeLog,
099                            ServiceContext serviceContext)
100                    throws PortalException {
101    
102                    boolean isLocked = LockManagerUtil.isLocked(
103                            DLFileEntry.class.getName(), fileEntryId);
104    
105                    if (isLocked && !hasFileEntryLock(fileEntryId)) {
106                            throw new FileEntryLockException.MustOwnLock();
107                    }
108    
109                    dlFileEntryLocalService.checkInFileEntry(
110                            getUserId(), fileEntryId, major, changeLog, serviceContext);
111            }
112    
113            /**
114             * @deprecated As of 6.2.0, replaced by {@link #checkInFileEntry(long,
115             *             String, ServiceContext)}
116             */
117            @Deprecated
118            @Override
119            public void checkInFileEntry(long fileEntryId, String lockUuid)
120                    throws PortalException {
121    
122                    checkInFileEntry(fileEntryId, lockUuid, new ServiceContext());
123            }
124    
125            @Override
126            public void checkInFileEntry(
127                            long fileEntryId, String lockUuid, ServiceContext serviceContext)
128                    throws PortalException {
129    
130                    boolean locked = LockManagerUtil.isLocked(
131                            DLFileEntryConstants.getClassName(), fileEntryId);
132    
133                    if (locked && !hasFileEntryLock(fileEntryId)) {
134                            throw new FileEntryLockException.MustOwnLock();
135                    }
136    
137                    dlFileEntryLocalService.checkInFileEntry(
138                            getUserId(), fileEntryId, lockUuid, serviceContext);
139            }
140    
141            /**
142             * @deprecated As of 6.2.0, replaced by {@link #checkOutFileEntry(long,
143             *             ServiceContext)}
144             */
145            @Deprecated
146            @Override
147            public DLFileEntry checkOutFileEntry(long fileEntryId)
148                    throws PortalException {
149    
150                    return checkOutFileEntry(fileEntryId, new ServiceContext());
151            }
152    
153            @Override
154            public DLFileEntry checkOutFileEntry(
155                            long fileEntryId, ServiceContext serviceContext)
156                    throws PortalException {
157    
158                    return checkOutFileEntry(
159                            fileEntryId, null, DLFileEntryImpl.LOCK_EXPIRATION_TIME,
160                            serviceContext);
161            }
162    
163            /**
164             * @deprecated As of 6.2.0, replaced by {@link #checkOutFileEntry(long,
165             *             String, long, ServiceContext)}
166             */
167            @Deprecated
168            @Override
169            public DLFileEntry checkOutFileEntry(
170                            long fileEntryId, String owner, long expirationTime)
171                    throws PortalException {
172    
173                    return checkOutFileEntry(
174                            fileEntryId, owner, expirationTime, new ServiceContext());
175            }
176    
177            @Override
178            public DLFileEntry checkOutFileEntry(
179                            long fileEntryId, String owner, long expirationTime,
180                            ServiceContext serviceContext)
181                    throws PortalException {
182    
183                    DLFileEntryPermission.check(
184                            getPermissionChecker(), fileEntryId, ActionKeys.UPDATE);
185    
186                    return dlFileEntryLocalService.checkOutFileEntry(
187                            getUserId(), fileEntryId, owner, expirationTime, serviceContext);
188            }
189    
190            @Override
191            public DLFileEntry copyFileEntry(
192                            long groupId, long repositoryId, long fileEntryId,
193                            long destFolderId, ServiceContext serviceContext)
194                    throws PortalException {
195    
196                    DLFileEntryPermission.check(
197                            getPermissionChecker(), fileEntryId, ActionKeys.VIEW);
198    
199                    DLFolderPermission.check(
200                            getPermissionChecker(), groupId, destFolderId,
201                            ActionKeys.ADD_DOCUMENT);
202    
203                    return dlFileEntryLocalService.copyFileEntry(
204                            getUserId(), groupId, repositoryId, fileEntryId, destFolderId,
205                            serviceContext);
206            }
207    
208            @Override
209            public void deleteFileEntry(long fileEntryId) throws PortalException {
210                    DLFileEntryPermission.check(
211                            getPermissionChecker(), fileEntryId, ActionKeys.DELETE);
212    
213                    dlFileEntryLocalService.deleteFileEntry(getUserId(), fileEntryId);
214            }
215    
216            @Override
217            public void deleteFileEntry(long groupId, long folderId, String title)
218                    throws PortalException {
219    
220                    DLFileEntry dlFileEntry = getFileEntry(groupId, folderId, title);
221    
222                    deleteFileEntry(dlFileEntry.getFileEntryId());
223            }
224    
225            @Override
226            public void deleteFileVersion(long fileEntryId, String version)
227                    throws PortalException {
228    
229                    DLFileEntryPermission.check(
230                            getPermissionChecker(), fileEntryId, ActionKeys.DELETE);
231    
232                    dlFileEntryLocalService.deleteFileVersion(
233                            getUserId(), fileEntryId, version);
234            }
235    
236            @Override
237            public DLFileEntry fetchFileEntryByImageId(long imageId)
238                    throws PortalException {
239    
240                    DLFileEntry dlFileEntry = dlFileEntryFinder.fetchByAnyImageId(imageId);
241    
242                    if (dlFileEntry != null) {
243                            DLFileEntryPermission.check(
244                                    getPermissionChecker(), dlFileEntry, ActionKeys.VIEW);
245                    }
246    
247                    return dlFileEntry;
248            }
249    
250            @Override
251            public InputStream getFileAsStream(long fileEntryId, String version)
252                    throws PortalException {
253    
254                    DLFileEntryPermission.check(
255                            getPermissionChecker(), fileEntryId, ActionKeys.VIEW);
256    
257                    return dlFileEntryLocalService.getFileAsStream(fileEntryId, version);
258            }
259    
260            @Override
261            public InputStream getFileAsStream(
262                            long fileEntryId, String version, boolean incrementCounter)
263                    throws PortalException {
264    
265                    DLFileEntryPermission.check(
266                            getPermissionChecker(), fileEntryId, ActionKeys.VIEW);
267    
268                    return dlFileEntryLocalService.getFileAsStream(
269                            fileEntryId, version, incrementCounter);
270            }
271    
272            @Override
273            public List<DLFileEntry> getFileEntries(
274                            long groupId, long folderId, int status, int start, int end,
275                            OrderByComparator<DLFileEntry> obc)
276                    throws PortalException {
277    
278                    DLFolderPermission.check(
279                            getPermissionChecker(), groupId, folderId, ActionKeys.VIEW);
280    
281                    List<Long> folderIds = new ArrayList<>();
282    
283                    folderIds.add(folderId);
284    
285                    QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(
286                            status, false, start, end, obc);
287    
288                    return dlFileEntryFinder.filterFindByG_F(
289                            groupId, folderIds, queryDefinition);
290            }
291    
292            @Override
293            public List<DLFileEntry> getFileEntries(
294                            long groupId, long folderId, int start, int end,
295                            OrderByComparator<DLFileEntry> obc)
296                    throws PortalException {
297    
298                    return getFileEntries(
299                            groupId, folderId, WorkflowConstants.STATUS_APPROVED, start, end,
300                            obc);
301            }
302    
303            @Override
304            public List<DLFileEntry> getFileEntries(
305                            long groupId, long folderId, long fileEntryTypeId, int start,
306                            int end, OrderByComparator<DLFileEntry> obc)
307                    throws PortalException {
308    
309                    DLFolderPermission.check(
310                            getPermissionChecker(), groupId, folderId, ActionKeys.VIEW);
311    
312                    return dlFileEntryPersistence.filterFindByG_F_F(
313                            groupId, folderId, fileEntryTypeId, start, end, obc);
314            }
315    
316            @Override
317            public List<DLFileEntry> getFileEntries(
318                            long groupId, long folderId, String[] mimeTypes, int start, int end,
319                            OrderByComparator<DLFileEntry> obc)
320                    throws PortalException {
321    
322                    DLFolderPermission.check(
323                            getPermissionChecker(), groupId, folderId, ActionKeys.VIEW);
324    
325                    List<Long> folderIds = new ArrayList<>();
326    
327                    folderIds.add(folderId);
328    
329                    QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(
330                            WorkflowConstants.STATUS_IN_TRASH, true, start, end, obc);
331    
332                    return dlFileEntryFinder.filterFindByG_U_F_M(
333                            groupId, 0, folderIds, mimeTypes, queryDefinition);
334            }
335    
336            @Override
337            public int getFileEntriesCount(long groupId, long folderId) {
338                    return getFileEntriesCount(
339                            groupId, folderId, WorkflowConstants.STATUS_APPROVED);
340            }
341    
342            @Override
343            public int getFileEntriesCount(long groupId, long folderId, int status) {
344                    List<Long> folderIds = new ArrayList<>();
345    
346                    folderIds.add(folderId);
347    
348                    return dlFileEntryFinder.filterCountByG_F(
349                            groupId, folderIds, new QueryDefinition<DLFileEntry>(status));
350            }
351    
352            @Override
353            public int getFileEntriesCount(
354                    long groupId, long folderId, long fileEntryTypeId) {
355    
356                    return dlFileEntryPersistence.filterCountByG_F_F(
357                            groupId, folderId, fileEntryTypeId);
358            }
359    
360            @Override
361            public int getFileEntriesCount(
362                    long groupId, long folderId, String[] mimeTypes) {
363    
364                    List<Long> folderIds = new ArrayList<>();
365    
366                    folderIds.add(folderId);
367    
368                    return dlFileEntryFinder.filterCountByG_U_F_M(
369                            groupId, 0, folderIds, mimeTypes,
370                            new QueryDefinition<DLFileEntry>(WorkflowConstants.STATUS_ANY));
371            }
372    
373            @Override
374            public DLFileEntry getFileEntry(long fileEntryId) throws PortalException {
375                    DLFileEntryPermission.check(
376                            getPermissionChecker(), fileEntryId, ActionKeys.VIEW);
377    
378                    return dlFileEntryLocalService.getFileEntry(fileEntryId);
379            }
380    
381            @Override
382            public DLFileEntry getFileEntry(long groupId, long folderId, String title)
383                    throws PortalException {
384    
385                    DLFileEntry dlFileEntry = dlFileEntryLocalService.getFileEntry(
386                            groupId, folderId, title);
387    
388                    DLFileEntryPermission.check(
389                            getPermissionChecker(), dlFileEntry, ActionKeys.VIEW);
390    
391                    return dlFileEntry;
392            }
393    
394            @Override
395            public DLFileEntry getFileEntryByUuidAndGroupId(String uuid, long groupId)
396                    throws PortalException {
397    
398                    DLFileEntry dlFileEntry = dlFileEntryPersistence.findByUUID_G(
399                            uuid, groupId);
400    
401                    DLFileEntryPermission.check(
402                            getPermissionChecker(), dlFileEntry, ActionKeys.VIEW);
403    
404                    return dlFileEntry;
405            }
406    
407            @Override
408            public Lock getFileEntryLock(long fileEntryId) {
409                    try {
410                            return LockManagerUtil.getLock(
411                                    DLFileEntry.class.getName(), fileEntryId);
412                    }
413                    catch (Exception e) {
414                            return null;
415                    }
416            }
417    
418            @Override
419            public int getFoldersFileEntriesCount(
420                    long groupId, List<Long> folderIds, int status) {
421    
422                    QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(
423                            status);
424    
425                    if (folderIds.size() <= PropsValues.SQL_DATA_MAX_PARAMETERS) {
426                            return dlFileEntryFinder.filterCountByG_F(
427                                    groupId, folderIds, queryDefinition);
428                    }
429                    else {
430                            int start = 0;
431                            int end = PropsValues.SQL_DATA_MAX_PARAMETERS;
432    
433                            int filesCount = dlFileEntryFinder.filterCountByG_F(
434                                    groupId, folderIds.subList(start, end), queryDefinition);
435    
436                            folderIds.subList(start, end).clear();
437    
438                            filesCount += getFoldersFileEntriesCount(
439                                    groupId, folderIds, status);
440    
441                            return filesCount;
442                    }
443            }
444    
445            @Override
446            public List<DLFileEntry> getGroupFileEntries(
447                            long groupId, long userId, long rootFolderId, int start, int end,
448                            OrderByComparator<DLFileEntry> obc)
449                    throws PortalException {
450    
451                    List<Long> folderIds = dlFolderService.getFolderIds(
452                            groupId, rootFolderId);
453    
454                    if (folderIds.isEmpty()) {
455                            return Collections.emptyList();
456                    }
457                    else if (userId <= 0) {
458                            return dlFileEntryPersistence.filterFindByG_F(
459                                    groupId, ArrayUtil.toLongArray(folderIds), start, end, obc);
460                    }
461                    else {
462                            return dlFileEntryPersistence.filterFindByG_U_F(
463                                    groupId, userId, ArrayUtil.toLongArray(folderIds), start, end,
464                                    obc);
465                    }
466            }
467    
468            @Override
469            public List<DLFileEntry> getGroupFileEntries(
470                            long groupId, long userId, long repositoryId, long rootFolderId,
471                            String[] mimeTypes, int status, int start, int end,
472                            OrderByComparator<DLFileEntry> obc)
473                    throws PortalException {
474    
475                    List<Long> repositoryIds = new ArrayList<>();
476    
477                    if (repositoryId != 0) {
478                            repositoryIds.add(repositoryId);
479                    }
480    
481                    QueryDefinition<DLFileEntry> queryDefinition = new QueryDefinition<>(
482                            status, start, end, obc);
483    
484                    if (rootFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
485                            return dlFileEntryFinder.filterFindByG_U_R_F_M(
486                                    groupId, userId, repositoryIds, new ArrayList<Long>(),
487                                    mimeTypes, queryDefinition);
488                    }
489    
490                    List<Long> folderIds = dlFolderService.getFolderIds(
491                            groupId, rootFolderId);
492    
493                    if (folderIds.isEmpty()) {
494                            return Collections.emptyList();
495                    }
496    
497                    return dlFileEntryFinder.filterFindByG_U_R_F_M(
498                            groupId, userId, repositoryIds, folderIds, mimeTypes,
499                            queryDefinition);
500            }
501    
502            @Override
503            public List<DLFileEntry> getGroupFileEntries(
504                            long groupId, long userId, long rootFolderId, String[] mimeTypes,
505                            int status, int start, int end, OrderByComparator<DLFileEntry> obc)
506                    throws PortalException {
507    
508                    return getGroupFileEntries(
509                            groupId, userId, 0, rootFolderId, mimeTypes, status, start, end,
510                            obc);
511            }
512    
513            @Override
514            public int getGroupFileEntriesCount(
515                            long groupId, long userId, long rootFolderId)
516                    throws PortalException {
517    
518                    List<Long> folderIds = dlFolderService.getFolderIds(
519                            groupId, rootFolderId);
520    
521                    if (folderIds.isEmpty()) {
522                            return 0;
523                    }
524                    else if (userId <= 0) {
525                            return dlFileEntryPersistence.filterCountByG_F(
526                                    groupId, ArrayUtil.toLongArray(folderIds));
527                    }
528                    else {
529                            return dlFileEntryPersistence.filterCountByG_U_F(
530                                    groupId, userId, ArrayUtil.toLongArray(folderIds));
531                    }
532            }
533    
534            @Override
535            public int getGroupFileEntriesCount(
536                            long groupId, long userId, long repositoryId, long rootFolderId,
537                            String[] mimeTypes, int status)
538                    throws PortalException {
539    
540                    List<Long> repositoryIds = new ArrayList<>();
541    
542                    if (repositoryId != 0) {
543                            repositoryIds.add(repositoryId);
544                    }
545    
546                    if (rootFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
547                            return dlFileEntryFinder.filterCountByG_U_R_F_M(
548                                    groupId, userId, repositoryIds, new ArrayList<Long>(),
549                                    mimeTypes, new QueryDefinition<DLFileEntry>(status));
550                    }
551    
552                    List<Long> folderIds = dlFolderService.getFolderIds(
553                            groupId, rootFolderId);
554    
555                    if (folderIds.isEmpty()) {
556                            return 0;
557                    }
558    
559                    return dlFileEntryFinder.filterCountByG_U_R_F_M(
560                            groupId, userId, repositoryIds, folderIds, mimeTypes,
561                            new QueryDefinition<DLFileEntry>(status));
562            }
563    
564            @Override
565            public int getGroupFileEntriesCount(
566                            long groupId, long userId, long rootFolderId, String[] mimeTypes,
567                            int status)
568                    throws PortalException {
569    
570                    return getGroupFileEntriesCount(
571                            groupId, userId, 0, rootFolderId, mimeTypes, status);
572            }
573    
574            @Override
575            public boolean hasFileEntryLock(long fileEntryId) throws PortalException {
576                    DLFileEntry dlFileEntry = dlFileEntryLocalService.getFileEntry(
577                            fileEntryId);
578    
579                    long folderId = dlFileEntry.getFolderId();
580    
581                    boolean hasLock = LockManagerUtil.hasLock(
582                            getUserId(), DLFileEntry.class.getName(), fileEntryId);
583    
584                    if (!hasLock &&
585                            (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {
586    
587                            hasLock = dlFolderLocalService.hasInheritableLock(folderId);
588                    }
589    
590                    return hasLock;
591            }
592    
593            @Override
594            public boolean isFileEntryCheckedOut(long fileEntryId)
595                    throws PortalException {
596    
597                    return dlFileEntryLocalService.isFileEntryCheckedOut(fileEntryId);
598            }
599    
600            @Override
601            public boolean isKeepFileVersionLabel(
602                            long fileEntryId, ServiceContext serviceContext)
603                    throws PortalException {
604    
605                    PermissionChecker permissionChecker = getPermissionChecker();
606    
607                    DLFileEntryPermission.check(
608                            permissionChecker, fileEntryId, ActionKeys.VIEW);
609    
610                    return dlFileEntryLocalService.isKeepFileVersionLabel(
611                            fileEntryId, serviceContext);
612            }
613    
614            @Override
615            public DLFileEntry moveFileEntry(
616                            long fileEntryId, long newFolderId, ServiceContext serviceContext)
617                    throws PortalException {
618    
619                    PermissionChecker permissionChecker = getPermissionChecker();
620    
621                    DLFileEntryPermission.check(
622                            permissionChecker, fileEntryId, ActionKeys.UPDATE);
623    
624                    DLFolderPermission.check(
625                            permissionChecker, serviceContext.getScopeGroupId(), newFolderId,
626                            ActionKeys.ADD_DOCUMENT);
627    
628                    return dlFileEntryLocalService.moveFileEntry(
629                            getUserId(), fileEntryId, newFolderId, serviceContext);
630            }
631    
632            @Override
633            public Lock refreshFileEntryLock(
634                            String lockUuid, long companyId, long expirationTime)
635                    throws PortalException {
636    
637                    return LockManagerUtil.refresh(lockUuid, companyId, expirationTime);
638            }
639    
640            @Override
641            public void revertFileEntry(
642                            long fileEntryId, String version, ServiceContext serviceContext)
643                    throws PortalException {
644    
645                    DLFileEntryPermission.check(
646                            getPermissionChecker(), fileEntryId, ActionKeys.UPDATE);
647    
648                    dlFileEntryLocalService.revertFileEntry(
649                            getUserId(), fileEntryId, version, serviceContext);
650            }
651    
652            @Override
653            public Hits search(
654                            long groupId, long creatorUserId, int status, int start, int end)
655                    throws PortalException {
656    
657                    return dlFileEntryLocalService.search(
658                            groupId, getUserId(), creatorUserId, status, start, end);
659            }
660    
661            @Override
662            public Hits search(
663                            long groupId, long creatorUserId, long folderId, String[] mimeTypes,
664                            int status, int start, int end)
665                    throws PortalException {
666    
667                    return dlFileEntryLocalService.search(
668                            groupId, getUserId(), creatorUserId, folderId, mimeTypes, status,
669                            start, end);
670            }
671    
672            @Override
673            public DLFileEntry updateFileEntry(
674                            long fileEntryId, String sourceFileName, String mimeType,
675                            String title, String description, String changeLog,
676                            boolean majorVersion, long fileEntryTypeId,
677                            Map<String, DDMFormValues> ddmFormValuesMap, File file,
678                            InputStream is, long size, ServiceContext serviceContext)
679                    throws PortalException {
680    
681                    DLFileEntryPermission.check(
682                            getPermissionChecker(), fileEntryId, ActionKeys.UPDATE);
683    
684                    if (LockManagerUtil.isLocked(
685                                    DLFileEntryConstants.getClassName(), fileEntryId)) {
686    
687                            boolean hasLock = LockManagerUtil.hasLock(
688                                    getUserId(), DLFileEntry.class.getName(), fileEntryId);
689    
690                            if (!hasLock) {
691                                    throw new FileEntryLockException.MustOwnLock();
692                            }
693                    }
694    
695                    return dlFileEntryLocalService.updateFileEntry(
696                            getUserId(), fileEntryId, sourceFileName, mimeType, title,
697                            description, changeLog, majorVersion, fileEntryTypeId,
698                            ddmFormValuesMap, file, is, size, serviceContext);
699            }
700    
701            @Override
702            public DLFileEntry updateStatus(
703                            long userId, long fileVersionId, int status,
704                            ServiceContext serviceContext,
705                            Map<String, Serializable> workflowContext)
706                    throws PortalException {
707    
708                    DLFileVersion dlFileVersion = dlFileVersionLocalService.getFileVersion(
709                            fileVersionId);
710    
711                    DLFileEntryPermission.check(
712                            getPermissionChecker(), dlFileVersion.getFileEntryId(),
713                            ActionKeys.UPDATE);
714    
715                    return dlFileEntryLocalService.updateStatus(
716                            userId, fileVersionId, status, serviceContext, workflowContext);
717            }
718    
719            @Override
720            public boolean verifyFileEntryCheckOut(long fileEntryId, String lockUuid)
721                    throws PortalException {
722    
723                    return dlFileEntryLocalService.verifyFileEntryCheckOut(
724                            fileEntryId, lockUuid);
725            }
726    
727            @Override
728            public boolean verifyFileEntryLock(long fileEntryId, String lockUuid)
729                    throws PortalException {
730    
731                    return dlFileEntryLocalService.verifyFileEntryLock(
732                            fileEntryId, lockUuid);
733            }
734    
735            private boolean _hasOverrideCheckoutPermission(long fileEntryId)
736                    throws PortalException {
737    
738                    return DLFileEntryPermission.contains(
739                            getPermissionChecker(), fileEntryId, ActionKeys.OVERRIDE_CHECKOUT);
740            }
741    
742    }