2 * Copyright (C) 2016, 2017 Roland Häder
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.Calendar;
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.contact.Contact;
40 import org.mxchange.jcontacts.contact.UserContact;
41 import org.mxchange.jcustomercore.model.customer.Customer;
42 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
47 * @author Roland Häder<roland@mxchange.org>
49 @Entity (name = "customer")
55 @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC"),
56 @NamedQuery (name = "SearchCustomerByNumber", query = "SELECT c FROM customer AS c WHERE c.customerNumber = :customerNumber"),
57 @NamedQuery (name = "SearchCustomerById", query = "SELECT c FROM customer AS c WHERE c.customerId = :customerId")
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_created", nullable = false, updatable = false)
89 @Temporal (TemporalType.TIMESTAMP)
90 private Calendar customerCreated;
93 * Id number for this entry
96 @GeneratedValue (strategy = GenerationType.IDENTITY)
97 @Column (name = "customer_id", nullable = false, updatable = false)
98 private Long customerId;
101 * When this customer has been locked (last timestamp)
103 @Column (name = "customer_last_locked")
104 @Temporal (TemporalType.TIMESTAMP)
105 private Calendar customerLastLocked;
111 @Column (name = "customer_last_locked_reason")
112 private String customerLastLockedReason;
117 @Basic (optional = false)
118 @Column (name = "customer_number", nullable = false, updatable = false, unique = true)
119 private String customerNumber;
122 * When this customer has been updated
124 @Column (name = "customer_updated")
125 @Temporal (TemporalType.TIMESTAMP)
126 private Calendar customerUpdated;
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
147 this.customerAccountStatus = customerAccountStatus;
148 this.customerContact = customerContact;
149 this.customerNumber = customerNumber;
153 public void copyAll (final Customer customer) {
154 // Copy all supported fields
155 this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
156 this.setCustomerContact(customer.getCustomerContact());
157 this.setCustomerCreated(customer.getCustomerCreated());
158 this.setCustomerId(customer.getCustomerId());
159 this.setCustomerLastLocked(customer.getCustomerLastLocked());
160 this.setCustomerLastLockedReason(customer.getCustomerLastLockedReason());
161 this.setCustomerNumber(customer.getCustomerNumber());
165 public boolean equals (final Object object) {
166 if (this == object) {
168 } else if (null == object) {
170 } else if (this.getClass() != object.getClass()) {
174 final Customer other = (Customer) object;
176 if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
178 } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) {
180 } else if (!Objects.equals(this.getCustomerId(), other.getCustomerId())) {
188 public int hashCode () {
191 hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
192 hash = 53 * hash + Objects.hashCode(this.getCustomerId());
193 hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
199 public CustomerAccountStatus getCustomerAccountStatus () {
200 return this.customerAccountStatus;
204 public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
205 this.customerAccountStatus = customerStatus;
209 public String getCustomerConfirmKey () {
210 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
214 public void setCustomerConfirmKey (final String customerConfirmKey) {
215 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
219 public Contact getCustomerContact () {
220 return this.customerContact;
224 public void setCustomerContact (final Contact customerContact) {
225 this.customerContact = customerContact;
229 @SuppressWarnings ("ReturnOfDateField")
230 public Calendar getCustomerCreated () {
231 return this.customerCreated;
235 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
236 public void setCustomerCreated (final Calendar customerCreated) {
237 this.customerCreated = customerCreated;
241 public Long getCustomerId () {
242 return this.customerId;
246 public void setCustomerId (final Long customerId) {
247 this.customerId = customerId;
251 @SuppressWarnings ("ReturnOfDateField")
252 public Calendar getCustomerLastLocked () {
253 return this.customerLastLocked;
257 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
258 public void setCustomerLastLocked (final Calendar customerLastLocked) {
259 this.customerLastLocked = customerLastLocked;
263 public String getCustomerLastLockedReason () {
264 return this.customerLastLockedReason;
268 public void setCustomerLastLockedReason (final String customerLastLockedReason) {
269 this.customerLastLockedReason = customerLastLockedReason;
273 public String getCustomerNumber () {
274 return this.customerNumber;
278 public void setCustomerNumber (final String customerNumber) {
279 this.customerNumber = customerNumber;
283 public String getCustomerPasswordHash () {
284 throw new UnsupportedOperationException("Unfinished"); //NOI18N
288 public void setCustomerPasswordHash (final String customerPasswordHash) {
289 throw new UnsupportedOperationException("Unfinished"); //NOI18N
293 @SuppressWarnings ("ReturnOfDateField")
294 public Calendar getCustomerUpdated () {
295 return this.customerUpdated;
299 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
300 public void setCustomerUpdated (final Calendar customerUpdated) {
301 this.customerUpdated = customerUpdated;