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