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.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            @Override
039            public void addBookItems(long groupId, long categoryId, String[] isbns)
040                    throws PortalException, SystemException {
041    
042                    ShoppingCategoryPermission.check(
043                            getPermissionChecker(), groupId, categoryId, ActionKeys.ADD_ITEM);
044    
045                    shoppingItemLocalService.addBookItems(
046                            getUserId(), groupId, categoryId, isbns);
047            }
048    
049            @Override
050            public ShoppingItem addItem(
051                            long groupId, long categoryId, String sku, String name,
052                            String description, String properties, String fieldsQuantities,
053                            boolean requiresShipping, int stockQuantity, boolean featured,
054                            Boolean sale, boolean smallImage, String smallImageURL,
055                            File smallFile, boolean mediumImage, String mediumImageURL,
056                            File mediumFile, boolean largeImage, String largeImageURL,
057                            File largeFile, List<ShoppingItemField> itemFields,
058                            List<ShoppingItemPrice> itemPrices, ServiceContext serviceContext)
059                    throws PortalException, SystemException {
060    
061                    ShoppingCategoryPermission.check(
062                            getPermissionChecker(), groupId, categoryId, ActionKeys.ADD_ITEM);
063    
064                    return shoppingItemLocalService.addItem(
065                            getUserId(), groupId, categoryId, sku, name, description,
066                            properties, fieldsQuantities, requiresShipping, stockQuantity,
067                            featured, sale, smallImage, smallImageURL, smallFile, mediumImage,
068                            mediumImageURL, mediumFile, largeImage, largeImageURL, largeFile,
069                            itemFields, itemPrices, serviceContext);
070            }
071    
072            @Override
073            public void deleteItem(long itemId)
074                    throws PortalException, SystemException {
075    
076                    ShoppingItemPermission.check(
077                            getPermissionChecker(), itemId, ActionKeys.DELETE);
078    
079                    shoppingItemLocalService.deleteItem(itemId);
080            }
081    
082            @Override
083            public int getCategoriesItemsCount(long groupId, List<Long> categoryIds)
084                    throws SystemException {
085    
086                    return shoppingItemFinder.filterCountByG_C(groupId, categoryIds);
087            }
088    
089            @Override
090            public ShoppingItem getItem(long itemId)
091                    throws PortalException, SystemException {
092    
093                    ShoppingItemPermission.check(
094                            getPermissionChecker(), itemId, ActionKeys.VIEW);
095    
096                    return shoppingItemLocalService.getItem(itemId);
097            }
098    
099            @Override
100            public List<ShoppingItem> getItems(long groupId, long categoryId)
101                    throws SystemException {
102    
103                    return shoppingItemPersistence.filterFindByG_C(groupId, categoryId);
104            }
105    
106            @Override
107            public List<ShoppingItem> getItems(
108                            long groupId, long categoryId, int start, int end,
109                            OrderByComparator obc)
110                    throws SystemException {
111    
112                    return shoppingItemPersistence.filterFindByG_C(
113                            groupId, categoryId, start, end, obc);
114            }
115    
116            @Override
117            public int getItemsCount(long groupId, long categoryId)
118                    throws SystemException {
119    
120                    return shoppingItemPersistence.filterCountByG_C(groupId, categoryId);
121            }
122    
123            @Override
124            public ShoppingItem[] getItemsPrevAndNext(
125                            long itemId, OrderByComparator obc)
126                    throws PortalException, SystemException {
127    
128                    ShoppingItem item = shoppingItemPersistence.findByPrimaryKey(itemId);
129    
130                    return shoppingItemPersistence.filterFindByG_C_PrevAndNext(
131                            item.getItemId(), item.getGroupId(), item.getCategoryId(), obc);
132            }
133    
134            @Override
135            public ShoppingItem updateItem(
136                            long itemId, long groupId, long categoryId, String sku, String name,
137                            String description, String properties, String fieldsQuantities,
138                            boolean requiresShipping, int stockQuantity, boolean featured,
139                            Boolean sale, boolean smallImage, String smallImageURL,
140                            File smallFile, boolean mediumImage, String mediumImageURL,
141                            File mediumFile, boolean largeImage, String largeImageURL,
142                            File largeFile, List<ShoppingItemField> itemFields,
143                            List<ShoppingItemPrice> itemPrices, ServiceContext serviceContext)
144                    throws PortalException, SystemException {
145    
146                    ShoppingItemPermission.check(
147                            getPermissionChecker(), itemId, ActionKeys.UPDATE);
148    
149                    return shoppingItemLocalService.updateItem(
150                            getUserId(), itemId, groupId, categoryId, sku, name, description,
151                            properties, fieldsQuantities, requiresShipping, stockQuantity,
152                            featured, sale, smallImage, smallImageURL, smallFile, mediumImage,
153                            mediumImageURL, mediumFile, largeImage, largeImageURL, largeFile,
154                            itemFields, itemPrices, serviceContext);
155            }
156    
157    }