001    /**
002     * Copyright (c) 2000-2010 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.model.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.log.Log;
020    import com.liferay.portal.kernel.log.LogFactoryUtil;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portlet.shopping.model.ShoppingCategory;
023    import com.liferay.portlet.shopping.model.ShoppingItem;
024    import com.liferay.portlet.shopping.model.ShoppingItemPrice;
025    import com.liferay.portlet.shopping.service.ShoppingCategoryLocalServiceUtil;
026    import com.liferay.portlet.shopping.service.ShoppingItemPriceLocalServiceUtil;
027    import com.liferay.portlet.shopping.util.comparator.ItemNameComparator;
028    
029    import java.util.List;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class ShoppingItemImpl
035            extends ShoppingItemModelImpl implements ShoppingItem {
036    
037            public ShoppingItemImpl() {
038            }
039    
040            public int compareTo(ShoppingItem item) {
041                    return new ItemNameComparator(true).compare(this, item);
042            }
043    
044            public ShoppingCategory getCategory() {
045                    ShoppingCategory category = null;
046    
047                    if (getCategoryId() > 0) {
048                            try {
049                                    category = ShoppingCategoryLocalServiceUtil.getCategory(
050                                            getCategoryId());
051                            }
052                            catch (Exception e) {
053                                    category = new ShoppingCategoryImpl();
054    
055                                    category.setGroupId(getGroupId());
056    
057                                    _log.error(e);
058                            }
059                    }
060                    else {
061                            category = new ShoppingCategoryImpl();
062    
063                            category.setGroupId(getGroupId());
064                    }
065    
066                    return category;
067            }
068    
069            public String[] getFieldsQuantitiesArray() {
070                    return _fieldsQuantitiesArray;
071            }
072    
073            public List<ShoppingItemPrice> getItemPrices()
074                    throws PortalException, SystemException {
075    
076                    return ShoppingItemPriceLocalServiceUtil.getItemPrices(getItemId());
077            }
078    
079            public void setFieldsQuantities(String fieldsQuantities) {
080                    _fieldsQuantitiesArray = StringUtil.split(fieldsQuantities);
081    
082                    super.setFieldsQuantities(fieldsQuantities);
083            }
084    
085            public void setFieldsQuantitiesArray(String[] fieldsQuantitiesArray) {
086                    _fieldsQuantitiesArray = fieldsQuantitiesArray;
087    
088                    super.setFieldsQuantities(StringUtil.merge(fieldsQuantitiesArray));
089            }
090    
091            private static Log _log = LogFactoryUtil.getLog(ShoppingItemImpl.class);
092    
093            private String[] _fieldsQuantitiesArray;
094    
095    }