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.portlet.social.util;
016    
017    import com.liferay.portal.kernel.util.PrefsParamUtil;
018    import com.liferay.portal.kernel.util.PrefsPropsUtil;
019    import com.liferay.portlet.social.util.SocialInteractionsConfiguration.SocialInteractionsType;
020    
021    import javax.portlet.PortletPreferences;
022    
023    import javax.servlet.http.HttpServletRequest;
024    
025    /**
026     * @author Adolfo P??rez
027     * @author Sergio Gonz??lez
028     */
029    public class SocialInteractionsConfigurationUtil {
030    
031            public static SocialInteractionsConfiguration
032                    getSocialInteractionsConfiguration(
033                            long companyId, HttpServletRequest request, String serviceName) {
034    
035                    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(
036                            companyId, true);
037    
038                    boolean socialInteractionsFriendsEnabled = PrefsParamUtil.getBoolean(
039                            portletPreferences, request,
040                            "socialInteractionsFriendsEnabled" + serviceName, true);
041                    boolean socialInteractionsSitesEnabled = PrefsParamUtil.getBoolean(
042                            portletPreferences, request,
043                            "socialInteractionsSitesEnabled" + serviceName, true);
044                    SocialInteractionsType socialInteractionsType =
045                            SocialInteractionsType.parse(
046                                    PrefsParamUtil.getString(
047                                            portletPreferences, request,
048                                            "socialInteractionsType" + serviceName,
049                                            SocialInteractionsType.ALL_USERS.toString()));
050    
051                    return new SocialInteractionsConfiguration(
052                            socialInteractionsFriendsEnabled, socialInteractionsSitesEnabled,
053                            socialInteractionsType);
054            }
055    
056            public static SocialInteractionsConfiguration
057                    getSocialInteractionsConfiguration(long companyId, String serviceName) {
058    
059                    boolean socialInteractionsFriendsEnabled = PrefsPropsUtil.getBoolean(
060                            companyId, "socialInteractionsFriendsEnabled" + serviceName, true);
061                    boolean socialInteractionsSitesEnabled = PrefsPropsUtil.getBoolean(
062                            companyId, "socialInteractionsSitesEnabled" + serviceName, true);
063                    SocialInteractionsType socialInteractionsType =
064                            SocialInteractionsType.parse(
065                                    PrefsPropsUtil.getString(
066                                            companyId, "socialInteractionsType" + serviceName,
067                                            SocialInteractionsType.ALL_USERS.toString()));
068    
069                    return new SocialInteractionsConfiguration(
070                            socialInteractionsFriendsEnabled, socialInteractionsSitesEnabled,
071                            socialInteractionsType);
072            }
073    
074    }