001    /**
002     * Copyright (c) 2000-2012 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.kernel.exception.SystemException;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.security.permission.PermissionChecker;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup;
023    import com.liferay.portlet.mobiledevicerules.service.base.MDRRuleGroupServiceBaseImpl;
024    import com.liferay.portlet.mobiledevicerules.service.permission.MDRPermissionUtil;
025    import com.liferay.portlet.mobiledevicerules.service.permission.MDRRuleGroupPermissionUtil;
026    
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            public MDRRuleGroup addRuleGroup(
036                            long groupId, Map<Locale, String> nameMap,
037                            Map<Locale, String> descriptionMap, ServiceContext serviceContext)
038                    throws PortalException, SystemException {
039    
040                    MDRPermissionUtil.check(
041                            getPermissionChecker(), groupId, ActionKeys.ADD_RULE_GROUP);
042    
043                    return mdrRuleGroupLocalService.addRuleGroup(
044                            groupId, nameMap, descriptionMap, serviceContext);
045            }
046    
047            public MDRRuleGroup copyRuleGroup(
048                            long ruleGroupId, long groupId, ServiceContext serviceContext)
049                    throws PortalException, SystemException {
050    
051                    PermissionChecker permissionChecker = getPermissionChecker();
052    
053                    MDRRuleGroup ruleGroup = getRuleGroup(ruleGroupId);
054    
055                    MDRRuleGroupPermissionUtil.check(
056                            permissionChecker, ruleGroup, ActionKeys.VIEW);
057    
058                    MDRPermissionUtil.check(
059                            permissionChecker, groupId, ActionKeys.ADD_RULE_GROUP);
060    
061                    return mdrRuleGroupLocalService.copyRuleGroup(
062                            ruleGroup, groupId, serviceContext);
063            }
064    
065            public void deleteRuleGroup(long ruleGroupId)
066                    throws PortalException, SystemException {
067    
068                    MDRRuleGroup ruleGroup = mdrRuleGroupPersistence.findByPrimaryKey(
069                            ruleGroupId);
070    
071                    MDRRuleGroupPermissionUtil.check(
072                            getPermissionChecker(), ruleGroup, ActionKeys.DELETE);
073    
074                    mdrRuleGroupLocalService.deleteRuleGroup(ruleGroup);
075            }
076    
077            public MDRRuleGroup fetchRuleGroup(long ruleGroupId)
078                    throws PortalException, SystemException {
079    
080                    MDRRuleGroup ruleGroup = mdrRuleGroupPersistence.fetchByPrimaryKey(
081                            ruleGroupId);
082    
083                    if (ruleGroup != null) {
084                            MDRRuleGroupPermissionUtil.check(
085                                    getPermissionChecker(), ruleGroup, ActionKeys.VIEW);
086                    }
087    
088                    return ruleGroup;
089            }
090    
091            public MDRRuleGroup getRuleGroup(long ruleGroupId)
092                    throws PortalException, SystemException {
093    
094                    MDRRuleGroup ruleGroup = mdrRuleGroupPersistence.findByPrimaryKey(
095                            ruleGroupId);
096    
097                    MDRRuleGroupPermissionUtil.check(
098                            getPermissionChecker(), ruleGroup, ActionKeys.VIEW);
099    
100                    return ruleGroup;
101            }
102    
103            public MDRRuleGroup updateRuleGroup(
104                            long ruleGroupId, Map<Locale, String> nameMap,
105                            Map<Locale, String> descriptionMap, ServiceContext serviceContext)
106                    throws PortalException, SystemException {
107    
108                    MDRRuleGroup ruleGroup = mdrRuleGroupPersistence.findByPrimaryKey(
109                            ruleGroupId);
110    
111                    MDRRuleGroupPermissionUtil.check(
112                            getPermissionChecker(), ruleGroup, ActionKeys.UPDATE);
113    
114                    return mdrRuleGroupLocalService.updateRuleGroup(
115                            ruleGroupId, nameMap, descriptionMap, serviceContext);
116            }
117    
118    }