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.kernel.model.Group;
019    import com.liferay.portal.kernel.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                    _configurationPid = settingsId;
032            }
033    
034            public GroupServiceSettingsLocator(
035                    long groupId, String settingsId, String configurationPid) {
036    
037                    _groupId = groupId;
038                    _settingsId = settingsId;
039                    _configurationPid = configurationPid;
040            }
041    
042            @Override
043            public Settings getSettings() throws SettingsException {
044                    long companyId = getCompanyId(_groupId);
045    
046                    Settings portalPropertiesSettings =
047                            _settingsLocatorHelper.getPortalPropertiesSettings();
048    
049                    Settings configurationBeanSettings =
050                            _settingsLocatorHelper.getConfigurationBeanSettings(
051                                    _configurationPid, portalPropertiesSettings);
052    
053                    Settings portalPreferencesSettings =
054                            _settingsLocatorHelper.getPortalPreferencesSettings(
055                                    companyId, configurationBeanSettings);
056    
057                    Settings companyPortletPreferencesSettings =
058                            _settingsLocatorHelper.getCompanyPortletPreferencesSettings(
059                                    companyId, _settingsId, portalPreferencesSettings);
060    
061                    return _settingsLocatorHelper.getGroupPortletPreferencesSettings(
062                            _groupId, _settingsId, companyPortletPreferencesSettings);
063            }
064    
065            @Override
066            public String getSettingsId() {
067                    return _settingsId;
068            }
069    
070            protected long getCompanyId(long groupId) throws SettingsException {
071                    try {
072                            Group group = GroupLocalServiceUtil.getGroup(groupId);
073    
074                            return group.getCompanyId();
075                    }
076                    catch (PortalException pe) {
077                            throw new SettingsException(pe);
078                    }
079            }
080    
081            private final String _configurationPid;
082            private final long _groupId;
083            private final String _settingsId;
084            private final SettingsLocatorHelper _settingsLocatorHelper =
085                    SettingsLocatorHelperUtil.getSettingsLocatorHelper();
086    
087    }