]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jproduct/model/product/GenericProduct.java
Continued a bit:
[jproduct-core.git] / src / org / mxchange / jproduct / model / product / GenericProduct.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jproduct.model.product;
18
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import javax.persistence.Transient;
36 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
37 import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
38 import org.mxchange.jproduct.model.category.Category;
39 import org.mxchange.jproduct.model.category.ProductCategory;
40
41 /**
42  * Generic product class
43  * <p>
44  * @author Roland Häder<roland@mxchange.org>
45  * TODO: Find a better name
46  */
47 @Entity (name = "generic_products")
48 @Table (name = "generic_products")
49 @NamedQueries (
50                 {
51                         @NamedQuery (name = "AllProducts", query = "SELECT p FROM generic_products AS p ORDER BY p.productId ASC"),
52                         @NamedQuery (name = "AllAvailableProducts", query = "SELECT p FROM generic_products AS p WHERE p.productAvailability=TRUE ORDER BY p.productId ASC")
53                 }
54 )
55 @SuppressWarnings ("PersistenceUnitPresent")
56 public class GenericProduct implements Product {
57
58         /**
59          * Serial number
60          */
61         @Transient
62         private static final long serialVersionUID = 54_578_571_769_283L;
63
64         /**
65          * Availability of product
66          */
67         @Basic (optional = false)
68         @Column (name = "product_availability", nullable = false)
69         private Boolean productAvailability;
70
71         /**
72          * Product productCategory
73          */
74         @JoinColumn (name = "product_category_id", referencedColumnName = "category_id", nullable = false, updatable = false)
75         @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
76         private Category productCategory;
77
78         /**
79          * When this product has been created
80          */
81         @Basic (optional = false)
82         @Column (name = "product_created", nullable = false, updatable = false)
83         @Temporal (TemporalType.TIMESTAMP)
84         private Date productCreated;
85
86         /**
87          * Currency code for both prices, like EUR or USD
88          */
89         @Basic (optional = false)
90         @Column (name = "product_currency_code", nullable = false, length = 3)
91         private String productCurrencyCode;
92
93         /**
94          * Gross price of product
95          */
96         @Basic (optional = false)
97         @Column (name = "product_gross_price", nullable = false)
98         private Float productGrossPrice;
99
100         /**
101          * I18n key of product
102          */
103         @Basic (optional = false)
104         @Column (name = "product_i18n_key", length = 100, nullable = false, unique = true)
105         private String productI18nKey;
106
107         /**
108          * Id number of product
109          */
110         @Id
111         @GeneratedValue (strategy = GenerationType.IDENTITY)
112         @Column (name = "product_id", nullable = false, updatable = false)
113         private Long productId;
114
115         /**
116          * The company that has manufactured/produced this product
117          */
118         @JoinColumn (name = "product_manufacturer_id", referencedColumnName = "company_data_id")
119         @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH)
120         private BasicData productManfacturer;
121
122         /**
123          * Net price of product
124          */
125         @Column (name = "product_net_price")
126         private Float productNetPrice;
127
128         /**
129          * Tax rate (0-1, by 1=100%)
130          */
131         @Column (name = "product_tax_rate")
132         private Float productTaxRate;
133
134         /**
135          * Amount of this product (for example 1 for 1 liter)
136          */
137         @Column (name = "product_unit_amount")
138         private Float productUnitAmount;
139
140         /**
141          * Unit type (for example liter)
142          */
143         @Column (name = "product_unit_type")
144         private String productUnitType;
145
146         /**
147          * Default constructor
148          */
149         public GenericProduct () {
150         }
151
152         /**
153          * Constructor will all required data
154          * <p>
155          * @param productI18nKey      I18n key of product
156          * @param productGrossPrice   Product's gross price
157          * @param productCurrencyCode code for both prices
158          * @param productCategory     Category instance
159          * @param productAvailability Availability (selectable by customer)
160          */
161         public GenericProduct (final String productI18nKey, final Float productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability) {
162                 // Set all here
163                 this.productI18nKey = productI18nKey;
164                 this.productGrossPrice = productGrossPrice;
165                 this.productCurrencyCode = productCurrencyCode;
166                 this.productCategory = productCategory;
167                 this.productAvailability = productAvailability;
168         }
169
170         @Override
171         public boolean equals (final Object object) {
172                 if (this == object) {
173                         return true;
174                 } else if (null == object) {
175                         return false;
176                 } else if (this.getClass() != object.getClass()) {
177                         return false;
178                 }
179
180                 final Product product = (Product) object;
181
182                 if (!Objects.equals(this.getProductId(), product.getProductId())) {
183                         return false;
184                 } else if (!Objects.equals(this.getProductI18nKey(), product.getProductI18nKey())) {
185                         return false;
186                 }
187
188                 return true;
189         }
190
191         @Override
192         public Boolean getProductAvailability () {
193                 return this.productAvailability;
194         }
195
196         @Override
197         public void setProductAvailability (final Boolean productAvailability) {
198                 this.productAvailability = productAvailability;
199         }
200
201         @Override
202         public Category getProductCategory () {
203                 return this.productCategory;
204         }
205
206         @Override
207         public void setProductCategory (final Category productCategory) {
208                 this.productCategory = productCategory;
209         }
210
211         @Override
212         @SuppressWarnings ("ReturnOfDateField")
213         public Date getProductCreated () {
214                 return this.productCreated;
215         }
216
217         @Override
218         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
219         public void setProductCreated (final Date productCreated) {
220                 this.productCreated = productCreated;
221         }
222
223         @Override
224         public String getProductCurrencyCode () {
225                 return this.productCurrencyCode;
226         }
227
228         @Override
229         public void setProductCurrencyCode (final String productCurrencyCode) {
230                 this.productCurrencyCode = productCurrencyCode;
231         }
232
233         @Override
234         public Float getProductGrossPrice () {
235                 return this.productGrossPrice;
236         }
237
238         @Override
239         public void setProductGrossPrice (final Float productGrossPrice) {
240                 this.productGrossPrice = productGrossPrice;
241         }
242
243         @Override
244         public String getProductI18nKey () {
245                 return this.productI18nKey;
246         }
247
248         @Override
249         public void setProductI18nKey (final String productI18nKey) {
250                 this.productI18nKey = productI18nKey;
251         }
252
253         @Override
254         public Long getProductId () {
255                 return this.productId;
256         }
257
258         @Override
259         public void setProductId (final Long productId) {
260                 this.productId = productId;
261         }
262
263         @Override
264         public BasicData getProductManfacturer () {
265                 return this.productManfacturer;
266         }
267
268         @Override
269         public void setProductManfacturer (final BasicData productManfacturer) {
270                 this.productManfacturer = productManfacturer;
271         }
272
273         @Override
274         public Float getProductNetPrice () {
275                 return this.productNetPrice;
276         }
277
278         @Override
279         public void setProductNetPrice (final Float productNetPrice) {
280                 this.productNetPrice = productNetPrice;
281         }
282
283         @Override
284         public Float getProductTaxRate () {
285                 return this.productTaxRate;
286         }
287
288         @Override
289         public void setProductTaxRate (final Float productTaxRate) {
290                 this.productTaxRate = productTaxRate;
291         }
292
293         @Override
294         public Float getProductUnitAmount () {
295                 return this.productUnitAmount;
296         }
297
298         @Override
299         public void setProductUnitAmount (final Float productUnitAmount) {
300                 this.productUnitAmount = productUnitAmount;
301         }
302
303         @Override
304         public String getProductUnitType () {
305                 return this.productUnitType;
306         }
307
308         @Override
309         public void setProductUnitType (final String productUnitType) {
310                 this.productUnitType = productUnitType;
311         }
312
313         @Override
314         public int hashCode () {
315                 int hash = 7;
316
317                 hash = 23 * hash + Objects.hashCode(this.getProductId());
318                 hash = 23 * hash + Objects.hashCode(this.getProductI18nKey());
319
320                 return hash;
321         }
322
323 }