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.exception.PortalException;
018    import com.liferay.portal.kernel.repository.DocumentRepository;
019    import com.liferay.portal.kernel.repository.LocalRepository;
020    import com.liferay.portlet.documentlibrary.service.DLAppLocalService;
021    import com.liferay.portlet.documentlibrary.service.DLAppLocalServiceUtil;
022    import com.liferay.portlet.documentlibrary.service.DLAppService;
023    import com.liferay.portlet.documentlibrary.service.DLAppServiceUtil;
024    
025    /**
026     * @author Iv??n Zaera
027     */
028    public class DLAppServiceAdapter {
029    
030            public static DLAppServiceAdapter create(
031                    DocumentRepository documentRepository) {
032    
033                    if (documentRepository instanceof LocalRepository) {
034                            return new DLAppServiceAdapter(DLAppLocalServiceUtil.getService());
035                    }
036    
037                    return new DLAppServiceAdapter(
038                            DLAppLocalServiceUtil.getService(), DLAppServiceUtil.getService());
039            }
040    
041            public DLAppServiceAdapter(DLAppLocalService dlAppLocalService) {
042                    this(dlAppLocalService, null);
043            }
044    
045            public DLAppServiceAdapter(
046                    DLAppLocalService dlAppLocalService, DLAppService dlAppService) {
047    
048                    _dlAppLocalService = dlAppLocalService;
049                    _dlAppService = dlAppService;
050            }
051    
052            public void deleteFileEntry(long fileEntryId) throws PortalException {
053                    if (_dlAppService != null) {
054                            _dlAppService.deleteFileEntry(fileEntryId);
055                    }
056                    else {
057                            _dlAppLocalService.deleteFileEntry(fileEntryId);
058                    }
059            }
060    
061            private final DLAppLocalService _dlAppLocalService;
062            private final DLAppService _dlAppService;
063    
064    }