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.portal.repository.liferayrepository;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.repository.LocalRepository;
019    import com.liferay.portal.kernel.repository.capabilities.WorkflowCapability;
020    import com.liferay.portal.kernel.repository.model.FileEntry;
021    import com.liferay.portal.repository.util.LocalRepositoryWrapper;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portlet.documentlibrary.service.DLAppHelperLocalServiceUtil;
024    
025    import java.io.File;
026    import java.io.InputStream;
027    
028    /**
029     * @author Adolfo P??rez
030     */
031    public class LiferayWorkflowLocalRepositoryWrapper
032            extends LocalRepositoryWrapper {
033    
034            public LiferayWorkflowLocalRepositoryWrapper(
035                    LocalRepository localRepository,
036                    WorkflowCapability workflowCapability) {
037    
038                    super(localRepository);
039    
040                    _workflowCapability = workflowCapability;
041            }
042    
043            @Override
044            public FileEntry addFileEntry(
045                            long userId, long folderId, String sourceFileName, String mimeType,
046                            String title, String description, String changeLog, File file,
047                            ServiceContext serviceContext)
048                    throws PortalException {
049    
050                    FileEntry fileEntry = super.addFileEntry(
051                            userId, folderId, sourceFileName, mimeType, title, description,
052                            changeLog, file, serviceContext);
053    
054                    DLAppHelperLocalServiceUtil.updateAsset(
055                            userId, fileEntry, fileEntry.getFileVersion(),
056                            serviceContext.getAssetCategoryIds(),
057                            serviceContext.getAssetTagNames(),
058                            serviceContext.getAssetLinkEntryIds());
059    
060                    _workflowCapability.addFileEntry(userId, fileEntry, serviceContext);
061    
062                    return fileEntry;
063            }
064    
065            @Override
066            public FileEntry addFileEntry(
067                            long userId, long folderId, String sourceFileName, String mimeType,
068                            String title, String description, String changeLog, InputStream is,
069                            long size, ServiceContext serviceContext)
070                    throws PortalException {
071    
072                    FileEntry fileEntry = super.addFileEntry(
073                            userId, folderId, sourceFileName, mimeType, title, description,
074                            changeLog, is, size, serviceContext);
075    
076                    DLAppHelperLocalServiceUtil.updateAsset(
077                            userId, fileEntry, fileEntry.getFileVersion(),
078                            serviceContext.getAssetCategoryIds(),
079                            serviceContext.getAssetTagNames(),
080                            serviceContext.getAssetLinkEntryIds());
081    
082                    _workflowCapability.addFileEntry(userId, fileEntry, serviceContext);
083    
084                    return fileEntry;
085            }
086    
087            @Override
088            public void checkInFileEntry(
089                            long userId, long fileEntryId, boolean major, String changeLog,
090                            ServiceContext serviceContext)
091                    throws PortalException {
092    
093                    super.checkInFileEntry(
094                            userId, fileEntryId, major, changeLog, serviceContext);
095    
096                    FileEntry fileEntry = super.getFileEntry(fileEntryId);
097    
098                    _workflowCapability.checkInFileEntry(userId, fileEntry, serviceContext);
099            }
100    
101            @Override
102            public void checkInFileEntry(
103                            long userId, long fileEntryId, String lockUuid,
104                            ServiceContext serviceContext)
105                    throws PortalException {
106    
107                    super.checkInFileEntry(userId, fileEntryId, lockUuid, serviceContext);
108    
109                    FileEntry fileEntry = super.getFileEntry(fileEntryId);
110    
111                    _workflowCapability.checkInFileEntry(userId, fileEntry, serviceContext);
112            }
113    
114            @Override
115            public FileEntry copyFileEntry(
116                            long userId, long groupId, long fileEntryId, long destFolderId,
117                            ServiceContext serviceContext)
118                    throws PortalException {
119    
120                    FileEntry fileEntry = super.copyFileEntry(
121                            userId, groupId, fileEntryId, destFolderId, serviceContext);
122    
123                    DLAppHelperLocalServiceUtil.updateAsset(
124                            userId, fileEntry, fileEntry.getFileVersion(),
125                            serviceContext.getAssetCategoryIds(),
126                            serviceContext.getAssetTagNames(),
127                            serviceContext.getAssetLinkEntryIds());
128    
129                    _workflowCapability.addFileEntry(userId, fileEntry, serviceContext);
130    
131                    return fileEntry;
132            }
133    
134            @Override
135            public void revertFileEntry(
136                    long userId, long fileEntryId, String version,
137                    ServiceContext serviceContext) throws PortalException {
138    
139                    super.revertFileEntry(userId, fileEntryId, version, serviceContext);
140    
141                    FileEntry fileEntry = super.getFileEntry(fileEntryId);
142    
143                    _workflowCapability.revertFileEntry(userId, fileEntry, serviceContext);
144            }
145    
146            @Override
147            public FileEntry updateFileEntry(
148                            long userId, long fileEntryId, String sourceFileName,
149                            String mimeType, String title, String description, String changeLog,
150                            boolean majorVersion, File file, ServiceContext serviceContext)
151                    throws PortalException {
152    
153                    FileEntry fileEntry = super.updateFileEntry(
154                            userId, fileEntryId, sourceFileName, mimeType, title, description,
155                            changeLog, majorVersion, file, serviceContext);
156    
157                    _workflowCapability.updateFileEntry(userId, fileEntry, serviceContext);
158    
159                    return super.getFileEntry(fileEntryId);
160            }
161    
162            @Override
163            public FileEntry updateFileEntry(
164                            long userId, long fileEntryId, String sourceFileName,
165                            String mimeType, String title, String description, String changeLog,
166                            boolean majorVersion, InputStream is, long size,
167                            ServiceContext serviceContext)
168                    throws PortalException {
169    
170                    FileEntry fileEntry = super.updateFileEntry(
171                            userId, fileEntryId, sourceFileName, mimeType, title, description,
172                            changeLog, majorVersion, is, size, serviceContext);
173    
174                    _workflowCapability.updateFileEntry(userId, fileEntry, serviceContext);
175    
176                    return super.getFileEntry(fileEntryId);
177            }
178    
179            private final WorkflowCapability _workflowCapability;
180    
181    }