2 * Copyright (C) 2016 - 2020 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.jcustomercore.model.customer;
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.apache.commons.lang3.StringUtils;
40 import org.mxchange.jcontacts.model.contact.Contact;
41 import org.mxchange.jcontacts.model.contact.UserContact;
42 import org.mxchange.jcoreutils.Comparables;
43 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
48 * @author Roland Häder<roland@mxchange.org>
50 @Entity (name = "customer")
56 @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC")
59 @SuppressWarnings ("PersistenceUnitPresent")
60 public class ContactCustomer implements Customer {
66 private static final long serialVersionUID = 14_857_923_178_504_617L;
69 * Account status for this customer
71 @Basic (optional = false)
72 @Enumerated (EnumType.STRING)
73 @Column (name = "customer_status", nullable = false)
74 private CustomerAccountStatus customerAccountStatus;
77 * Contact instance (personal data)
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;
84 * When this customer has been created
86 @Basic (optional = false)
87 @Column (name = "customer_entry_created", updatable = false, nullable = false)
88 @Temporal (TemporalType.TIMESTAMP)
89 private Date customerEntryCreated;
92 * When this customer has been updated
94 @Column (name = "customer_entry_updated", insertable = false)
95 @Temporal (TemporalType.TIMESTAMP)
96 private Date customerEntryUpdated;
99 * Id number for this entry
102 @GeneratedValue (strategy = GenerationType.IDENTITY)
103 @Column (name = "customer_id", nullable = false, updatable = false)
104 private Long customerId;
107 * When this customer has been locked (last timestamp)
109 @Column (name = "customer_last_locked")
110 @Temporal (TemporalType.TIMESTAMP)
111 private Date customerLastLocked;
117 @Column (name = "customer_last_locked_reason")
118 private String customerLastLockedReason;
123 @Basic (optional = false)
124 @Column (name = "customer_number", nullable = false, updatable = false, unique = true)
125 private String customerNumber;
128 * Default constructor
130 public ContactCustomer () {
134 * Constructor with account status, contact instance and customer number
136 * @param customerAccountStatus Account status (Call-agents may only call
138 * @param customerContact Contact instance
139 * @param customerNumber Customer number
141 public ContactCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) {
142 // Call other constructor
145 // Validate parameter
146 if (null == customerAccountStatus) {
148 throw new NullPointerException("customerAccountStatus is null"); //NOI18N
149 } else if (null == customerContact) {
151 throw new NullPointerException("customerContact is null"); //NOI18N
152 } else if (null == customerNumber) {
154 throw new NullPointerException("customerNumber is null"); //NOI18N
155 } else if (customerNumber.isEmpty()) {
157 throw new IllegalArgumentException("customerNumber is empty"); //NOI18N
161 this.customerAccountStatus = customerAccountStatus;
162 this.customerContact = customerContact;
163 this.customerNumber = customerNumber;
167 public int compareTo (final Customer customer) {
168 // Check parameter on null-reference and equality to this
169 if (null == customer) {
171 throw new NullPointerException("customer is null"); //NOI18N
172 } else if (customer.equals(this)) {
178 final int comparators[] = {
179 // First check contact instance
180 this.getCustomerContact().compareTo(customer.getCustomerContact()),
181 // ... then customer number
182 this.getCustomerNumber().compareTo(customer.getCustomerNumber()),
183 // ... last is confirmation key
184 StringUtils.compare(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey())
188 final int comparison = Comparables.checkAll(comparators);
195 public boolean equals (final Object object) {
196 if (this == object) {
198 } else if (null == object) {
200 } else if (this.getClass() != object.getClass()) {
204 final Customer customer = (Customer) object;
206 if (!Objects.equals(this.getCustomerAccountStatus(), customer.getCustomerAccountStatus())) {
208 } else if (!Objects.equals(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey())) {
210 } else if (!Objects.equals(this.getCustomerContact(), customer.getCustomerContact())) {
212 } else if (!Objects.equals(this.getCustomerId(), customer.getCustomerId())) {
214 } else if (!Objects.equals(this.getCustomerLastLocked(), customer.getCustomerLastLocked())) {
216 } else if (!Objects.equals(this.getCustomerLastLockedReason(), customer.getCustomerLastLockedReason())) {
218 } else if (!Objects.equals(this.getCustomerNumber(), customer.getCustomerNumber())) {
220 } else if (!Objects.equals(this.getCustomerPasswordHash(), customer.getCustomerPasswordHash())) {
228 public CustomerAccountStatus getCustomerAccountStatus () {
229 return this.customerAccountStatus;
233 public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
234 this.customerAccountStatus = customerStatus;
238 public String getCustomerConfirmKey () {
239 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
243 public void setCustomerConfirmKey (final String customerConfirmKey) {
244 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
248 public Contact getCustomerContact () {
249 return this.customerContact;
253 public void setCustomerContact (final Contact customerContact) {
254 this.customerContact = customerContact;
258 @SuppressWarnings ("ReturnOfDateField")
259 public Date getCustomerEntryCreated () {
260 return this.customerEntryCreated;
264 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
265 public void setCustomerEntryCreated (final Date customerEntryCreated) {
266 this.customerEntryCreated = customerEntryCreated;
270 @SuppressWarnings ("ReturnOfDateField")
271 public Date getCustomerEntryUpdated () {
272 return this.customerEntryUpdated;
276 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
277 public void setCustomerEntryUpdated (final Date customerEntryUpdated) {
278 this.customerEntryUpdated = customerEntryUpdated;
282 public Long getCustomerId () {
283 return this.customerId;
287 public void setCustomerId (final Long customerId) {
288 this.customerId = customerId;
292 @SuppressWarnings ("ReturnOfDateField")
293 public Date getCustomerLastLocked () {
294 return this.customerLastLocked;
298 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
299 public void setCustomerLastLocked (final Date customerLastLocked) {
300 this.customerLastLocked = customerLastLocked;
304 public String getCustomerLastLockedReason () {
305 return this.customerLastLockedReason;
309 public void setCustomerLastLockedReason (final String customerLastLockedReason) {
310 this.customerLastLockedReason = customerLastLockedReason;
314 public String getCustomerNumber () {
315 return this.customerNumber;
319 public void setCustomerNumber (final String customerNumber) {
320 this.customerNumber = customerNumber;
324 public String getCustomerPasswordHash () {
325 throw new UnsupportedOperationException("Unfinished"); //NOI18N
329 public void setCustomerPasswordHash (final String customerPasswordHash) {
330 throw new UnsupportedOperationException("Unfinished"); //NOI18N
334 public int hashCode () {
337 hash = 53 * hash + Objects.hashCode(this.getCustomerAccountStatus());
338 hash = 53 * hash + Objects.hashCode(this.getCustomerConfirmKey());
339 hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
340 hash = 53 * hash + Objects.hashCode(this.getCustomerId());
341 hash = 53 * hash + Objects.hashCode(this.getCustomerLastLocked());
342 hash = 53 * hash + Objects.hashCode(this.getCustomerLastLockedReason());
343 hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
344 hash = 53 * hash + Objects.hashCode(this.getCustomerPasswordHash());