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.mobiledevicerules.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.security.permission.ActionKeys;
019    import com.liferay.portal.security.permission.PermissionChecker;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup;
022    import com.liferay.portlet.mobiledevicerules.service.base.MDRRuleGroupServiceBaseImpl;
023    import com.liferay.portlet.mobiledevicerules.service.permission.MDRPermissionUtil;
024    import com.liferay.portlet.mobiledevicerules.service.permission.MDRRuleGroupPermissionUtil;
025    
026    import java.util.List;
027    import java.util.Locale;
028    import java.util.Map;
029    
030    /**
031     * @author Edward C. Han
032     */
033    public class MDRRuleGroupServiceImpl extends MDRRuleGroupServiceBaseImpl {
034    
035            @Override
036            public MDRRuleGroup addRuleGroup(
037                            long groupId, Map<Locale, String> nameMap,
038                            Map<Locale, String> descriptionMap, ServiceContext serviceContext)
039                    throws PortalException {
040    
041                    MDRPermissionUtil.check(
042                            getPermissionChecker(), groupId, ActionKeys.ADD_RULE_GROUP);
043    
044                    return mdrRuleGroupLocalService.addRuleGroup(
045                            groupId, nameMap, descriptionMap, serviceContext);
046            }
047    
048            @Override
049            public MDRRuleGroup copyRuleGroup(
050                            long ruleGroupId, long groupId, ServiceContext serviceContext)
051                    throws PortalException {
052    
053                    PermissionChecker permissionChecker = getPermissionChecker();
054    
055                    MDRRuleGroup ruleGroup = getRuleGroup(ruleGroupId);
056    
057                    MDRRuleGroupPermissionUtil.check(
058                            permissionChecker, ruleGroup, ActionKeys.VIEW);
059    
060                    MDRPermissionUtil.check(
061                            permissionChecker, groupId, ActionKeys.ADD_RULE_GROUP);
062    
063                    return mdrRuleGroupLocalService.copyRuleGroup(
064                            ruleGroup, groupId, serviceContext);
065            }
066    
067            @Override
068            public void deleteRuleGroup(long ruleGroupId) throws PortalException {
069                    MDRRuleGroup ruleGroup = mdrRuleGroupPersistence.findByPrimaryKey(
070                            ruleGroupId);
071    
072                    MDRRuleGroupPermissionUtil.check(
073                            getPermissionChecker(), ruleGroup, ActionKeys.DELETE);
074    
075                    mdrRuleGroupLocalService.deleteRuleGroup(ruleGroup);
076            }
077    
078            @Override
079            public MDRRuleGroup fetchRuleGroup(long ruleGroupId)
080                    throws PortalException {
081    
082                    MDRRuleGroup ruleGroup = mdrRuleGroupPersistence.fetchByPrimaryKey(
083                            ruleGroupId);
084    
085                    if (ruleGroup != null) {
086                            MDRRuleGroupPermissionUtil.check(
087                                    getPermissionChecker(), ruleGroup, ActionKeys.VIEW);
088                    }
089    
090                    return ruleGroup;
091            }
092    
093            @Override
094            public MDRRuleGroup getRuleGroup(long ruleGroupId) throws PortalException {
095                    MDRRuleGroup ruleGroup = mdrRuleGroupPersistence.findByPrimaryKey(
096                            ruleGroupId);
097    
098                    MDRRuleGroupPermissionUtil.check(
099                            getPermissionChecker(), ruleGroup, ActionKeys.VIEW);
100    
101                    return ruleGroup;
102            }
103    
104            @Override
105            public List<MDRRuleGroup> getRuleGroups(
106                    long[] groupIds, int start, int end) {
107    
108                    return mdrRuleGroupPersistence.filterFindByGroupId(
109                            groupIds, start, end);
110            }
111    
112            @Override
113            public int getRuleGroupsCount(long[] groupIds) {
114                    return mdrRuleGroupPersistence.filterCountByGroupId(groupIds);
115            }
116    
117            @Override
118            public MDRRuleGroup updateRuleGroup(
119                            long ruleGroupId, Map<Locale, String> nameMap,
120                            Map<Locale, String> descriptionMap, ServiceContext serviceContext)
121                    throws PortalException {
122    
123                    MDRRuleGroup ruleGroup = mdrRuleGroupPersistence.findByPrimaryKey(
124                            ruleGroupId);
125    
126                    MDRRuleGroupPermissionUtil.check(
127                            getPermissionChecker(), ruleGroup, ActionKeys.UPDATE);
128    
129                    return mdrRuleGroupLocalService.updateRuleGroup(
130                            ruleGroupId, nameMap, descriptionMap, serviceContext);
131            }
132    
133    }