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.shopping.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.security.permission.ActionKeys;
019    import com.liferay.portal.service.ServiceContext;
020    import com.liferay.portlet.shopping.model.ShoppingCoupon;
021    import com.liferay.portlet.shopping.service.base.ShoppingCouponServiceBaseImpl;
022    import com.liferay.portlet.shopping.service.permission.ShoppingPermission;
023    
024    import java.util.List;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class ShoppingCouponServiceImpl extends ShoppingCouponServiceBaseImpl {
030    
031            @Override
032            public ShoppingCoupon addCoupon(
033                            String code, boolean autoCode, String name, String description,
034                            int startDateMonth, int startDateDay, int startDateYear,
035                            int startDateHour, int startDateMinute, int endDateMonth,
036                            int endDateDay, int endDateYear, int endDateHour, int endDateMinute,
037                            boolean neverExpire, boolean active, String limitCategories,
038                            String limitSkus, double minOrder, double discount,
039                            String discountType, ServiceContext serviceContext)
040                    throws PortalException {
041    
042                    ShoppingPermission.check(
043                            getPermissionChecker(), serviceContext.getScopeGroupId(),
044                            ActionKeys.MANAGE_COUPONS);
045    
046                    return shoppingCouponLocalService.addCoupon(
047                            getUserId(), code, autoCode, name, description, startDateMonth,
048                            startDateDay, startDateYear, startDateHour, startDateMinute,
049                            endDateMonth, endDateDay, endDateYear, endDateHour, endDateMinute,
050                            neverExpire, active, limitCategories, limitSkus, minOrder, discount,
051                            discountType, serviceContext);
052            }
053    
054            @Override
055            public void deleteCoupon(long groupId, long couponId)
056                    throws PortalException {
057    
058                    ShoppingPermission.check(
059                            getPermissionChecker(), groupId, ActionKeys.MANAGE_COUPONS);
060    
061                    shoppingCouponLocalService.deleteCoupon(couponId);
062            }
063    
064            @Override
065            public ShoppingCoupon getCoupon(long groupId, long couponId)
066                    throws PortalException {
067    
068                    ShoppingPermission.check(
069                            getPermissionChecker(), groupId, ActionKeys.MANAGE_COUPONS);
070    
071                    return shoppingCouponLocalService.getCoupon(couponId);
072            }
073    
074            @Override
075            public List<ShoppingCoupon> search(
076                            long groupId, long companyId, String code, boolean active,
077                            String discountType, boolean andOperator, int start, int end)
078                    throws PortalException {
079    
080                    ShoppingPermission.check(
081                            getPermissionChecker(), groupId, ActionKeys.MANAGE_COUPONS);
082    
083                    return shoppingCouponLocalService.search(
084                            groupId, companyId, code, active, discountType, andOperator, start,
085                            end);
086            }
087    
088            @Override
089            public ShoppingCoupon updateCoupon(
090                            long couponId, String name, String description, int startDateMonth,
091                            int startDateDay, int startDateYear, int startDateHour,
092                            int startDateMinute, int endDateMonth, int endDateDay,
093                            int endDateYear, int endDateHour, int endDateMinute,
094                            boolean neverExpire, boolean active, String limitCategories,
095                            String limitSkus, double minOrder, double discount,
096                            String discountType, ServiceContext serviceContext)
097                    throws PortalException {
098    
099                    ShoppingPermission.check(
100                            getPermissionChecker(), serviceContext.getScopeGroupId(),
101                            ActionKeys.MANAGE_COUPONS);
102    
103                    return shoppingCouponLocalService.updateCoupon(
104                            getUserId(), couponId, name, description, startDateMonth,
105                            startDateDay, startDateYear, startDateHour, startDateMinute,
106                            endDateMonth, endDateDay, endDateYear, endDateHour, endDateMinute,
107                            neverExpire, active, limitCategories, limitSkus, minOrder, discount,
108                            discountType, serviceContext);
109            }
110    
111    }