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.portal.kernel.util.StringPool;
020    import com.liferay.portlet.social.util.SocialInteractionsConfiguration.SocialInteractionsType;
021    
022    import javax.portlet.PortletPreferences;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Adolfo P??rez
028     * @author Sergio Gonz??lez
029     */
030    public class SocialInteractionsConfigurationUtil {
031    
032            public static SocialInteractionsConfiguration
033                    getSocialInteractionsConfiguration(long companyId) {
034    
035                    SocialInteractionsType socialInteractionsType =
036                            SocialInteractionsType.parse(
037                                    PrefsPropsUtil.getString(
038                                            companyId, "socialInteractionsType",
039                                            SocialInteractionsType.ALL_USERS.toString()));
040                    boolean socialInteractionsSitesEnabled = PrefsPropsUtil.getBoolean(
041                            companyId, "socialInteractionsSitesEnabled", true);
042                    String socialInteractionsSocialRelationTypes = PrefsPropsUtil.getString(
043                            companyId, "socialInteractionsSocialRelationTypes",
044                            StringPool.BLANK);
045                    boolean socialInteractionsSocialRelationTypesEnabled =
046                            PrefsPropsUtil.getBoolean(
047                                    companyId, "socialInteractionsSocialRelationTypesEnabled",
048                                    true);
049    
050                    return new SocialInteractionsConfiguration(
051                            socialInteractionsType, socialInteractionsSitesEnabled,
052                            socialInteractionsSocialRelationTypes,
053                            socialInteractionsSocialRelationTypesEnabled, null);
054            }
055    
056            public static SocialInteractionsConfiguration
057                    getSocialInteractionsConfiguration(
058                            long companyId, HttpServletRequest request) {
059    
060                    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(
061                            companyId, true);
062    
063                    SocialInteractionsType socialInteractionsType =
064                            SocialInteractionsType.parse(
065                                    PrefsParamUtil.getString(
066                                            portletPreferences, request, "socialInteractionsType",
067                                            SocialInteractionsType.ALL_USERS.toString()));
068                    boolean socialInteractionsSitesEnabled = PrefsParamUtil.getBoolean(
069                            portletPreferences, request, "socialInteractionsSitesEnabled",
070                            true);
071                    String socialInteractionsSocialRelationTypes =
072                            portletPreferences.getValue(
073                                    "socialInteractionsSocialRelationTypes", StringPool.BLANK);
074                    boolean socialInteractionsSocialRelationTypesEnabled =
075                            PrefsParamUtil.getBoolean(
076                                    portletPreferences, request,
077                                    "socialInteractionsSocialRelationTypesEnabled", true);
078    
079                    return new SocialInteractionsConfiguration(
080                            socialInteractionsType, socialInteractionsSitesEnabled,
081                            socialInteractionsSocialRelationTypes,
082                            socialInteractionsSocialRelationTypesEnabled, null);
083            }
084    
085            public static SocialInteractionsConfiguration
086                    getSocialInteractionsConfiguration(
087                            long companyId, HttpServletRequest request, String serviceName) {
088    
089                    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(
090                            companyId, true);
091    
092                    SocialInteractionsType socialInteractionsType =
093                            SocialInteractionsType.parse(
094                                    PrefsParamUtil.getString(
095                                            portletPreferences, request,
096                                            "socialInteractionsType" + serviceName,
097                                            SocialInteractionsType.ALL_USERS.toString()));
098                    boolean socialInteractionsSitesEnabled = PrefsParamUtil.getBoolean(
099                            portletPreferences, request,
100                            "socialInteractionsSitesEnabled" + serviceName, true);
101                    String socialInteractionsSocialRelationTypes =
102                            portletPreferences.getValue(
103                                    "socialInteractionsSocialRelationTypes" + serviceName,
104                                    StringPool.BLANK);
105                    boolean socialInteractionsSocialRelationTypesEnabled =
106                            PrefsParamUtil.getBoolean(
107                                    portletPreferences, request,
108                                    "socialInteractionsSocialRelationTypesEnabled" + serviceName,
109                                    true);
110    
111                    SocialInteractionsConfiguration defaultSocialInteractionsConfiguration =
112                            SocialInteractionsConfigurationUtil.
113                                    getSocialInteractionsConfiguration(companyId, request);
114    
115                    return new SocialInteractionsConfiguration(
116                            socialInteractionsType, socialInteractionsSitesEnabled,
117                            socialInteractionsSocialRelationTypes,
118                            socialInteractionsSocialRelationTypesEnabled,
119                            defaultSocialInteractionsConfiguration);
120            }
121    
122            public static SocialInteractionsConfiguration
123                    getSocialInteractionsConfiguration(long companyId, String serviceName) {
124    
125                    SocialInteractionsType socialInteractionsType =
126                            SocialInteractionsType.parse(
127                                    PrefsPropsUtil.getString(
128                                            companyId, "socialInteractionsType" + serviceName,
129                                            SocialInteractionsType.ALL_USERS.toString()));
130                    boolean socialInteractionsSitesEnabled = PrefsPropsUtil.getBoolean(
131                            companyId, "socialInteractionsSitesEnabled" + serviceName, true);
132                    String socialInteractionsSocialRelationTypes = PrefsPropsUtil.getString(
133                            companyId, "socialInteractionsSocialRelationTypes" + serviceName,
134                            StringPool.BLANK);
135                    boolean socialInteractionsSocialRelationTypesEnabled =
136                            PrefsPropsUtil.getBoolean(
137                                    companyId,
138                                    "socialInteractionsSocialRelationTypesEnabled" + serviceName,
139                                    true);
140    
141                    SocialInteractionsConfiguration defaultSocialInteractionsConfiguration =
142                            SocialInteractionsConfigurationUtil.
143                                    getSocialInteractionsConfiguration(companyId);
144    
145                    return new SocialInteractionsConfiguration(
146                            socialInteractionsType, socialInteractionsSitesEnabled,
147                            socialInteractionsSocialRelationTypes,
148                            socialInteractionsSocialRelationTypesEnabled,
149                            defaultSocialInteractionsConfiguration);
150            }
151    
152            public static boolean isInheritSocialInteractionsConfiguration(
153                    long companyId, HttpServletRequest request, String serviceName) {
154    
155                    PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(
156                            companyId, true);
157    
158                    return PrefsParamUtil.getBoolean(
159                            portletPreferences, request,
160                            "inheritSocialInteractionsConfiguration" + serviceName, true);
161            }
162    
163    }