001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.social.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.Group;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.portlet.social.model.SocialEquityGroupSetting;
022    import com.liferay.portlet.social.model.SocialEquitySettingConstants;
023    import com.liferay.portlet.social.service.base.SocialEquityGroupSettingLocalServiceBaseImpl;
024    
025    /**
026     * @author Zsolt Berentey
027     */
028    public class SocialEquityGroupSettingLocalServiceImpl
029            extends SocialEquityGroupSettingLocalServiceBaseImpl {
030    
031            public boolean isEnabled(long groupId, String className)
032                    throws SystemException {
033    
034                    if (isEnabled(
035                                    groupId, className,
036                                    SocialEquitySettingConstants.TYPE_INFORMATION) &&
037                            isEnabled(
038                                    groupId, className,
039                                    SocialEquitySettingConstants.TYPE_PARTICIPATION)) {
040    
041                            return true;
042                    }
043                    else {
044                            return false;
045                    }
046            }
047    
048            public boolean isEnabled(long groupId, String className, int type)
049                    throws SystemException {
050    
051                    long classNameId = PortalUtil.getClassNameId(className);
052    
053                    SocialEquityGroupSetting equityGroupSetting =
054                            socialEquityGroupSettingPersistence.fetchByG_C_T(
055                                    groupId, classNameId, type);
056    
057                    if (equityGroupSetting != null) {
058                            return equityGroupSetting.isEnabled();
059                    }
060    
061                    if (className.equals(Group.class.getName())) {
062                            return false;
063                    }
064    
065                    return true;
066            }
067    
068            public void updateEquityGroupSetting(
069                            long groupId, String className, int type, boolean enabled)
070                    throws PortalException, SystemException {
071    
072                    long classNameId = PortalUtil.getClassNameId(className);
073    
074                    SocialEquityGroupSetting equityGroupSetting =
075                            socialEquityGroupSettingPersistence.fetchByG_C_T(
076                                    groupId, classNameId, type);
077    
078                    if (equityGroupSetting == null) {
079                            Group group = groupLocalService.getGroup(groupId);
080    
081                            long equityGroupSettingId = counterLocalService.increment();
082    
083                            equityGroupSetting = socialEquityGroupSettingPersistence.create(
084                                    equityGroupSettingId);
085    
086                            equityGroupSetting.setGroupId(groupId);
087                            equityGroupSetting.setCompanyId(group.getCompanyId());
088                            equityGroupSetting.setClassNameId(classNameId);
089                            equityGroupSetting.setType(type);
090                    }
091    
092                    equityGroupSetting.setEnabled(enabled);
093    
094                    socialEquityGroupSettingPersistence.update(equityGroupSetting, false);
095            }
096    
097    }