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