001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.shopping.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.OrderByComparator;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.service.ServiceContext;
022    import com.liferay.portlet.shopping.model.ShoppingItem;
023    import com.liferay.portlet.shopping.model.ShoppingItemField;
024    import com.liferay.portlet.shopping.model.ShoppingItemPrice;
025    import com.liferay.portlet.shopping.service.base.ShoppingItemServiceBaseImpl;
026    import com.liferay.portlet.shopping.service.permission.ShoppingCategoryPermission;
027    import com.liferay.portlet.shopping.service.permission.ShoppingItemPermission;
028    
029    import java.io.File;
030    
031    import java.util.List;
032    
033    /**
034     * @author Brian Wing Shun Chan
035     */
036    public class ShoppingItemServiceImpl extends ShoppingItemServiceBaseImpl {
037    
038            public void addBookItems(long groupId, long categoryId, String[] isbns)
039                    throws PortalException, SystemException {
040    
041                    ShoppingCategoryPermission.check(
042                            getPermissionChecker(), groupId, categoryId, ActionKeys.ADD_ITEM);
043    
044                    shoppingItemLocalService.addBookItems(
045                            getUserId(), groupId, categoryId, isbns);
046            }
047    
048            public ShoppingItem addItem(
049                            long groupId, long categoryId, String sku, String name,
050                            String description, String properties, String fieldsQuantities,
051                            boolean requiresShipping, int stockQuantity, boolean featured,
052                            Boolean sale, boolean smallImage, String smallImageURL,
053                            File smallFile, boolean mediumImage, String mediumImageURL,
054                            File mediumFile, boolean largeImage, String largeImageURL,
055                            File largeFile, List<ShoppingItemField> itemFields,
056                            List<ShoppingItemPrice> itemPrices, ServiceContext serviceContext)
057                    throws PortalException, SystemException {
058    
059                    ShoppingCategoryPermission.check(
060                            getPermissionChecker(), groupId, categoryId, ActionKeys.ADD_ITEM);
061    
062                    return shoppingItemLocalService.addItem(
063                            getUserId(), groupId, categoryId, sku, name, description,
064                            properties, fieldsQuantities, requiresShipping, stockQuantity,
065                            featured, sale, smallImage, smallImageURL, smallFile, mediumImage,
066                            mediumImageURL, mediumFile, largeImage, largeImageURL, largeFile,
067                            itemFields, itemPrices, serviceContext);
068            }
069    
070            public void deleteItem(long itemId)
071                    throws PortalException, SystemException {
072    
073                    ShoppingItemPermission.check(
074                            getPermissionChecker(), itemId, ActionKeys.DELETE);
075    
076                    shoppingItemLocalService.deleteItem(itemId);
077            }
078    
079            public int getCategoriesItemsCount(long groupId, List<Long> categoryIds)
080                    throws SystemException {
081    
082                    return shoppingItemFinder.filterCountByG_C(groupId, categoryIds);
083            }
084    
085            public ShoppingItem getItem(long itemId)
086                    throws PortalException, SystemException {
087    
088                    ShoppingItemPermission.check(
089                            getPermissionChecker(), itemId, ActionKeys.VIEW);
090    
091                    return shoppingItemLocalService.getItem(itemId);
092            }
093    
094            public List<ShoppingItem> getItems(long groupId, long categoryId)
095                    throws SystemException {
096    
097                    return shoppingItemPersistence.filterFindByG_C(groupId, categoryId);
098            }
099    
100            public List<ShoppingItem> getItems(
101                            long groupId, long categoryId, int start, int end,
102                            OrderByComparator obc)
103                    throws SystemException {
104    
105                    return shoppingItemPersistence.filterFindByG_C(
106                            groupId, categoryId, start, end, obc);
107            }
108    
109            public int getItemsCount(long groupId, long categoryId)
110                    throws SystemException {
111    
112                    return shoppingItemPersistence.filterCountByG_C(groupId, categoryId);
113            }
114    
115            public ShoppingItem[] getItemsPrevAndNext(
116                            long itemId, OrderByComparator obc)
117                    throws PortalException, SystemException {
118    
119                    ShoppingItem item = shoppingItemPersistence.findByPrimaryKey(itemId);
120    
121                    return shoppingItemPersistence.filterFindByG_C_PrevAndNext(
122                            item.getItemId(), item.getGroupId(), item.getCategoryId(), obc);
123            }
124    
125            public ShoppingItem updateItem(
126                            long itemId, long groupId, long categoryId, String sku, String name,
127                            String description, String properties, String fieldsQuantities,
128                            boolean requiresShipping, int stockQuantity, boolean featured,
129                            Boolean sale, boolean smallImage, String smallImageURL,
130                            File smallFile, boolean mediumImage, String mediumImageURL,
131                            File mediumFile, boolean largeImage, String largeImageURL,
132                            File largeFile, List<ShoppingItemField> itemFields,
133                            List<ShoppingItemPrice> itemPrices, ServiceContext serviceContext)
134                    throws PortalException, SystemException {
135    
136                    ShoppingItemPermission.check(
137                            getPermissionChecker(), itemId, ActionKeys.UPDATE);
138    
139                    return shoppingItemLocalService.updateItem(
140                            getUserId(), itemId, groupId, categoryId, sku, name, description,
141                            properties, fieldsQuantities, requiresShipping, stockQuantity,
142                            featured, sale, smallImage, smallImageURL, smallFile, mediumImage,
143                            mediumImageURL, mediumFile, largeImage, largeImageURL, largeFile,
144                            itemFields, itemPrices, serviceContext);
145            }
146    
147    }