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.kernel.util.UnicodeProperties;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portlet.mobiledevicerules.model.MDRRule;
023    import com.liferay.portlet.mobiledevicerules.service.base.MDRRuleServiceBaseImpl;
024    import com.liferay.portlet.mobiledevicerules.service.permission.MDRRuleGroupPermissionUtil;
025    
026    import java.util.Locale;
027    import java.util.Map;
028    
029    /**
030     * @author Edward C. Han
031     */
032    public class MDRRuleServiceImpl extends MDRRuleServiceBaseImpl {
033    
034            public MDRRule addRule(
035                            long ruleGroupId, Map<Locale, String> nameMap,
036                            Map<Locale, String> descriptionMap, String type,
037                            String typeSettings, ServiceContext serviceContext)
038                    throws PortalException, SystemException {
039    
040                    MDRRuleGroupPermissionUtil.check(
041                            getPermissionChecker(), ruleGroupId, ActionKeys.UPDATE);
042    
043                    return mdrRuleLocalService.addRule(
044                            ruleGroupId, nameMap, descriptionMap, type, typeSettings,
045                            serviceContext);
046            }
047    
048            public MDRRule addRule(
049                            long ruleGroupId, Map<Locale, String> nameMap,
050                            Map<Locale, String> descriptionMap, String type,
051                            UnicodeProperties typeSettings, ServiceContext serviceContext)
052                    throws PortalException, SystemException {
053    
054                    MDRRuleGroupPermissionUtil.check(
055                            getPermissionChecker(), ruleGroupId, ActionKeys.UPDATE);
056    
057                    return mdrRuleLocalService.addRule(
058                            ruleGroupId, nameMap, descriptionMap, type, typeSettings,
059                            serviceContext);
060            }
061    
062            public void deleteRule(long ruleId)
063                    throws PortalException, SystemException {
064    
065                    MDRRule rule = mdrRulePersistence.findByPrimaryKey(ruleId);
066    
067                    MDRRuleGroupPermissionUtil.check(
068                            getPermissionChecker(), rule.getRuleGroupId(), ActionKeys.UPDATE);
069    
070                    mdrRuleLocalService.deleteRule(rule);
071            }
072    
073            public MDRRule fetchRule(long ruleId)
074                    throws PortalException, SystemException {
075    
076                    MDRRule rule = mdrRuleLocalService.fetchRule(ruleId);
077    
078                    if (rule != null) {
079                            MDRRuleGroupPermissionUtil.check(
080                                    getPermissionChecker(), rule.getRuleGroupId(), ActionKeys.VIEW);
081                    }
082    
083                    return rule;
084            }
085    
086            public MDRRule getRule(long ruleId)
087                    throws PortalException, SystemException {
088    
089                    MDRRule rule = mdrRulePersistence.findByPrimaryKey(ruleId);
090    
091                    MDRRuleGroupPermissionUtil.check(
092                            getPermissionChecker(), rule.getRuleGroupId(), ActionKeys.VIEW);
093    
094                    return rule;
095            }
096    
097            public MDRRule updateRule(
098                            long ruleId, Map<Locale, String> nameMap,
099                            Map<Locale, String> descriptionMap, String type,
100                            String typeSettings, ServiceContext serviceContext)
101                    throws PortalException, SystemException {
102    
103                    MDRRule rule = mdrRulePersistence.findByPrimaryKey(ruleId);
104    
105                    MDRRuleGroupPermissionUtil.check(
106                            getPermissionChecker(), rule.getRuleGroupId(), ActionKeys.UPDATE);
107    
108                    return mdrRuleLocalService.updateRule(
109                            ruleId, nameMap, descriptionMap, type, typeSettings,
110                            serviceContext);
111            }
112    
113            public MDRRule updateRule(
114                            long ruleId, Map<Locale, String> nameMap,
115                            Map<Locale, String> descriptionMap, String type,
116                            UnicodeProperties typeSettingsProperties,
117                            ServiceContext serviceContext)
118                    throws PortalException, SystemException {
119    
120                    MDRRule rule = mdrRulePersistence.findByPrimaryKey(ruleId);
121    
122                    MDRRuleGroupPermissionUtil.check(
123                            getPermissionChecker(), rule.getRuleGroupId(), ActionKeys.UPDATE);
124    
125                    return mdrRuleLocalService.updateRule(
126                            ruleId, nameMap, descriptionMap, type, typeSettingsProperties,
127                            serviceContext);
128            }
129    
130    }