2 * Copyright (C) 2016 - 2022 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.jcontacts.model.utils.ContactUtils;
43 import org.mxchange.jcoreutils.comparable.ComparableUtils;
44 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
49 * @author Roland Häder<roland@mxchange.org>
51 @Entity (name = "customer")
57 @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC")
60 @SuppressWarnings ("PersistenceUnitPresent")
61 public class ContactCustomer implements Customer {
67 private static final long serialVersionUID = 14_857_923_178_504_617L;
70 * Account status for this customer
72 @Basic (optional = false)
73 @Enumerated (EnumType.STRING)
74 @Column (name = "customer_status", nullable = false)
75 private CustomerAccountStatus customerAccountStatus;
78 * Contact instance (personal data)
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;
85 * When this customer has been created
87 @Basic (optional = false)
88 @Column (name = "customer_entry_created", updatable = false, nullable = false)
89 @Temporal (TemporalType.TIMESTAMP)
90 private Date customerEntryCreated;
93 * When this customer has been updated
95 @Column (name = "customer_entry_updated", insertable = false)
96 @Temporal (TemporalType.TIMESTAMP)
97 private Date customerEntryUpdated;
100 * Id number for this entry
103 @GeneratedValue (strategy = GenerationType.IDENTITY)
104 @Column (name = "customer_id", nullable = false, updatable = false)
105 private Long customerId;
108 * When this customer has been locked (last timestamp)
110 @Column (name = "customer_last_locked")
111 @Temporal (TemporalType.TIMESTAMP)
112 private Date customerLastLocked;
118 @Column (name = "customer_last_locked_reason")
119 private String customerLastLockedReason;
124 @Basic (optional = false)
125 @Column (name = "customer_number", nullable = false, updatable = false, unique = true)
126 private String customerNumber;
129 * Default constructor
131 public ContactCustomer () {
135 * Constructor with account status, contact instance and customer number
137 * @param customerAccountStatus Account status (Call-agents may only call
139 * @param customerContact Contact instance
140 * @param customerNumber Customer number
142 public ContactCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) {
143 // Call other constructor
146 // Validate parameter
147 if (null == customerAccountStatus) {
149 throw new NullPointerException("customerAccountStatus is null"); //NOI18N
150 } else if (null == customerContact) {
152 throw new NullPointerException("customerContact is null"); //NOI18N
153 } else if (null == customerNumber) {
155 throw new NullPointerException("customerNumber is null"); //NOI18N
156 } else if (customerNumber.isEmpty()) {
158 throw new IllegalArgumentException("customerNumber is empty"); //NOI18N
162 this.customerAccountStatus = customerAccountStatus;
163 this.customerContact = customerContact;
164 this.customerNumber = customerNumber;
168 public int compareTo (final Customer customer) {
169 // Check parameter on null-reference and equality to this
170 if (null == customer) {
172 throw new NullPointerException("Parameter 'customer' is null"); //NOI18N
173 } else if (Objects.equals(this, customer)) {
179 final int comparators[] = {
180 // First check contact instance
181 ContactUtils.compare(this.getCustomerContact(), customer.getCustomerContact()),
182 // ... then customer number
183 StringUtils.compare(this.getCustomerNumber(), customer.getCustomerNumber()),
184 // ... last is confirmation key
185 StringUtils.compare(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey())
189 final int comparison = ComparableUtils.checkAll(comparators);
196 public boolean equals (final Object object) {
197 if (this == object) {
199 } else if (null == object) {
201 } else if (this.getClass() != object.getClass()) {
205 final Customer customer = (Customer) object;
207 if (!Objects.equals(this.getCustomerAccountStatus(), customer.getCustomerAccountStatus())) {
209 } else if (!Objects.equals(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey())) {
211 } else if (!Objects.equals(this.getCustomerContact(), customer.getCustomerContact())) {
213 } else if (!Objects.equals(this.getCustomerId(), customer.getCustomerId())) {
215 } else if (!Objects.equals(this.getCustomerLastLocked(), customer.getCustomerLastLocked())) {
217 } else if (!Objects.equals(this.getCustomerLastLockedReason(), customer.getCustomerLastLockedReason())) {
219 } else if (!Objects.equals(this.getCustomerNumber(), customer.getCustomerNumber())) {
221 } else if (!Objects.equals(this.getCustomerPasswordHash(), customer.getCustomerPasswordHash())) {
229 public CustomerAccountStatus getCustomerAccountStatus () {
230 return this.customerAccountStatus;
234 public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
235 this.customerAccountStatus = customerStatus;
239 public String getCustomerConfirmKey () {
240 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
244 public void setCustomerConfirmKey (final String customerConfirmKey) {
245 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
249 public Contact getCustomerContact () {
250 return this.customerContact;
254 public void setCustomerContact (final Contact customerContact) {
255 this.customerContact = customerContact;
259 @SuppressWarnings ("ReturnOfDateField")
260 public Date getCustomerEntryCreated () {
261 return this.customerEntryCreated;
265 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
266 public void setCustomerEntryCreated (final Date customerEntryCreated) {
267 this.customerEntryCreated = customerEntryCreated;
271 @SuppressWarnings ("ReturnOfDateField")
272 public Date getCustomerEntryUpdated () {
273 return this.customerEntryUpdated;
277 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
278 public void setCustomerEntryUpdated (final Date customerEntryUpdated) {
279 this.customerEntryUpdated = customerEntryUpdated;
283 public Long getCustomerId () {
284 return this.customerId;
288 public void setCustomerId (final Long customerId) {
289 this.customerId = customerId;
293 @SuppressWarnings ("ReturnOfDateField")
294 public Date getCustomerLastLocked () {
295 return this.customerLastLocked;
299 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
300 public void setCustomerLastLocked (final Date customerLastLocked) {
301 this.customerLastLocked = customerLastLocked;
305 public String getCustomerLastLockedReason () {
306 return this.customerLastLockedReason;
310 public void setCustomerLastLockedReason (final String customerLastLockedReason) {
311 this.customerLastLockedReason = customerLastLockedReason;
315 public String getCustomerNumber () {
316 return this.customerNumber;
320 public void setCustomerNumber (final String customerNumber) {
321 this.customerNumber = customerNumber;
325 public String getCustomerPasswordHash () {
326 throw new UnsupportedOperationException("Unfinished"); //NOI18N
330 public void setCustomerPasswordHash (final String customerPasswordHash) {
331 throw new UnsupportedOperationException("Unfinished"); //NOI18N
335 public int hashCode () {
338 hash = 53 * hash + Objects.hashCode(this.getCustomerAccountStatus());
339 hash = 53 * hash + Objects.hashCode(this.getCustomerConfirmKey());
340 hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
341 hash = 53 * hash + Objects.hashCode(this.getCustomerId());
342 hash = 53 * hash + Objects.hashCode(this.getCustomerLastLocked());
343 hash = 53 * hash + Objects.hashCode(this.getCustomerLastLockedReason());
344 hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
345 hash = 53 * hash + Objects.hashCode(this.getCustomerPasswordHash());