1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.shopping.model.impl;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.log.Log;
20  import com.liferay.portal.kernel.log.LogFactoryUtil;
21  import com.liferay.portal.kernel.util.StringUtil;
22  import com.liferay.portlet.shopping.model.ShoppingCategory;
23  import com.liferay.portlet.shopping.model.ShoppingItem;
24  import com.liferay.portlet.shopping.model.ShoppingItemPrice;
25  import com.liferay.portlet.shopping.service.ShoppingCategoryLocalServiceUtil;
26  import com.liferay.portlet.shopping.service.ShoppingItemPriceLocalServiceUtil;
27  import com.liferay.portlet.shopping.util.comparator.ItemNameComparator;
28  
29  import java.util.List;
30  
31  /**
32   * <a href="ShoppingItemImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class ShoppingItemImpl
37      extends ShoppingItemModelImpl implements ShoppingItem {
38  
39      public ShoppingItemImpl() {
40      }
41  
42      public int compareTo(ShoppingItem item) {
43          return new ItemNameComparator(true).compare(this, item);
44      }
45  
46      public ShoppingCategory getCategory() {
47          ShoppingCategory category = null;
48  
49          try {
50              category = ShoppingCategoryLocalServiceUtil.getCategory(
51                  getCategoryId());
52          }
53          catch (Exception e) {
54              category = new ShoppingCategoryImpl();
55  
56              _log.error(e);
57          }
58  
59          return category;
60      }
61  
62      public String[] getFieldsQuantitiesArray() {
63          return _fieldsQuantitiesArray;
64      }
65  
66      public List<ShoppingItemPrice> getItemPrices()
67          throws PortalException, SystemException {
68  
69          return ShoppingItemPriceLocalServiceUtil.getItemPrices(getItemId());
70      }
71  
72      public void setFieldsQuantities(String fieldsQuantities) {
73          _fieldsQuantitiesArray = StringUtil.split(fieldsQuantities);
74  
75          super.setFieldsQuantities(fieldsQuantities);
76      }
77  
78      public void setFieldsQuantitiesArray(String[] fieldsQuantitiesArray) {
79          _fieldsQuantitiesArray = fieldsQuantitiesArray;
80  
81          super.setFieldsQuantities(StringUtil.merge(fieldsQuantitiesArray));
82      }
83  
84      private static Log _log = LogFactoryUtil.getLog(ShoppingItemImpl.class);
85  
86      private String[] _fieldsQuantitiesArray;
87  
88  }