View Javadoc
1   /*
2    * Copyright (c) 2002-2020, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.stock.business.product;
35  
36  import fr.paris.lutece.plugins.stock.business.StockEntityBean;
37  import fr.paris.lutece.plugins.stock.business.attribute.product.ProductAttribute;
38  import fr.paris.lutece.plugins.stock.business.attribute.product.ProductAttributeDate;
39  import fr.paris.lutece.plugins.stock.business.attribute.product.ProductAttributeNum;
40  import fr.paris.lutece.plugins.stock.business.category.Category;
41  import fr.paris.lutece.plugins.stock.business.provider.Provider;
42  import fr.paris.lutece.plugins.stock.utils.jpa.StockJPAUtils;
43  
44  import java.util.HashSet;
45  import java.util.Set;
46  
47  import javax.persistence.CascadeType;
48  import javax.persistence.Column;
49  import javax.persistence.Entity;
50  import javax.persistence.FetchType;
51  import javax.persistence.GeneratedValue;
52  import javax.persistence.GenerationType;
53  import javax.persistence.Id;
54  import javax.persistence.Inheritance;
55  import javax.persistence.InheritanceType;
56  import javax.persistence.JoinColumn;
57  import javax.persistence.ManyToOne;
58  import javax.persistence.OneToMany;
59  import javax.persistence.Table;
60  import javax.persistence.TableGenerator;
61  
62  /**
63   * Product.
64   */
65  @Entity
66  @Inheritance( strategy = InheritanceType.JOINED )
67  @Table( name = "stock_product" )
68  public class Product extends StockEntityBean<Product>
69  {
70  
71      /**  
72       *
73       */
74      private static final long serialVersionUID = -2357849090898194150L;
75  
76      /** Sequence name. */
77      private static final String JPA_SEQUENCE_NAME = "stock_product_sequence";
78  
79      /** Unique value. */
80      private static final String JPA_COLUMN_NAME = "stock_product_id";
81  
82      /** The _id product. */
83      private Integer _idProduct;
84  
85      /** The _str description. */
86      private String _strDescription;
87  
88      /** The _str name. */
89      private String _strName;
90  
91      /** The _price. */
92      private Float _price;
93  
94      /** The _category. */
95      private Category _category;
96  
97      /** The _provider. */
98      private Provider _provider;
99  
100     /** The _attribute date list. */
101     private Set<ProductAttributeDate> _attributeDateList;
102 
103     /** The _attribute num list. */
104     private Set<ProductAttributeNum> _attributeNumList;
105 
106     /** The _attribute list. */
107     private Set<ProductAttribute> _attributeList;
108 
109     /**
110      * Constructor.
111      */
112     public Product( )
113     {
114         super( );
115         this._attributeDateList = new HashSet<>( );
116         this._attributeList = new HashSet<>( );
117         this._attributeNumList = new HashSet<>( );
118         this._provider = new Provider( );
119         this._category = new Category( );
120     }
121 
122     /**
123      * Constructor from an other product object.
124      * 
125      * @param product
126      *            the product
127      */
128     public Product" href="../../../../../../../fr/paris/lutece/plugins/stock/business/product/Product.html#Product">Product( Product product )
129     {
130         _strName = product.getName( );
131         _strDescription = product.getDescription( );
132         _price = product.getPrice( );
133         _category = product.getCategory( );
134         _idProduct = product.getId( );
135     }
136 
137     /**
138      * Return the product id.
139      * 
140      * @return the product id
141      */
142     @TableGenerator( table = StockJPAUtils.SEQUENCE_TABLE_NAME, name = JPA_SEQUENCE_NAME, pkColumnValue = JPA_COLUMN_NAME, allocationSize = 1 )
143     @Id
144     @GeneratedValue( strategy = GenerationType.TABLE, generator = JPA_SEQUENCE_NAME )
145     @Column( name = "id_product" )
146     public Integer getId( )
147     {
148         return _idProduct;
149     }
150 
151     /**
152      * Set the product id.
153      * 
154      * @param idProduct
155      *            the product id
156      */
157     public void setId( Integer idProduct )
158     {
159         _idProduct = idProduct;
160     }
161 
162     /**
163      * Return the product description.
164      * 
165      * @return the description
166      */
167     @Column( name = "description" )
168     public String getDescription( )
169     {
170         return _strDescription;
171     }
172 
173     /**
174      * Set the product description.
175      * 
176      * @param description
177      *            the product description
178      */
179     public void setDescription( String description )
180     {
181         _strDescription = description;
182     }
183 
184     /**
185      * Return the product name.
186      * 
187      * @return the name
188      */
189     @Column( name = "name" )
190     public String getName( )
191     {
192         return _strName;
193     }
194 
195     /**
196      * Set the product name.
197      * 
198      * @param name
199      *            the product name
200      */
201     public void setName( String name )
202     {
203         _strName = name;
204     }
205 
206     /**
207      * Return the price.
208      * 
209      * @return the price
210      */
211     @Column( name = "price" )
212     public Float getPrice( )
213     {
214         return _price;
215     }
216 
217     /**
218      * Set the price.
219      * 
220      * @param price
221      *            the price
222      */
223     public void setPrice( Float price )
224     {
225         _price = price;
226     }
227 
228     /**
229      * Get the category linked to the product.
230      * 
231      * @return the category
232      */
233     @ManyToOne( fetch = FetchType.LAZY )
234     @JoinColumn( name = "category_id_category", nullable = true )
235     public Category getCategory( )
236     {
237         return _category;
238     }
239 
240     /**
241      * Set the category linked to the product.
242      * 
243      * @param category
244      *            the category
245      */
246     public void setCategory( Category category )
247     {
248         _category = category;
249     }
250 
251     /**
252      * Get the provider linked to the product.
253      * 
254      * @return the provider
255      */
256     @ManyToOne( fetch = FetchType.LAZY )
257     @JoinColumn( name = "provider_id_provider", nullable = true )
258     public Provider getProvider( )
259     {
260         return _provider;
261     }
262 
263     /**
264      * Set the provider linked to the product.
265      * 
266      * @param provider
267      *            the provider
268      */
269     public void setProvider( Provider provider )
270     {
271         _provider = provider;
272     }
273 
274     /**
275      * Get the product list.
276      * 
277      * @return the product list
278      */
279     @OneToMany( cascade = {
280             CascadeType.ALL
281     }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
282     public Set<ProductAttribute> getAttributeList( )
283     {
284         return _attributeList;
285     }
286 
287     /**
288      * Sets the attribute list.
289      * 
290      * @param stringAttribute
291      *            the new attribute list
292      */
293     public void setAttributeList( Set<ProductAttribute> stringAttribute )
294     {
295         this._attributeList = stringAttribute;
296     }
297 
298     /**
299      * Returns dynamic attributes list.
300      * 
301      * @return dynamic attributes list
302      */
303     @OneToMany( cascade = {
304             CascadeType.ALL
305     }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
306     public Set<ProductAttributeDate> getAttributeDateList( )
307     {
308         return _attributeDateList;
309     }
310 
311     /**
312      * Sets the attribute date list.
313      * 
314      * @param dateAttribute
315      *            the new attribute date list
316      */
317     public void setAttributeDateList( Set<ProductAttributeDate> dateAttribute )
318     {
319         this._attributeDateList = dateAttribute;
320     }
321 
322     /**
323      * Returns dynamic attributes list.
324      * 
325      * @return dynamic attributes list
326      */
327     @OneToMany( cascade = {
328             CascadeType.ALL
329     }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
330     public Set<ProductAttributeNum> getAttributeNumList( )
331     {
332         return _attributeNumList;
333     }
334 
335     /**
336      * Set attribute list.
337      * 
338      * @param numAttribute
339      *            numAttribute
340      */
341     public void setAttributeNumList( Set<ProductAttributeNum> numAttribute )
342     {
343         this._attributeNumList = numAttribute;
344     }
345 
346 }