2 * Copyright (C) 2016 - 2024 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.text.MessageFormat;
20 import java.util.Date;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.EnumType;
27 import javax.persistence.Enumerated;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.Lob;
33 import javax.persistence.NamedQueries;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.OneToOne;
36 import javax.persistence.Table;
37 import javax.persistence.Temporal;
38 import javax.persistence.TemporalType;
39 import javax.persistence.Transient;
40 import org.apache.commons.lang3.StringUtils;
41 import org.mxchange.jcontacts.model.contact.Contact;
42 import org.mxchange.jcontacts.model.contact.UserContact;
43 import org.mxchange.jcontacts.model.utils.ContactUtils;
44 import org.mxchange.jcoreutils.comparable.ComparableUtils;
45 import org.mxchange.jcoreutils.enums.EnumUtils;
46 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
51 * @author Roland Häder<roland@mxchange.org>
53 @Entity (name = "customer")
59 @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC")
62 @SuppressWarnings ("PersistenceUnitPresent")
63 public class ContactCustomer implements Customer {
69 private static final long serialVersionUID = 14_857_923_178_504_617L;
72 * Account status for this customer
74 @Basic (optional = false)
75 @Enumerated (EnumType.STRING)
76 @Column (name = "customer_status", nullable = false)
77 private CustomerAccountStatus customerAccountStatus;
80 * Contact instance (personal data)
82 @JoinColumn (name = "customer_contact_id", nullable = false, updatable = false, unique = true)
83 @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
84 private Contact customerContact;
87 * When this customer has been created
89 @Basic (optional = false)
90 @Column (name = "customer_entry_created", updatable = false, nullable = false)
91 @Temporal (TemporalType.TIMESTAMP)
92 private Date customerEntryCreated;
95 * When this customer has been updated
97 @Column (name = "customer_entry_updated", insertable = false)
98 @Temporal (TemporalType.TIMESTAMP)
99 private Date customerEntryUpdated;
102 * Id number for this entry
105 @GeneratedValue (strategy = GenerationType.IDENTITY)
106 @Column (name = "customer_id", nullable = false, updatable = false)
107 private Long customerId;
110 * When this customer has been locked (last timestamp)
112 @Column (name = "customer_last_locked")
113 @Temporal (TemporalType.TIMESTAMP)
114 private Date customerLastLocked;
120 @Column (name = "customer_last_locked_reason")
121 private String customerLastLockedReason;
126 @Basic (optional = false)
127 @Column (name = "customer_number", nullable = false, updatable = false, unique = true)
128 private String customerNumber;
131 * Default constructor
133 public ContactCustomer () {
137 * Constructor with account status, contact instance and customer number
139 * @param customerAccountStatus Account status (Call-agents may only call
141 * @param customerContact Contact instance
142 * @param customerNumber Customer number
144 public ContactCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) {
145 // Call other constructor
148 // Validate parameter
149 if (null == customerAccountStatus) {
151 throw new NullPointerException("customerAccountStatus is null"); //NOI18N
152 } else if (null == customerContact) {
154 throw new NullPointerException("customerContact is null"); //NOI18N
155 } else if (customerContact.getContactId() == null) {
157 throw new NullPointerException("customerContact.contactId is null"); //NOI18N
158 } else if (customerContact.getContactId() < 1) {
160 throw new IllegalArgumentException(MessageFormat.format("customerContact.contactId={0} is invalid", customerContact.getContactId())); //NOI18N
161 } else if (null == customerNumber) {
163 throw new NullPointerException("customerNumber is null"); //NOI18N
164 } else if (customerNumber.isEmpty()) {
166 throw new IllegalArgumentException("customerNumber is empty"); //NOI18N
170 this.customerAccountStatus = customerAccountStatus;
171 this.customerContact = customerContact;
172 this.customerNumber = customerNumber;
176 public int compareTo (final Customer customer) {
177 // Check parameter on null-reference and equality to this
178 if (null == customer) {
180 throw new NullPointerException("Parameter 'customer' is null"); //NOI18N
181 } else if (Objects.equals(this, customer)) {
187 final int comparators[] = {
188 // First check contact instance
189 ContactUtils.compare(this.getCustomerContact(), customer.getCustomerContact()),
190 // ... then customer number
191 StringUtils.compare(this.getCustomerNumber(), customer.getCustomerNumber()),
192 // ... next is confirmation key
193 StringUtils.compare(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey()),
194 // ... next account status
195 EnumUtils.compare(this.getCustomerAccountStatus(), customer.getCustomerAccountStatus())
199 final int comparison = ComparableUtils.checkAll(comparators);
206 public boolean equals (final Object object) {
207 if (this == object) {
209 } else if (null == object) {
211 } else if (this.getClass() != object.getClass()) {
215 final Customer customer = (Customer) object;
217 if (!Objects.equals(this.getCustomerAccountStatus(), customer.getCustomerAccountStatus())) {
219 } else if (!Objects.equals(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey())) {
221 } else if (!Objects.equals(this.getCustomerContact(), customer.getCustomerContact())) {
223 } else if (!Objects.equals(this.getCustomerId(), customer.getCustomerId())) {
225 } else if (!Objects.equals(this.getCustomerLastLocked(), customer.getCustomerLastLocked())) {
227 } else if (!Objects.equals(this.getCustomerLastLockedReason(), customer.getCustomerLastLockedReason())) {
229 } else if (!Objects.equals(this.getCustomerNumber(), customer.getCustomerNumber())) {
231 } else if (!Objects.equals(this.getCustomerPasswordHash(), customer.getCustomerPasswordHash())) {
239 public CustomerAccountStatus getCustomerAccountStatus () {
240 return this.customerAccountStatus;
244 public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
245 this.customerAccountStatus = customerStatus;
249 public String getCustomerConfirmKey () {
250 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
254 public void setCustomerConfirmKey (final String customerConfirmKey) {
255 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
259 public Contact getCustomerContact () {
260 return this.customerContact;
264 public void setCustomerContact (final Contact customerContact) {
265 this.customerContact = customerContact;
269 @SuppressWarnings ("ReturnOfDateField")
270 public Date getCustomerEntryCreated () {
271 return this.customerEntryCreated;
275 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
276 public void setCustomerEntryCreated (final Date customerEntryCreated) {
277 this.customerEntryCreated = customerEntryCreated;
281 @SuppressWarnings ("ReturnOfDateField")
282 public Date getCustomerEntryUpdated () {
283 return this.customerEntryUpdated;
287 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
288 public void setCustomerEntryUpdated (final Date customerEntryUpdated) {
289 this.customerEntryUpdated = customerEntryUpdated;
293 public Long getCustomerId () {
294 return this.customerId;
298 public void setCustomerId (final Long customerId) {
299 this.customerId = customerId;
303 @SuppressWarnings ("ReturnOfDateField")
304 public Date getCustomerLastLocked () {
305 return this.customerLastLocked;
309 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
310 public void setCustomerLastLocked (final Date customerLastLocked) {
311 this.customerLastLocked = customerLastLocked;
315 public String getCustomerLastLockedReason () {
316 return this.customerLastLockedReason;
320 public void setCustomerLastLockedReason (final String customerLastLockedReason) {
321 this.customerLastLockedReason = customerLastLockedReason;
325 public String getCustomerNumber () {
326 return this.customerNumber;
330 public void setCustomerNumber (final String customerNumber) {
331 this.customerNumber = customerNumber;
335 public String getCustomerPasswordHash () {
336 throw new UnsupportedOperationException("Unfinished"); //NOI18N
340 public void setCustomerPasswordHash (final String customerPasswordHash) {
341 throw new UnsupportedOperationException("Unfinished"); //NOI18N
345 public int hashCode () {
348 hash = 53 * hash + Objects.hashCode(this.getCustomerAccountStatus());
349 hash = 53 * hash + Objects.hashCode(this.getCustomerConfirmKey());
350 hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
351 hash = 53 * hash + Objects.hashCode(this.getCustomerId());
352 hash = 53 * hash + Objects.hashCode(this.getCustomerLastLocked());
353 hash = 53 * hash + Objects.hashCode(this.getCustomerLastLockedReason());
354 hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
355 hash = 53 * hash + Objects.hashCode(this.getCustomerPasswordHash());