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.kernel.settings;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.model.Group;
019    import com.liferay.portal.service.GroupLocalServiceUtil;
020    
021    /**
022     * @author Ivan Zaera
023     * @author Jorge Ferrer
024     */
025    public class GroupServiceSettingsLocator implements SettingsLocator {
026    
027            public GroupServiceSettingsLocator(long groupId, String settingsId) {
028                    _groupId = groupId;
029                    _settingsId = settingsId;
030            }
031    
032            @Override
033            public Settings getSettings() throws SettingsException {
034                    long companyId = getCompanyId(_groupId);
035    
036                    Settings portalPropertiesSettings =
037                            _settingsLocatorHelper.getPortalPropertiesSettings();
038    
039                    Settings configurationBeanSettings =
040                            _settingsLocatorHelper.getConfigurationBeanSettings(
041                                    _settingsId, portalPropertiesSettings);
042    
043                    Settings portalPreferencesSettings =
044                            _settingsLocatorHelper.getPortalPreferencesSettings(
045                                    companyId, configurationBeanSettings);
046    
047                    Settings companyPortletPreferencesSettings =
048                            _settingsLocatorHelper.getCompanyPortletPreferencesSettings(
049                                    companyId, _settingsId, portalPreferencesSettings);
050    
051                    return _settingsLocatorHelper.getGroupPortletPreferencesSettings(
052                            _groupId, _settingsId, companyPortletPreferencesSettings);
053            }
054    
055            @Override
056            public String getSettingsId() {
057                    return _settingsId;
058            }
059    
060            protected long getCompanyId(long groupId) throws SettingsException {
061                    try {
062                            Group group = GroupLocalServiceUtil.getGroup(groupId);
063    
064                            return group.getCompanyId();
065                    }
066                    catch (PortalException pe) {
067                            throw new SettingsException(pe);
068                    }
069            }
070    
071            private final long _groupId;
072            private final String _settingsId;
073            private final SettingsLocatorHelper _settingsLocatorHelper =
074                    SettingsLocatorHelperUtil.getSettingsLocatorHelper();
075    
076    }