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.util;
016    
017    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
018    import com.liferay.portal.kernel.dao.orm.QueryDefinition;
019    import com.liferay.portal.kernel.exception.PortalException;
020    import com.liferay.portal.kernel.repository.DocumentRepository;
021    import com.liferay.portal.kernel.repository.LocalRepository;
022    import com.liferay.portal.security.auth.PrincipalException;
023    import com.liferay.portlet.documentlibrary.service.DLFolderLocalService;
024    import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
025    import com.liferay.portlet.documentlibrary.service.DLFolderService;
026    import com.liferay.portlet.documentlibrary.service.DLFolderServiceUtil;
027    
028    import java.util.List;
029    
030    /**
031     * @author Iv??n Zaera
032     */
033    public class DLFolderServiceAdapter {
034    
035            public static DLFolderServiceAdapter create(
036                    DocumentRepository documentRepository) {
037    
038                    if (documentRepository instanceof LocalRepository) {
039                            return new DLFolderServiceAdapter(
040                                    DLFolderLocalServiceUtil.getService());
041                    }
042    
043                    return new DLFolderServiceAdapter(
044                            DLFolderLocalServiceUtil.getService(),
045                            DLFolderServiceUtil.getService());
046            }
047    
048            public DLFolderServiceAdapter(DLFolderLocalService dlFolderLocalService) {
049                    this(dlFolderLocalService, null);
050            }
051    
052            public DLFolderServiceAdapter(
053                    DLFolderLocalService dlFolderLocalService,
054                    DLFolderService dlFolderService) {
055    
056                    _dlFolderLocalService = dlFolderLocalService;
057                    _dlFolderService = dlFolderService;
058            }
059    
060            public void deleteFolder(long folderId, boolean includeTrashedEntries)
061                    throws PortalException {
062    
063                    if (_dlFolderService != null) {
064                            _dlFolderService.deleteFolder(folderId, includeTrashedEntries);
065                    }
066                    else {
067                            _dlFolderLocalService.deleteFolder(folderId, includeTrashedEntries);
068                    }
069            }
070    
071            public ActionableDynamicQuery getActionableDynamicQuery()
072                    throws PortalException {
073    
074                    if (_dlFolderService != null) {
075                            throw new PrincipalException("DL folder service is not null");
076                    }
077    
078                    return _dlFolderLocalService.getActionableDynamicQuery();
079            }
080    
081            public List<Object> getFoldersAndFileEntriesAndFileShortcuts(
082                            long groupId, long folderId, String[] mimeTypes,
083                            boolean includeMountFolders, QueryDefinition<?> queryDefinition)
084                    throws PortalException {
085    
086                    List<Object> foldersAndFileEntriesAndFileShortcuts = null;
087    
088                    if (_dlFolderService != null) {
089                            foldersAndFileEntriesAndFileShortcuts =
090                                    _dlFolderService.getFoldersAndFileEntriesAndFileShortcuts(
091                                            groupId, folderId, mimeTypes, includeMountFolders,
092                                            queryDefinition);
093                    }
094                    else {
095                            foldersAndFileEntriesAndFileShortcuts =
096                                    _dlFolderLocalService.getFoldersAndFileEntriesAndFileShortcuts(
097                                            groupId, folderId, mimeTypes, includeMountFolders,
098                                            queryDefinition);
099                    }
100    
101                    return foldersAndFileEntriesAndFileShortcuts;
102            }
103    
104            private final DLFolderLocalService _dlFolderLocalService;
105            private final DLFolderService _dlFolderService;
106    
107    }