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.ProcessorCapability;
021    import com.liferay.portal.kernel.repository.model.FileEntry;
022    import com.liferay.portal.kernel.repository.model.FileVersion;
023    import com.liferay.portal.kernel.transaction.TransactionCommitCallbackRegistryUtil;
024    import com.liferay.portal.repository.liferayrepository.LiferayProcessorLocalRepositoryWrapper;
025    import com.liferay.portal.repository.liferayrepository.LiferayProcessorRepositoryWrapper;
026    import com.liferay.portal.repository.util.RepositoryWrapperAware;
027    import com.liferay.portlet.documentlibrary.util.DLProcessorRegistryUtil;
028    
029    import java.util.concurrent.Callable;
030    
031    /**
032     * @author Adolfo P??rez
033     */
034    public class LiferayProcessorCapability
035            implements ProcessorCapability, RepositoryWrapperAware {
036    
037            @Override
038            public void cleanUp(FileEntry fileEntry) {
039                    DLProcessorRegistryUtil.cleanUp(fileEntry);
040            }
041    
042            @Override
043            public void cleanUp(FileVersion fileVersion) {
044                    DLProcessorRegistryUtil.cleanUp(fileVersion);
045            }
046    
047            @Override
048            public void copyPrevious(FileVersion fileVersion) throws PortalException {
049                    registerDLProcessorCallback(fileVersion.getFileEntry(), fileVersion);
050            }
051    
052            @Override
053            public void generateNew(FileEntry fileEntry) {
054                    registerDLProcessorCallback(fileEntry, null);
055            }
056    
057            @Override
058            public LocalRepository wrapLocalRepository(
059                    LocalRepository localRepository) {
060    
061                    return new LiferayProcessorLocalRepositoryWrapper(
062                            localRepository, this);
063            }
064    
065            @Override
066            public Repository wrapRepository(Repository repository) {
067                    return new LiferayProcessorRepositoryWrapper(repository, this);
068            }
069    
070            protected void registerDLProcessorCallback(
071                    final FileEntry fileEntry, final FileVersion fileVersion) {
072    
073                    TransactionCommitCallbackRegistryUtil.registerCallback(
074                            new Callable<Void>() {
075    
076                                    @Override
077                                    public Void call() throws Exception {
078                                            DLProcessorRegistryUtil.trigger(
079                                                    fileEntry, fileVersion, true);
080    
081                                            return null;
082                                    }
083    
084                            });
085            }
086    
087    }