]> git.mxchange.org Git - pizzaservice-core.git/blob - src/org/mxchange/pizzaaplication/model/customer/PizzaCustomer.java
initialized project
[pizzaservice-core.git] / src / org / mxchange / pizzaaplication / model / customer / PizzaCustomer.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (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 Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.pizzaapplication.model.customer;
18
19 import java.util.Calendar;
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.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.Index;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.OneToOne;
35 import javax.persistence.Table;
36 import javax.persistence.Temporal;
37 import javax.persistence.TemporalType;
38 import org.mxchange.jcontacts.contact.Contact;
39 import org.mxchange.jcontacts.contact.UserContact;
40 import org.mxchange.jcustomercore.model.customer.Customer;
41 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
42
43 /**
44  * A customer entity
45  * <p>
46  * @author Roland Haeder<roland@mxchange.org>
47  */
48 @Entity (name = "customer")
49 @Table (
50                 name = "customer",
51                 indexes = {
52                         @Index (columnList = "customer_number", unique = true)
53                 }
54 )
55 @NamedQueries (
56                 {
57                         @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC")
58                 }
59 )
60 @SuppressWarnings ("PersistenceUnitPresent")
61 public class PizzaCustomer implements Customer {
62
63         /**
64          * Serial number
65          */
66         private static final long serialVersionUID = 14_857_923_178_504_617L;
67
68         /**
69          * Account status for this customer
70          */
71         @Basic (optional = false)
72         @Enumerated (EnumType.STRING)
73         @Column (name = "customer_status", nullable = false)
74         private CustomerAccountStatus customerAccountStatus;
75
76         /**
77          * Contact instance (personal data)
78          */
79         @JoinColumn (name = "customer_contact_id", nullable = false, updatable = false, unique = true)
80         @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
81         private Contact customerContact;
82
83         /**
84          * When this customer has been created
85          */
86         @Basic (optional = false)
87         @Column (name = "customer_created", nullable = false, updatable = false)
88         @Temporal (TemporalType.TIMESTAMP)
89         private Calendar customerCreated;
90
91         /**
92          * Id number for this entry
93          */
94         @Id
95         @GeneratedValue (strategy = GenerationType.IDENTITY)
96         @Column (name = "customer_id", nullable = false, updatable = false)
97         private Long customerId;
98
99         /**
100          * When this customer has been locked (last timestamp)
101          */
102         @Column (name = "customer_last_locked")
103         @Temporal (TemporalType.TIMESTAMP)
104         private Calendar customerLocked;
105
106         /**
107          * Customer number
108          */
109         @Basic (optional = false)
110         @Column (name = "customer_number", nullable = false, updatable = false)
111         private String customerNumber;
112
113         /**
114          * Default constructor
115          */
116         public PizzaCustomer () {
117         }
118
119         /**
120          * Constructor with account status, contact instance and customer number
121          * <p>
122          * @param customerAccountStatus Account status (Call-agents may only call
123          * unlocked accounts)
124          * @param customerContact Contact instance
125          * @param customerNumber Customer number
126          */
127         public PizzaCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) {
128                 // Call other constructor
129                 this();
130
131                 // Set all parameter
132                 this.customerAccountStatus = customerAccountStatus;
133                 this.customerContact = customerContact;
134                 this.customerNumber = customerNumber;
135         }
136
137         @Override
138         public void copyAll (final Customer customer) {
139                 // Copy all supported fields
140                 this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
141                 this.setCustomerContact(customer.getCustomerContact());
142                 this.setCustomerCreated(customer.getCustomerCreated());
143                 this.setCustomerId(customer.getCustomerId());
144                 this.setCustomerLocked(customer.getCustomerLocked());
145                 this.setCustomerNumber(customer.getCustomerNumber());
146         }
147
148         @Override
149         public boolean equals (final Object object) {
150                 if (this == object) {
151                         return true;
152                 } else if (null == object) {
153                         return false;
154                 } else if (this.getClass() != object.getClass()) {
155                         return false;
156                 }
157
158                 final Customer other = (Customer) object;
159
160                 if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
161                         return false;
162                 } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) {
163                         return false;
164                 } else if (!Objects.equals(this.getCustomerId(), other.getCustomerId())) {
165                         return false;
166                 }
167
168                 return true;
169         }
170
171         @Override
172         public int hashCode () {
173                 int hash = 7;
174
175                 hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
176                 hash = 53 * hash + Objects.hashCode(this.getCustomerId());
177                 hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
178
179                 return hash;
180         }
181
182         @Override
183         public CustomerAccountStatus getCustomerAccountStatus () {
184                 return this.customerAccountStatus;
185         }
186
187         @Override
188         public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
189                 this.customerAccountStatus = customerStatus;
190         }
191
192         @Override
193         public String getCustomerConfirmKey () {
194                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
195         }
196
197         @Override
198         public void setCustomerConfirmKey (final String customerConfirmKey) {
199                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
200         }
201
202         @Override
203         public Contact getCustomerContact () {
204                 return this.customerContact;
205         }
206
207         @Override
208         public void setCustomerContact (final Contact customerContact) {
209                 this.customerContact = customerContact;
210         }
211
212         @Override
213         public Calendar getCustomerCreated () {
214                 return this.customerCreated;
215         }
216
217         @Override
218         public void setCustomerCreated (final Calendar customerCreated) {
219                 this.customerCreated = customerCreated;
220         }
221
222         @Override
223         public Long getCustomerId () {
224                 return this.customerId;
225         }
226
227         @Override
228         public void setCustomerId (final Long customerId) {
229                 this.customerId = customerId;
230         }
231
232         @Override
233         public Calendar getCustomerLocked () {
234                 return this.customerLocked;
235         }
236
237         @Override
238         public void setCustomerLocked (final Calendar customerLocked) {
239                 this.customerLocked = customerLocked;
240         }
241
242         @Override
243         public String getCustomerNumber () {
244                 return this.customerNumber;
245         }
246
247         @Override
248         public void setCustomerNumber (final String customerNumber) {
249                 this.customerNumber = customerNumber;
250         }
251
252         @Override
253         public String getCustomerPasswordHash () {
254                 throw new UnsupportedOperationException("Unfinished"); //NOI18N
255         }
256
257         @Override
258         public void setCustomerPasswordHash (final String customerPasswordHash) {
259                 throw new UnsupportedOperationException("Unfinished"); //NOI18N
260         }
261
262 }