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