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.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"),
56 @NamedQuery (name = "SearchCustomerById", query = "SELECT c FROM customer AS c WHERE c.customerId = :customerId")
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_created", nullable = false, updatable = false)
88 @Temporal (TemporalType.TIMESTAMP)
89 private Date customerCreated;
92 * Id number for this entry
95 @GeneratedValue (strategy = GenerationType.IDENTITY)
96 @Column (name = "customer_id", nullable = false, updatable = false)
97 private Long customerId;
100 * When this customer has been locked (last timestamp)
102 @Column (name = "customer_last_locked")
103 @Temporal (TemporalType.TIMESTAMP)
104 private Date customerLastLocked;
110 @Column (name = "customer_last_locked_reason")
111 private String customerLastLockedReason;
116 @Basic (optional = false)
117 @Column (name = "customer_number", nullable = false, updatable = false, unique = true)
118 private String customerNumber;
121 * When this customer has been updated
123 @Column (name = "customer_updated")
124 @Temporal (TemporalType.TIMESTAMP)
125 private Date customerUpdated;
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
146 this.customerAccountStatus = customerAccountStatus;
147 this.customerContact = customerContact;
148 this.customerNumber = customerNumber;
152 public void copyAll (final Customer customer) {
153 // Copy all supported fields
154 this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
155 this.setCustomerContact(customer.getCustomerContact());
156 this.setCustomerCreated(customer.getCustomerCreated());
157 this.setCustomerId(customer.getCustomerId());
158 this.setCustomerLastLocked(customer.getCustomerLastLocked());
159 this.setCustomerLastLockedReason(customer.getCustomerLastLockedReason());
160 this.setCustomerNumber(customer.getCustomerNumber());
164 public boolean equals (final Object object) {
165 if (this == object) {
167 } else if (null == object) {
169 } else if (this.getClass() != object.getClass()) {
173 final Customer other = (Customer) object;
175 if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
177 } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) {
179 } else if (!Objects.equals(this.getCustomerId(), other.getCustomerId())) {
187 public int hashCode () {
190 hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
191 hash = 53 * hash + Objects.hashCode(this.getCustomerId());
192 hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
198 public CustomerAccountStatus getCustomerAccountStatus () {
199 return this.customerAccountStatus;
203 public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
204 this.customerAccountStatus = customerStatus;
208 public String getCustomerConfirmKey () {
209 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
213 public void setCustomerConfirmKey (final String customerConfirmKey) {
214 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
218 public Contact getCustomerContact () {
219 return this.customerContact;
223 public void setCustomerContact (final Contact customerContact) {
224 this.customerContact = customerContact;
228 @SuppressWarnings ("ReturnOfDateField")
229 public Date getCustomerCreated () {
230 return this.customerCreated;
234 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
235 public void setCustomerCreated (final Date customerCreated) {
236 this.customerCreated = customerCreated;
240 public Long getCustomerId () {
241 return this.customerId;
245 public void setCustomerId (final Long customerId) {
246 this.customerId = customerId;
250 @SuppressWarnings ("ReturnOfDateField")
251 public Date getCustomerLastLocked () {
252 return this.customerLastLocked;
256 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
257 public void setCustomerLastLocked (final Date customerLastLocked) {
258 this.customerLastLocked = customerLastLocked;
262 public String getCustomerLastLockedReason () {
263 return this.customerLastLockedReason;
267 public void setCustomerLastLockedReason (final String customerLastLockedReason) {
268 this.customerLastLockedReason = customerLastLockedReason;
272 public String getCustomerNumber () {
273 return this.customerNumber;
277 public void setCustomerNumber (final String customerNumber) {
278 this.customerNumber = customerNumber;
282 public String getCustomerPasswordHash () {
283 throw new UnsupportedOperationException("Unfinished"); //NOI18N
287 public void setCustomerPasswordHash (final String customerPasswordHash) {
288 throw new UnsupportedOperationException("Unfinished"); //NOI18N
292 @SuppressWarnings ("ReturnOfDateField")
293 public Date getCustomerUpdated () {
294 return this.customerUpdated;
298 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
299 public void setCustomerUpdated (final Date customerUpdated) {
300 this.customerUpdated = customerUpdated;