001
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
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 =
043 PrefsPropsUtil.getString(
044 companyId, "socialInteractionsSocialRelationTypes",
045 StringPool.BLANK);
046 boolean socialInteractionsSocialRelationTypesEnabled =
047 PrefsPropsUtil.getBoolean(
048 companyId, "socialInteractionsSocialRelationTypesEnabled",
049 true);
050
051 return new SocialInteractionsConfiguration(
052 socialInteractionsType, socialInteractionsSitesEnabled,
053 socialInteractionsSocialRelationTypes,
054 socialInteractionsSocialRelationTypesEnabled, null);
055 }
056
057 public static SocialInteractionsConfiguration
058 getSocialInteractionsConfiguration(
059 long companyId, HttpServletRequest request) {
060
061 PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(
062 companyId, true);
063
064 SocialInteractionsType socialInteractionsType =
065 SocialInteractionsType.parse(
066 PrefsParamUtil.getString(
067 portletPreferences, request, "socialInteractionsType",
068 SocialInteractionsType.ALL_USERS.toString()));
069 boolean socialInteractionsSitesEnabled = PrefsParamUtil.getBoolean(
070 portletPreferences, request, "socialInteractionsSitesEnabled",
071 true);
072 String socialInteractionsSocialRelationTypes =
073 portletPreferences.getValue(
074 "socialInteractionsSocialRelationTypes", StringPool.BLANK);
075 boolean socialInteractionsSocialRelationTypesEnabled =
076 PrefsParamUtil.getBoolean(
077 portletPreferences, request,
078 "socialInteractionsSocialRelationTypesEnabled", true);
079
080 return new SocialInteractionsConfiguration(
081 socialInteractionsType, socialInteractionsSitesEnabled,
082 socialInteractionsSocialRelationTypes,
083 socialInteractionsSocialRelationTypesEnabled, null);
084 }
085
086 public static SocialInteractionsConfiguration
087 getSocialInteractionsConfiguration(
088 long companyId, HttpServletRequest request, String serviceName) {
089
090 PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(
091 companyId, true);
092
093 SocialInteractionsType socialInteractionsType =
094 SocialInteractionsType.parse(
095 PrefsParamUtil.getString(
096 portletPreferences, request,
097 "socialInteractionsType" + serviceName,
098 SocialInteractionsType.ALL_USERS.toString()));
099 boolean socialInteractionsSitesEnabled = PrefsParamUtil.getBoolean(
100 portletPreferences, request,
101 "socialInteractionsSitesEnabled" + serviceName, true);
102 String socialInteractionsSocialRelationTypes =
103 portletPreferences.getValue(
104 "socialInteractionsSocialRelationTypes" + serviceName,
105 StringPool.BLANK);
106 boolean socialInteractionsSocialRelationTypesEnabled =
107 PrefsParamUtil.getBoolean(
108 portletPreferences, request,
109 "socialInteractionsSocialRelationTypesEnabled" + serviceName,
110 true);
111
112 SocialInteractionsConfiguration defaultSocialInteractionsConfiguration =
113 SocialInteractionsConfigurationUtil.
114 getSocialInteractionsConfiguration(companyId, request);
115
116 return new SocialInteractionsConfiguration(
117 socialInteractionsType, socialInteractionsSitesEnabled,
118 socialInteractionsSocialRelationTypes,
119 socialInteractionsSocialRelationTypesEnabled,
120 defaultSocialInteractionsConfiguration);
121 }
122
123 public static SocialInteractionsConfiguration
124 getSocialInteractionsConfiguration(long companyId, String serviceName) {
125
126 SocialInteractionsType socialInteractionsType =
127 SocialInteractionsType.parse(
128 PrefsPropsUtil.getString(
129 companyId, "socialInteractionsType" + serviceName,
130 SocialInteractionsType.ALL_USERS.toString()));
131 boolean socialInteractionsSitesEnabled = PrefsPropsUtil.getBoolean(
132 companyId, "socialInteractionsSitesEnabled" + serviceName, true);
133 String socialInteractionsSocialRelationTypes =
134 PrefsPropsUtil.getString(
135 companyId,
136 "socialInteractionsSocialRelationTypes" + serviceName,
137 StringPool.BLANK);
138 boolean socialInteractionsSocialRelationTypesEnabled =
139 PrefsPropsUtil.getBoolean(
140 companyId,
141 "socialInteractionsSocialRelationTypesEnabled" + serviceName,
142 true);
143
144 SocialInteractionsConfiguration defaultSocialInteractionsConfiguration =
145 SocialInteractionsConfigurationUtil.
146 getSocialInteractionsConfiguration(companyId);
147
148 return new SocialInteractionsConfiguration(
149 socialInteractionsType, socialInteractionsSitesEnabled,
150 socialInteractionsSocialRelationTypes,
151 socialInteractionsSocialRelationTypesEnabled,
152 defaultSocialInteractionsConfiguration);
153 }
154
155 public static boolean isInheritSocialInteractionsConfiguration(
156 long companyId, HttpServletRequest request, String serviceName) {
157
158 PortletPreferences portletPreferences = PrefsPropsUtil.getPreferences(
159 companyId, true);
160
161 return PrefsParamUtil.getBoolean(
162 portletPreferences, request,
163 "inheritSocialInteractionsConfiguration" + serviceName, true);
164 }
165
166 }