1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.shopping.model.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.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          if (getCategoryId() > 0) {
50              try {
51                  category = ShoppingCategoryLocalServiceUtil.getCategory(
52                      getCategoryId());
53              }
54              catch (Exception e) {
55                  category = new ShoppingCategoryImpl();
56  
57                  _log.error(e);
58              }
59          }
60          else {
61              category = new ShoppingCategoryImpl();
62          }
63  
64          return category;
65      }
66  
67      public String[] getFieldsQuantitiesArray() {
68          return _fieldsQuantitiesArray;
69      }
70  
71      public List<ShoppingItemPrice> getItemPrices()
72          throws PortalException, SystemException {
73  
74          return ShoppingItemPriceLocalServiceUtil.getItemPrices(getItemId());
75      }
76  
77      public void setFieldsQuantities(String fieldsQuantities) {
78          _fieldsQuantitiesArray = StringUtil.split(fieldsQuantities);
79  
80          super.setFieldsQuantities(fieldsQuantities);
81      }
82  
83      public void setFieldsQuantitiesArray(String[] fieldsQuantitiesArray) {
84          _fieldsQuantitiesArray = fieldsQuantitiesArray;
85  
86          super.setFieldsQuantities(StringUtil.merge(fieldsQuantitiesArray));
87      }
88  
89      private static Log _log = LogFactoryUtil.getLog(ShoppingItemImpl.class);
90  
91      private String[] _fieldsQuantitiesArray;
92  
93  }