--- /dev/null
+/*
+ * Copyright (C) 2016, 2017 Roland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcustomercore.model.customer;
+
+import java.util.Calendar;
+import java.util.Objects;
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.Transient;
+import org.mxchange.jcontacts.contact.Contact;
+import org.mxchange.jcontacts.contact.UserContact;
+import org.mxchange.jcustomercore.model.customer.Customer;
+import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
+
+/**
+ * A customer entity
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Entity (name = "customer")
+@Table (
+ name = "customer"
+)
+@NamedQueries (
+ {
+ @NamedQuery (name = "AllCustomers", query = "SELECT c FROM customer AS c ORDER BY c.customerId ASC"),
+ @NamedQuery (name = "SearchCustomerByNumber", query = "SELECT c FROM customer AS c WHERE c.customerNumber = :customerNumber"),
+ @NamedQuery (name = "SearchCustomerById", query = "SELECT c FROM customer AS c WHERE c.customerId = :customerId")
+ }
+)
+@SuppressWarnings ("PersistenceUnitPresent")
+public class ContactCustomer implements Customer {
+
+ /**
+ * Serial number
+ */
+ @Transient
+ private static final long serialVersionUID = 14_857_923_178_504_617L;
+
+ /**
+ * Account status for this customer
+ */
+ @Basic (optional = false)
+ @Enumerated (EnumType.STRING)
+ @Column (name = "customer_status", nullable = false)
+ private CustomerAccountStatus customerAccountStatus;
+
+ /**
+ * Contact instance (personal data)
+ */
+ @JoinColumn (name = "customer_contact_id", nullable = false, updatable = false, unique = true)
+ @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.ALL, optional = false)
+ private Contact customerContact;
+
+ /**
+ * When this customer has been created
+ */
+ @Basic (optional = false)
+ @Column (name = "customer_created", nullable = false, updatable = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ private Calendar customerCreated;
+
+ /**
+ * Id number for this entry
+ */
+ @Id
+ @GeneratedValue (strategy = GenerationType.IDENTITY)
+ @Column (name = "customer_id", nullable = false, updatable = false)
+ private Long customerId;
+
+ /**
+ * When this customer has been locked (last timestamp)
+ */
+ @Column (name = "customer_last_locked")
+ @Temporal (TemporalType.TIMESTAMP)
+ private Calendar customerLastLocked;
+
+ /**
+ * Last locked reason
+ */
+ @Lob
+ @Column (name = "customer_last_locked_reason")
+ private String customerLastLockedReason;
+
+ /**
+ * Customer number
+ */
+ @Basic (optional = false)
+ @Column (name = "customer_number", nullable = false, updatable = false, unique = true)
+ private String customerNumber;
+
+ /**
+ * When this customer has been updated
+ */
+ @Column (name = "customer_updated")
+ @Temporal (TemporalType.TIMESTAMP)
+ private Calendar customerUpdated;
+
+ /**
+ * Default constructor
+ */
+ public ContactCustomer () {
+ }
+
+ /**
+ * Constructor with account status, contact instance and customer number
+ * <p>
+ * @param customerAccountStatus Account status (Call-agents may only call
+ * unlocked accounts)
+ * @param customerContact Contact instance
+ * @param customerNumber Customer number
+ */
+ public ContactCustomer (final CustomerAccountStatus customerAccountStatus, final Contact customerContact, final String customerNumber) {
+ // Call other constructor
+ this();
+
+ // Set all parameter
+ this.customerAccountStatus = customerAccountStatus;
+ this.customerContact = customerContact;
+ this.customerNumber = customerNumber;
+ }
+
+ @Override
+ public void copyAll (final Customer customer) {
+ // Copy all supported fields
+ this.setCustomerAccountStatus(customer.getCustomerAccountStatus());
+ this.setCustomerContact(customer.getCustomerContact());
+ this.setCustomerCreated(customer.getCustomerCreated());
+ this.setCustomerId(customer.getCustomerId());
+ this.setCustomerLastLocked(customer.getCustomerLastLocked());
+ this.setCustomerLastLockedReason(customer.getCustomerLastLockedReason());
+ this.setCustomerNumber(customer.getCustomerNumber());
+ }
+
+ @Override
+ public boolean equals (final Object object) {
+ if (this == object) {
+ return true;
+ } else if (null == object) {
+ return false;
+ } else if (this.getClass() != object.getClass()) {
+ return false;
+ }
+
+ final Customer other = (Customer) object;
+
+ if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
+ return false;
+ } else if (!Objects.equals(this.getCustomerContact(), other.getCustomerContact())) {
+ return false;
+ } else if (!Objects.equals(this.getCustomerId(), other.getCustomerId())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode () {
+ int hash = 7;
+
+ hash = 53 * hash + Objects.hashCode(this.getCustomerContact());
+ hash = 53 * hash + Objects.hashCode(this.getCustomerId());
+ hash = 53 * hash + Objects.hashCode(this.getCustomerNumber());
+
+ return hash;
+ }
+
+ @Override
+ public CustomerAccountStatus getCustomerAccountStatus () {
+ return this.customerAccountStatus;
+ }
+
+ @Override
+ public void setCustomerAccountStatus (final CustomerAccountStatus customerStatus) {
+ this.customerAccountStatus = customerStatus;
+ }
+
+ @Override
+ public String getCustomerConfirmKey () {
+ throw new UnsupportedOperationException("Not supported yet."); //NOI18N
+ }
+
+ @Override
+ public void setCustomerConfirmKey (final String customerConfirmKey) {
+ throw new UnsupportedOperationException("Not supported yet."); //NOI18N
+ }
+
+ @Override
+ public Contact getCustomerContact () {
+ return this.customerContact;
+ }
+
+ @Override
+ public void setCustomerContact (final Contact customerContact) {
+ this.customerContact = customerContact;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Calendar getCustomerCreated () {
+ return this.customerCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setCustomerCreated (final Calendar customerCreated) {
+ this.customerCreated = customerCreated;
+ }
+
+ @Override
+ public Long getCustomerId () {
+ return this.customerId;
+ }
+
+ @Override
+ public void setCustomerId (final Long customerId) {
+ this.customerId = customerId;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Calendar getCustomerLastLocked () {
+ return this.customerLastLocked;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setCustomerLastLocked (final Calendar customerLastLocked) {
+ this.customerLastLocked = customerLastLocked;
+ }
+
+ @Override
+ public String getCustomerLastLockedReason () {
+ return this.customerLastLockedReason;
+ }
+
+ @Override
+ public void setCustomerLastLockedReason (final String customerLastLockedReason) {
+ this.customerLastLockedReason = customerLastLockedReason;
+ }
+
+ @Override
+ public String getCustomerNumber () {
+ return this.customerNumber;
+ }
+
+ @Override
+ public void setCustomerNumber (final String customerNumber) {
+ this.customerNumber = customerNumber;
+ }
+
+ @Override
+ public String getCustomerPasswordHash () {
+ throw new UnsupportedOperationException("Unfinished"); //NOI18N
+ }
+
+ @Override
+ public void setCustomerPasswordHash (final String customerPasswordHash) {
+ throw new UnsupportedOperationException("Unfinished"); //NOI18N
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Calendar getCustomerUpdated () {
+ return this.customerUpdated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setCustomerUpdated (final Calendar customerUpdated) {
+ this.customerUpdated = customerUpdated;
+ }
+
+}