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.capabilities;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.repository.LocalRepository;
019    import com.liferay.portal.kernel.repository.Repository;
020    import com.liferay.portal.kernel.repository.capabilities.WorkflowCapability;
021    import com.liferay.portal.kernel.repository.model.FileEntry;
022    import com.liferay.portal.kernel.repository.model.FileVersion;
023    import com.liferay.portal.kernel.workflow.WorkflowConstants;
024    import com.liferay.portal.repository.liferayrepository.LiferayWorkflowLocalRepositoryWrapper;
025    import com.liferay.portal.repository.liferayrepository.LiferayWorkflowRepositoryWrapper;
026    import com.liferay.portal.repository.util.RepositoryWrapperAware;
027    import com.liferay.portal.service.ServiceContext;
028    import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
029    
030    import java.io.Serializable;
031    
032    import java.util.Collections;
033    import java.util.Map;
034    
035    /**
036     * @author Adolfo P??rez
037     */
038    public class MinimalWorkflowCapability
039            implements RepositoryWrapperAware, WorkflowCapability {
040    
041            @Override
042            public void addFileEntry(
043                            long userId, FileEntry fileEntry, ServiceContext serviceContext)
044                    throws PortalException {
045    
046                    doUpdateStatus(userId, fileEntry, serviceContext);
047            }
048    
049            @Override
050            public void checkInFileEntry(
051                            long userId, FileEntry fileEntry, ServiceContext serviceContext)
052                    throws PortalException {
053    
054                    doUpdateStatus(userId, fileEntry, serviceContext);
055            }
056    
057            @Override
058            public void revertFileEntry(
059                            long userId, FileEntry fileEntry, ServiceContext serviceContext)
060                    throws PortalException {
061    
062                    doUpdateStatus(userId, fileEntry, serviceContext);
063            }
064    
065            @Override
066            public void updateFileEntry(
067                            long userId, FileEntry fileEntry, ServiceContext serviceContext)
068                    throws PortalException {
069    
070                    doUpdateStatus(userId, fileEntry, serviceContext);
071            }
072    
073            @Override
074            public LocalRepository wrapLocalRepository(
075                    LocalRepository localRepository) {
076    
077                    return new LiferayWorkflowLocalRepositoryWrapper(localRepository, this);
078            }
079    
080            @Override
081            public Repository wrapRepository(Repository repository) {
082                    return new LiferayWorkflowRepositoryWrapper(repository, this);
083            }
084    
085            protected void doUpdateStatus(
086                            long userId, FileEntry fileEntry, ServiceContext serviceContext)
087                    throws PortalException {
088    
089                    Map<String, Serializable> workflowContext = Collections.emptyMap();
090    
091                    FileVersion fileVersion = fileEntry.getFileVersion();
092    
093                    DLFileEntryLocalServiceUtil.updateStatus(
094                            userId, fileVersion.getFileVersionId(),
095                            WorkflowConstants.STATUS_APPROVED, serviceContext, workflowContext);
096            }
097    
098    }