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.portal.model.Group;
021    import com.liferay.portal.service.GroupLocalService;
022    import com.liferay.portal.service.GroupLocalServiceUtil;
023    import com.liferay.portal.service.GroupService;
024    import com.liferay.portal.service.GroupServiceUtil;
025    
026    /**
027     * @author Iv??n Zaera
028     */
029    public class GroupServiceAdapter {
030    
031            public static GroupServiceAdapter create(
032                    DocumentRepository documentRepository) {
033    
034                    if (documentRepository instanceof LocalRepository) {
035                            return new GroupServiceAdapter(GroupLocalServiceUtil.getService());
036                    }
037    
038                    return new GroupServiceAdapter(
039                            GroupLocalServiceUtil.getService(), GroupServiceUtil.getService());
040            }
041    
042            public GroupServiceAdapter(GroupLocalService groupLocalService) {
043                    this(groupLocalService, null);
044            }
045    
046            public GroupServiceAdapter(
047                    GroupLocalService groupLocalService, GroupService groupService) {
048    
049                    _groupLocalService = groupLocalService;
050                    _groupService = groupService;
051            }
052    
053            public Group getGroup(long groupId) throws PortalException {
054                    Group group = null;
055    
056                    if (_groupService != null) {
057                            group = _groupService.getGroup(groupId);
058                    }
059                    else {
060                            group = _groupLocalService.getGroup(groupId);
061                    }
062    
063                    return group;
064            }
065    
066            private final GroupLocalService _groupLocalService;
067            private final GroupService _groupService;
068    
069    }