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.provider;
35  
36  import fr.paris.lutece.plugins.stock.business.StockEntityBean;
37  import fr.paris.lutece.plugins.stock.business.attribute.provider.ProviderAttribute;
38  import fr.paris.lutece.plugins.stock.business.attribute.provider.ProviderAttributeDate;
39  import fr.paris.lutece.plugins.stock.business.attribute.provider.ProviderAttributeNum;
40  import fr.paris.lutece.plugins.stock.business.category.Category;
41  import fr.paris.lutece.plugins.stock.utils.jpa.StockJPAUtils;
42  
43  import java.util.HashSet;
44  import java.util.List;
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.OneToMany;
55  import javax.persistence.Table;
56  import javax.persistence.TableGenerator;
57  
58  /**
59   *
60   * Provider
61   *
62   */
63  @Entity
64  // @Inheritance( strategy = InheritanceType.JOINED )
65  @Table( name = "stock_provider" )
66  public class Provider extends StockEntityBean<Provider>
67  {
68      /**
69       * SUID
70       */
71      private static final long serialVersionUID = 4296244688535088812L;
72  
73      /** Sequence name */
74      private static final String JPA_SEQUENCE_NAME = "stock_provider_sequence";
75  
76      /** Unique value */
77      private static final String JPA_COLUNM_NAME = "stock_provider_id";
78      private Integer _id;
79      private String _strName;
80      private String _strAddress;
81      private String _strContactName;
82      private String _strPhoneNumber;
83      private String _strMail;
84      private String _strComment;
85      private List<Category> _listProducts;
86      private Set<ProviderAttribute> _attributeList;
87      private Set<ProviderAttributeDate> _attributeDateList;
88      private Set<ProviderAttributeNum> _attributeNumList;
89  
90      /**
91       * Constructor
92       */
93      public Provider( )
94      {
95          this._attributeDateList = new HashSet<>( );
96          this._attributeList = new HashSet<>( );
97          this._attributeNumList = new HashSet<>( );
98      }
99  
100     /**
101      * Construct a new provider from an other
102      * 
103      * @param provider
104      *            a provider object to copy
105      */
106     public Provider href="../../../../../../../fr/paris/lutece/plugins/stock/business/provider/Provider.html#Provider">Provider( Provider provider )
107     {
108         this._attributeDateList = new HashSet<>( );
109         this._attributeList = new HashSet<>( );
110         this._attributeNumList = new HashSet<>( );
111         copy( provider );
112     }
113 
114     /**
115      * Copy values from a provider object to this
116      * 
117      * @param provider
118      *            a provider object
119      */
120     private void copy( Provider provider )
121     {
122         setId( provider.getId( ) );
123         setName( provider.getName( ) );
124         setAddress( provider.getAddress( ) );
125         setContactName( provider.getContactName( ) );
126         setPhoneNumber( provider.getPhoneNumber( ) );
127         setMail( provider.getMail( ) );
128         setComment( provider.getComment( ) );
129         setProducts( provider.getProducts( ) );
130     }
131 
132     /**
133      * Return the provider id
134      * 
135      * @return the provider id
136      */
137     @TableGenerator( table = StockJPAUtils.SEQUENCE_TABLE_NAME, name = JPA_SEQUENCE_NAME, pkColumnValue = JPA_COLUNM_NAME, allocationSize = 1 )
138     @Id
139     @GeneratedValue( strategy = GenerationType.TABLE, generator = JPA_SEQUENCE_NAME )
140     @Column( name = "id_provider" )
141     public Integer getId( )
142     {
143         return _id;
144     }
145 
146     /**
147      * Set the provider id
148      * 
149      * @param idProvider
150      *            the provider id
151      */
152     public void setId( Integer idProvider )
153     {
154         _id = idProvider;
155     }
156 
157     /**
158      * Get the phone number to contact the provider
159      * 
160      * @return the phone number
161      */
162     @Column( name = "phone_number" )
163     public String getPhoneNumber( )
164     {
165         return _strPhoneNumber;
166     }
167 
168     /**
169      * Set the phone number
170      * 
171      * @param strPhoneNumber
172      *            the phone number
173      */
174     public void setPhoneNumber( String strPhoneNumber )
175     {
176         _strPhoneNumber = strPhoneNumber;
177     }
178 
179     /**
180      * Get the provider address
181      * 
182      * @return the provider address
183      */
184     @Column( name = "address" )
185     public String getAddress( )
186     {
187         return _strAddress;
188     }
189 
190     /**
191      * Set the provider address
192      * 
193      * @param address
194      *            address
195      */
196     public void setAddress( String address )
197     {
198         _strAddress = address;
199     }
200 
201     /**
202      * Get the provider mail
203      * 
204      * @return the mail
205      */
206     @Column( name = "mail" )
207     public String getMail( )
208     {
209         return _strMail;
210     }
211 
212     /**
213      * Set the provider mail
214      * 
215      * @param mail
216      *            the mail
217      */
218     public void setMail( String mail )
219     {
220         _strMail = mail;
221     }
222 
223     /**
224      * Get the provider name
225      * 
226      * @return the provider name
227      */
228     @Column( name = "name" )
229     public String getName( )
230     {
231         return this._strName;
232     }
233 
234     /**
235      * Set the provider name
236      * 
237      * @param name
238      *            the provider name
239      */
240     public void setName( String name )
241     {
242         this._strName = name;
243     }
244 
245     /**
246      * Get the product list
247      * 
248      * @return the product list
249      */
250     @OneToMany( cascade = CascadeType.ALL, fetch = FetchType.LAZY )
251     public List<Category> getProducts( )
252     {
253         return _listProducts;
254     }
255 
256     /**
257      * Set the product list
258      * 
259      * @param products
260      *            the product list
261      */
262     public void setProducts( List<Category> products )
263     {
264         _listProducts = products;
265     }
266 
267     /**
268      * Get the contact name
269      * 
270      * @return the contact name
271      */
272     public String getContactName( )
273     {
274         return _strContactName;
275     }
276 
277     /**
278      * Set the contact name
279      * 
280      * @param contactName
281      *            the name of the contact
282      */
283     public void setContactName( String contactName )
284     {
285         this._strContactName = contactName;
286     }
287 
288     /**
289      * Get the comment
290      * 
291      * @return the comment
292      */
293     public String getComment( )
294     {
295         return _strComment;
296     }
297 
298     /**
299      * Set the comment
300      * 
301      * @param comment
302      *            the comment
303      */
304     public void setComment( String comment )
305     {
306         this._strComment = comment;
307     }
308 
309     /**
310      * Returns dynamic attributes list
311      * 
312      * @return dynamic attributes list
313      */
314     @OneToMany( cascade = {
315             CascadeType.ALL
316     }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
317     public Set<ProviderAttribute> getAttributeList( )
318     {
319         return _attributeList;
320     }
321 
322     public void setAttributeList( Set<ProviderAttribute> stringAttribute )
323     {
324         this._attributeList = stringAttribute;
325     }
326 
327     /**
328      * Returns dynamic attributes list
329      * 
330      * @return dynamic attributes list
331      */
332     @OneToMany( cascade = {
333             CascadeType.ALL
334     }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
335     public Set<ProviderAttributeDate> getAttributeDateList( )
336     {
337         return _attributeDateList;
338     }
339 
340     /**
341      * Sets the attribute date list.
342      * 
343      * @param dateAttribute
344      *            the new attribute date list
345      */
346     public void setAttributeDateList( Set<ProviderAttributeDate> dateAttribute )
347     {
348         this._attributeDateList = dateAttribute;
349     }
350 
351     /**
352      * Returns dynamic attributes list
353      * 
354      * @return dynamic attributes list
355      */
356     @OneToMany( cascade = {
357             CascadeType.ALL
358     }, mappedBy = "owner", orphanRemoval = true, fetch = FetchType.EAGER )
359     public Set<ProviderAttributeNum> getAttributeNumList( )
360     {
361         return _attributeNumList;
362     }
363 
364     /**
365      * Set attribute list
366      * 
367      * @param numAttribute
368      *            numAttribute
369      */
370     public void setAttributeNumList( Set<ProviderAttributeNum> numAttribute )
371     {
372         this._attributeNumList = numAttribute;
373     }
374 
375 }