2 * Copyright (C) 2016 - 2018 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.mxchange.jcontacts.model.contact.Contact;
40 import org.mxchange.jcontacts.model.contact.UserContact;
41 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
46 * @author Roland Häder<roland@mxchange.org>
48 @Entity (name = "customer")
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"),
58 @SuppressWarnings ("PersistenceUnitPresent")
59 public class ContactCustomer implements Customer {
65 private static final long serialVersionUID = 14_857_923_178_504_617L;
68 * Account status for this customer
70 @Basic (optional = false)
71 @Enumerated (EnumType.STRING)
72 @Column (name = "customer_status", nullable = false)
73 private CustomerAccountStatus customerAccountStatus;
76 * Contact instance (personal data)
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;
83 * When this customer has been created
85 @Basic (optional = false)
86 @Column (name = "customer_created", nullable = false, updatable = false)
87 @Temporal (TemporalType.TIMESTAMP)
88 private Date customerCreated;
91 * Id number for this entry
94 @GeneratedValue (strategy = GenerationType.IDENTITY)
95 @Column (name = "customer_id", nullable = false, updatable = false)
96 private Long customerId;
99 * When this customer has been locked (last timestamp)
101 @Column (name = "customer_last_locked")
102 @Temporal (TemporalType.TIMESTAMP)
103 private Date customerLastLocked;
109 @Column (name = "customer_last_locked_reason")
110 private String customerLastLockedReason;
115 @Basic (optional = false)
116 @Column (name = "customer_number", nullable = false, updatable = false, unique = true)
117 private String customerNumber;
120 * When this customer has been updated
122 @Column (name = "customer_updated")
123 @Temporal (TemporalType.TIMESTAMP)
124 private Date customerUpdated;
127 * Default constructor
129 public ContactCustomer () {
133 * Constructor with account status, contact instance and customer number
135 * @param customerAccountStatus Account status (Call-agents may only call
137 * @param customerContact Contact instance
138 * @param customerNumber Customer number
140 public ContactCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) {
141 // Call other constructor
145 this.customerAccountStatus = customerAccountStatus;
146 this.customerContact = customerContact;
147 this.customerNumber = customerNumber;
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());
163 public boolean equals (final Object object) {
164 if (this == object) {
166 } else if (null == object) {
168 } else if (this.getClass() != object.getClass()) {
172 final Customer other = (Customer) object;
174 if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
176 } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) {
178 } else if (!Objects.equals(this.getCustomerId(), other.getCustomerId())) {
186 public int hashCode () {
189 hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
190 hash = 53 * hash + Objects.hashCode(this.getCustomerId());
191 hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
197 public CustomerAccountStatus getCustomerAccountStatus () {
198 return this.customerAccountStatus;
202 public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
203 this.customerAccountStatus = customerStatus;
207 public String getCustomerConfirmKey () {
208 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
212 public void setCustomerConfirmKey (final String customerConfirmKey) {
213 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
217 public Contact getCustomerContact () {
218 return this.customerContact;
222 public void setCustomerContact (final Contact customerContact) {
223 this.customerContact = customerContact;
227 @SuppressWarnings ("ReturnOfDateField")
228 public Date getCustomerCreated () {
229 return this.customerCreated;
233 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
234 public void setCustomerCreated (final Date customerCreated) {
235 this.customerCreated = customerCreated;
239 public Long getCustomerId () {
240 return this.customerId;
244 public void setCustomerId (final Long customerId) {
245 this.customerId = customerId;
249 @SuppressWarnings ("ReturnOfDateField")
250 public Date getCustomerLastLocked () {
251 return this.customerLastLocked;
255 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
256 public void setCustomerLastLocked (final Date customerLastLocked) {
257 this.customerLastLocked = customerLastLocked;
261 public String getCustomerLastLockedReason () {
262 return this.customerLastLockedReason;
266 public void setCustomerLastLockedReason (final String customerLastLockedReason) {
267 this.customerLastLockedReason = customerLastLockedReason;
271 public String getCustomerNumber () {
272 return this.customerNumber;
276 public void setCustomerNumber (final String customerNumber) {
277 this.customerNumber = customerNumber;
281 public String getCustomerPasswordHash () {
282 throw new UnsupportedOperationException("Unfinished"); //NOI18N
286 public void setCustomerPasswordHash (final String customerPasswordHash) {
287 throw new UnsupportedOperationException("Unfinished"); //NOI18N
291 @SuppressWarnings ("ReturnOfDateField")
292 public Date getCustomerUpdated () {
293 return this.customerUpdated;
297 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
298 public void setCustomerUpdated (final Date customerUpdated) {
299 this.customerUpdated = customerUpdated;