001    /**
002     * Copyright (c) 2000-2013 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.MDRAction;
023    import com.liferay.portlet.mobiledevicerules.service.base.MDRActionServiceBaseImpl;
024    import com.liferay.portlet.mobiledevicerules.service.permission.MDRRuleGroupInstancePermissionUtil;
025    
026    import java.util.Locale;
027    import java.util.Map;
028    
029    /**
030     * @author Edward C. Han
031     */
032    public class MDRActionServiceImpl extends MDRActionServiceBaseImpl {
033    
034            @Override
035            public MDRAction addAction(
036                            long ruleGroupInstanceId, Map<Locale, String> nameMap,
037                            Map<Locale, String> descriptionMap, String type,
038                            String typeSettings, ServiceContext serviceContext)
039                    throws PortalException, SystemException {
040    
041                    MDRRuleGroupInstancePermissionUtil.check(
042                            getPermissionChecker(), ruleGroupInstanceId, ActionKeys.UPDATE);
043    
044                    return mdrActionLocalService.addAction(
045                            ruleGroupInstanceId, nameMap, descriptionMap, type, typeSettings,
046                            serviceContext);
047            }
048    
049            @Override
050            public MDRAction addAction(
051                            long ruleGroupInstanceId, Map<Locale, String> nameMap,
052                            Map<Locale, String> descriptionMap, String type,
053                            UnicodeProperties typeSettingsProperties,
054                            ServiceContext serviceContext)
055                    throws PortalException, SystemException {
056    
057                    MDRRuleGroupInstancePermissionUtil.check(
058                            getPermissionChecker(), ruleGroupInstanceId, ActionKeys.UPDATE);
059    
060                    return mdrActionLocalService.addAction(
061                            ruleGroupInstanceId, nameMap, descriptionMap, type,
062                            typeSettingsProperties, serviceContext);
063            }
064    
065            @Override
066            public void deleteAction(long actionId)
067                    throws PortalException, SystemException {
068    
069                    MDRAction action = mdrActionPersistence.findByPrimaryKey(actionId);
070    
071                    MDRRuleGroupInstancePermissionUtil.check(
072                            getPermissionChecker(), action.getRuleGroupInstanceId(),
073                            ActionKeys.UPDATE);
074    
075                    mdrActionLocalService.deleteAction(action);
076            }
077    
078            @Override
079            public MDRAction fetchAction(long actionId)
080                    throws PortalException, SystemException {
081    
082                    MDRAction action = mdrActionLocalService.fetchAction(actionId);
083    
084                    if (action != null) {
085                            MDRRuleGroupInstancePermissionUtil.check(
086                                    getPermissionChecker(), action.getRuleGroupInstanceId(),
087                                    ActionKeys.VIEW);
088                    }
089    
090                    return action;
091            }
092    
093            @Override
094            public MDRAction getAction(long actionId)
095                    throws PortalException, SystemException {
096    
097                    MDRAction action = mdrActionPersistence.findByPrimaryKey(actionId);
098    
099                    MDRRuleGroupInstancePermissionUtil.check(
100                            getPermissionChecker(), action.getRuleGroupInstanceId(),
101                            ActionKeys.VIEW);
102    
103                    return action;
104            }
105    
106            @Override
107            public MDRAction updateAction(
108                            long actionId, Map<Locale, String> nameMap,
109                            Map<Locale, String> descriptionMap, String type,
110                            String typeSettings, ServiceContext serviceContext)
111                    throws PortalException, SystemException {
112    
113                    MDRAction action = mdrActionPersistence.findByPrimaryKey(actionId);
114    
115                    MDRRuleGroupInstancePermissionUtil.check(
116                            getPermissionChecker(), action.getRuleGroupInstanceId(),
117                            ActionKeys.UPDATE);
118    
119                    return mdrActionLocalService.updateAction(
120                            actionId, nameMap, descriptionMap, type, typeSettings,
121                            serviceContext);
122            }
123    
124            @Override
125            public MDRAction updateAction(
126                            long actionId, Map<Locale, String> nameMap,
127                            Map<Locale, String> descriptionMap, String type,
128                            UnicodeProperties typeSettingsProperties,
129                            ServiceContext serviceContext)
130                    throws PortalException, SystemException {
131    
132                    MDRAction action = mdrActionPersistence.findByPrimaryKey(actionId);
133    
134                    MDRRuleGroupInstancePermissionUtil.check(
135                            getPermissionChecker(), action.getRuleGroupInstanceId(),
136                            ActionKeys.UPDATE);
137    
138                    return mdrActionLocalService.updateAction(
139                            actionId, nameMap, descriptionMap, type, typeSettingsProperties,
140                            serviceContext);
141            }
142    
143    }