]> git.mxchange.org Git - jcustomer-core.git/blob - src/org/mxchange/jcustomercore/model/customer/ContactCustomer.java
Continued:
[jcustomer-core.git] / src / org / mxchange / jcustomercore / model / customer / ContactCustomer.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 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.jcustomercore.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.JoinColumn;
31 import javax.persistence.Lob;
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 javax.persistence.Transient;
39 import org.mxchange.jcontacts.model.contact.Contact;
40 import org.mxchange.jcontacts.model.contact.UserContact;
41 import org.mxchange.jcustomercore.model.customer.Customer;
42 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
43
44 /**
45  * A customer entity
46  * <p>
47  * @author Roland Häder<roland@mxchange.org>
48  */
49 @Entity (name = "customer")
50 @Table (
51                 name = "customer"
52 )
53 @NamedQueries (
54                 {
55                         @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC"),
56                         @NamedQuery (name = "SearchCustomerByNumber", query = "SELECT c FROM customer AS c WHERE c.customerNumber = :customerNumber"),
57                         @NamedQuery (name = "SearchCustomerById", query = "SELECT c FROM customer AS c WHERE c.customerId = :customerId")
58                 }
59 )
60 @SuppressWarnings ("PersistenceUnitPresent")
61 public class ContactCustomer implements Customer {
62
63         /**
64          * Serial number
65          */
66         @Transient
67         private static final long serialVersionUID = 14_857_923_178_504_617L;
68
69         /**
70          * Account status for this customer
71          */
72         @Basic (optional = false)
73         @Enumerated (EnumType.STRING)
74         @Column (name = "customer_status", nullable = false)
75         private CustomerAccountStatus customerAccountStatus;
76
77         /**
78          * Contact instance (personal data)
79          */
80         @JoinColumn (name = "customer_contact_id", nullable = false, updatable = false, unique = true)
81         @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
82         private Contact customerContact;
83
84         /**
85          * When this customer has been created
86          */
87         @Basic (optional = false)
88         @Column (name = "customer_created", nullable = false, updatable = false)
89         @Temporal (TemporalType.TIMESTAMP)
90         private Calendar customerCreated;
91
92         /**
93          * Id number for this entry
94          */
95         @Id
96         @GeneratedValue (strategy = GenerationType.IDENTITY)
97         @Column (name = "customer_id", nullable = false, updatable = false)
98         private Long customerId;
99
100         /**
101          * When this customer has been locked (last timestamp)
102          */
103         @Column (name = "customer_last_locked")
104         @Temporal (TemporalType.TIMESTAMP)
105         private Calendar customerLastLocked;
106
107         /**
108          * Last locked reason
109          */
110         @Lob
111         @Column (name = "customer_last_locked_reason")
112         private String customerLastLockedReason;
113
114         /**
115          * Customer number
116          */
117         @Basic (optional = false)
118         @Column (name = "customer_number", nullable = false, updatable = false, unique = true)
119         private String customerNumber;
120
121         /**
122          * When this customer has been updated
123          */
124         @Column (name = "customer_updated")
125         @Temporal (TemporalType.TIMESTAMP)
126         private Calendar customerUpdated;
127
128         /**
129          * Default constructor
130          */
131         public ContactCustomer () {
132         }
133
134         /**
135          * Constructor with account status, contact instance and customer number
136          * <p>
137          * @param customerAccountStatus Account status (Call-agents may only call
138          * unlocked accounts)
139          * @param customerContact Contact instance
140          * @param customerNumber Customer number
141          */
142         public ContactCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) {
143                 // Call other constructor
144                 this();
145
146                 // Set all parameter
147                 this.customerAccountStatus = customerAccountStatus;
148                 this.customerContact = customerContact;
149                 this.customerNumber = customerNumber;
150         }
151
152         @Override
153         public void copyAll (final Customer customer) {
154                 // Copy all supported fields
155                 this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
156                 this.setCustomerContact(customer.getCustomerContact());
157                 this.setCustomerCreated(customer.getCustomerCreated());
158                 this.setCustomerId(customer.getCustomerId());
159                 this.setCustomerLastLocked(customer.getCustomerLastLocked());
160                 this.setCustomerLastLockedReason(customer.getCustomerLastLockedReason());
161                 this.setCustomerNumber(customer.getCustomerNumber());
162         }
163
164         @Override
165         public boolean equals (final Object object) {
166                 if (this == object) {
167                         return true;
168                 } else if (null == object) {
169                         return false;
170                 } else if (this.getClass() != object.getClass()) {
171                         return false;
172                 }
173
174                 final Customer other = (Customer) object;
175
176                 if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
177                         return false;
178                 } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) {
179                         return false;
180                 } else if (!Objects.equals(this.getCustomerId(), other.getCustomerId())) {
181                         return false;
182                 }
183
184                 return true;
185         }
186
187         @Override
188         public int hashCode () {
189                 int hash = 7;
190
191                 hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
192                 hash = 53 * hash + Objects.hashCode(this.getCustomerId());
193                 hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
194
195                 return hash;
196         }
197
198         @Override
199         public CustomerAccountStatus getCustomerAccountStatus () {
200                 return this.customerAccountStatus;
201         }
202
203         @Override
204         public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
205                 this.customerAccountStatus = customerStatus;
206         }
207
208         @Override
209         public String getCustomerConfirmKey () {
210                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
211         }
212
213         @Override
214         public void setCustomerConfirmKey (final String customerConfirmKey) {
215                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
216         }
217
218         @Override
219         public Contact getCustomerContact () {
220                 return this.customerContact;
221         }
222
223         @Override
224         public void setCustomerContact (final Contact customerContact) {
225                 this.customerContact = customerContact;
226         }
227
228         @Override
229         @SuppressWarnings ("ReturnOfDateField")
230         public Calendar getCustomerCreated () {
231                 return this.customerCreated;
232         }
233
234         @Override
235         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
236         public void setCustomerCreated (final Calendar customerCreated) {
237                 this.customerCreated = customerCreated;
238         }
239
240         @Override
241         public Long getCustomerId () {
242                 return this.customerId;
243         }
244
245         @Override
246         public void setCustomerId (final Long customerId) {
247                 this.customerId = customerId;
248         }
249
250         @Override
251         @SuppressWarnings ("ReturnOfDateField")
252         public Calendar getCustomerLastLocked () {
253                 return this.customerLastLocked;
254         }
255
256         @Override
257         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
258         public void setCustomerLastLocked (final Calendar customerLastLocked) {
259                 this.customerLastLocked = customerLastLocked;
260         }
261
262         @Override
263         public String getCustomerLastLockedReason () {
264                 return this.customerLastLockedReason;
265         }
266
267         @Override
268         public void setCustomerLastLockedReason (final String customerLastLockedReason) {
269                 this.customerLastLockedReason = customerLastLockedReason;
270         }
271
272         @Override
273         public String getCustomerNumber () {
274                 return this.customerNumber;
275         }
276
277         @Override
278         public void setCustomerNumber (final String customerNumber) {
279                 this.customerNumber = customerNumber;
280         }
281
282         @Override
283         public String getCustomerPasswordHash () {
284                 throw new UnsupportedOperationException("Unfinished"); //NOI18N
285         }
286
287         @Override
288         public void setCustomerPasswordHash (final String customerPasswordHash) {
289                 throw new UnsupportedOperationException("Unfinished"); //NOI18N
290         }
291
292         @Override
293         @SuppressWarnings ("ReturnOfDateField")
294         public Calendar getCustomerUpdated () {
295                 return this.customerUpdated;
296         }
297
298         @Override
299         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
300         public void setCustomerUpdated (final Calendar customerUpdated) {
301                 this.customerUpdated = customerUpdated;
302         }
303
304 }