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.model.FileEntry;
020    import com.liferay.portal.repository.capabilities.WorkflowSupport;
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, 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 major, String changeLog,
089                            ServiceContext serviceContext)
090                    throws PortalException {
091    
092                    super.checkInFileEntry(
093                            userId, fileEntryId, major, changeLog, serviceContext);
094    
095                    FileEntry fileEntry = super.getFileEntry(fileEntryId);
096    
097                    _workflowSupport.checkInFileEntry(userId, fileEntry, serviceContext);
098            }
099    
100            @Override
101            public void checkInFileEntry(
102                            long userId, long fileEntryId, String lockUuid,
103                            ServiceContext serviceContext)
104                    throws PortalException {
105    
106                    super.checkInFileEntry(userId, fileEntryId, lockUuid, serviceContext);
107    
108                    FileEntry fileEntry = super.getFileEntry(fileEntryId);
109    
110                    _workflowSupport.checkInFileEntry(userId, fileEntry, serviceContext);
111            }
112    
113            @Override
114            public FileEntry copyFileEntry(
115                            long userId, long groupId, long fileEntryId, long destFolderId,
116                            ServiceContext serviceContext)
117                    throws PortalException {
118    
119                    FileEntry fileEntry = super.copyFileEntry(
120                            userId, groupId, fileEntryId, destFolderId, serviceContext);
121    
122                    DLAppHelperLocalServiceUtil.updateAsset(
123                            userId, fileEntry, fileEntry.getFileVersion(),
124                            serviceContext.getAssetCategoryIds(),
125                            serviceContext.getAssetTagNames(),
126                            serviceContext.getAssetLinkEntryIds());
127    
128                    _workflowSupport.addFileEntry(userId, fileEntry, serviceContext);
129    
130                    return fileEntry;
131            }
132    
133            @Override
134            public void revertFileEntry(
135                    long userId, long fileEntryId, String version,
136                    ServiceContext serviceContext) 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    }