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