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.GetterUtil;
018    import com.liferay.portal.kernel.util.StringUtil;
019    
020    /**
021     * @author Adolfo P??rez
022     * @author Sergio Gonz??lez
023     */
024    public class SocialInteractionsConfiguration {
025    
026            public SocialInteractionsConfiguration(
027                    SocialInteractionsType socialInteractionsType,
028                    boolean socialInteractionsSitesEnabled,
029                    String socialInteractionsSocialRelationTypes,
030                    boolean socialInteractionsSocialRelationTypesEnabled,
031                    SocialInteractionsConfiguration
032                            defaultSocialInteractionsConfiguration) {
033    
034                    _socialInteractionsType = socialInteractionsType;
035                    _socialInteractionsSitesEnabled = socialInteractionsSitesEnabled;
036                    _socialInteractionsSocialRelationTypes =
037                            socialInteractionsSocialRelationTypes;
038                    _socialInteractionSocialRelationTypesEnabled =
039                            socialInteractionsSocialRelationTypesEnabled;
040                    _defaultSocialInteractionsConfiguration =
041                            defaultSocialInteractionsConfiguration;
042    
043                    _socialInteractionsSocialRelationTypesArray =
044                            GetterUtil.getIntegerValues(
045                                    StringUtil.split(_socialInteractionsSocialRelationTypes));
046            }
047    
048            public String getSocialInteractionsSocialRelationTypes() {
049                    if (isInheritSocialInteractionsConfiguration() &&
050                            (_defaultSocialInteractionsConfiguration != null)) {
051    
052                            return _defaultSocialInteractionsConfiguration.
053                                    getSocialInteractionsSocialRelationTypes();
054                    }
055    
056                    return _socialInteractionsSocialRelationTypes;
057            }
058    
059            public int[] getSocialInteractionsSocialRelationTypesArray() {
060                    if (isInheritSocialInteractionsConfiguration() &&
061                            (_defaultSocialInteractionsConfiguration != null)) {
062    
063                            return _defaultSocialInteractionsConfiguration.
064                                    getSocialInteractionsSocialRelationTypesArray();
065                    }
066    
067                    return _socialInteractionsSocialRelationTypesArray;
068            }
069    
070            public boolean isInheritSocialInteractionsConfiguration() {
071                    if (_socialInteractionsType.equals(SocialInteractionsType.INHERIT)) {
072                            return true;
073                    }
074                    else {
075                            return false;
076                    }
077            }
078    
079            public boolean isSocialInteractionsAnyUserEnabled() {
080                    if (isInheritSocialInteractionsConfiguration() &&
081                            (_defaultSocialInteractionsConfiguration != null)) {
082    
083                            return _defaultSocialInteractionsConfiguration.
084                                    isSocialInteractionsAnyUserEnabled();
085                    }
086    
087                    if (_socialInteractionsType.equals(SocialInteractionsType.ALL_USERS)) {
088                            return true;
089                    }
090                    else {
091                            return false;
092                    }
093            }
094    
095            public boolean isSocialInteractionsSelectUsersEnabled() {
096                    if (isInheritSocialInteractionsConfiguration() &&
097                            (_defaultSocialInteractionsConfiguration != null)) {
098    
099                            return _defaultSocialInteractionsConfiguration.
100                                    isSocialInteractionsSelectUsersEnabled();
101                    }
102    
103                    if (_socialInteractionsType.equals(
104                                    SocialInteractionsType.SELECT_USERS)) {
105    
106                            return true;
107                    }
108                    else {
109                            return false;
110                    }
111            }
112    
113            public boolean isSocialInteractionsSitesEnabled() {
114                    if (isInheritSocialInteractionsConfiguration() &&
115                            (_defaultSocialInteractionsConfiguration != null)) {
116    
117                            return _defaultSocialInteractionsConfiguration.
118                                    isSocialInteractionsSitesEnabled();
119                    }
120    
121                    return _socialInteractionsSitesEnabled;
122            }
123    
124            public boolean isSocialInteractionsSocialRelationTypesEnabled() {
125                    if (isInheritSocialInteractionsConfiguration() &&
126                            (_defaultSocialInteractionsConfiguration != null)) {
127    
128                            return _defaultSocialInteractionsConfiguration.
129                                    isSocialInteractionsSocialRelationTypesEnabled();
130                    }
131    
132                    return _socialInteractionSocialRelationTypesEnabled;
133            }
134    
135            public enum SocialInteractionsType {
136    
137                    ALL_USERS("all_users"), INHERIT("inherit"),
138                    SELECT_USERS("select_users");
139    
140                    public static SocialInteractionsType parse(String value) {
141                            if (ALL_USERS.getValue().equals(value)) {
142                                    return ALL_USERS;
143                            }
144                            else if (INHERIT.getValue().equals(value)) {
145                                    return INHERIT;
146                            }
147                            else if (SELECT_USERS.getValue().equals(value)) {
148                                    return SELECT_USERS;
149                            }
150    
151                            throw new IllegalArgumentException("Invalid value " + value);
152                    }
153    
154                    public String getValue() {
155                            return _value;
156                    }
157    
158                    @Override
159                    public String toString() {
160                            return _value;
161                    }
162    
163                    private SocialInteractionsType(String value) {
164                            _value = value;
165                    }
166    
167                    private final String _value;
168    
169            }
170    
171            private final SocialInteractionsConfiguration
172                    _defaultSocialInteractionsConfiguration;
173            private final boolean _socialInteractionSocialRelationTypesEnabled;
174            private final boolean _socialInteractionsSitesEnabled;
175            private final String _socialInteractionsSocialRelationTypes;
176            private final int[] _socialInteractionsSocialRelationTypesArray;
177            private final SocialInteractionsType _socialInteractionsType;
178    
179    }