--- /dev/null
+/*
+ * Copyright (C) 2016 quix0r
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.email_address;
+
+import java.io.Serializable;
+import java.util.Calendar;
+import org.mxchange.jusercore.model.email_address.status.EmailChangeStatus;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A POJI for email address changes. This is required to have the user confirm
+ * the change (avoids abuse a bit).
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public interface ChangeableEmailAddress extends Serializable {
+
+ /**
+ * Getter for email change id
+ * <p>
+ * @return Email change id
+ */
+ Long getEmailChangeId ();
+
+ /**
+ * Setter for email change id
+ * <p>
+ * @param emailChangeId Email change id
+ */
+ void setEmailChangeId (final Long emailChangeId);
+
+ /**
+ * Getter for email address to change to
+ * <p>
+ * @return Email address to change to
+ */
+ String getEmailAddress ();
+
+ /**
+ * Setter for email address to change to
+ * <p>
+ * @param emailAddress Email address to change to
+ */
+ void setEmailAddress (final String emailAddress);
+
+ /**
+ * Getter for created "email change" timestamp
+ * <p>
+ * @return Created "email change" timestamp
+ */
+ Calendar getEmailChangeCreated ();
+
+ /**
+ * Setter for created "email change" timestamp
+ * <p>
+ * @param emailChangeCreated Created "email change" timestamp
+ */
+ void setEmailChangeCreated (final Calendar emailChangeCreated);
+
+ /**
+ * Getter for user initiating the email change
+ * <p>
+ * @return User initiating the email change
+ */
+ User getEmailChangeUser ();
+
+ /**
+ * Setter for user initiating the email change
+ * <p>
+ * @param emailChangeUser User initiating the email change
+ */
+ void setEmailChangeUser (final User emailChangeUser);
+
+ /**
+ * Getter for email change done/undone
+ * <p>
+ * @return Email change done/undone
+ */
+ Calendar getEmailChangeDone ();
+
+ /**
+ * Setter for email change done/undone
+ * <p>
+ * @param emailChangeDone Email change done/undone
+ */
+ void setEmailChangeDone (final Calendar emailChangeDone);
+
+ /**
+ * Getter for email change status
+ * <p>
+ * @return Email change status
+ */
+ EmailChangeStatus getEmailChangeStatus ();
+
+ /**
+ * Setter for email change status
+ * <p>
+ * @param emailChangeStatus Email change status
+ */
+ void setEmailChangeStatus (final EmailChangeStatus emailChangeStatus);
+
+ @Override
+ boolean equals (final Object object);
+
+ @Override
+ int hashCode ();
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 quix0r
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.email_address;
+
+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.Index;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import org.mxchange.jusercore.model.email_address.status.EmailChangeStatus;
+import org.mxchange.jusercore.model.user.LoginUser;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A POJO for changing email addresses.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Entity (name = "email_changes")
+@Table (
+ name = "email_changes",
+ indexes = {
+ @Index (name = "email_change_user", columnList = "email_change_user")
+ }
+)
+public class EmailAddressChange implements ChangeableEmailAddress, Comparable<ChangeableEmailAddress> {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 398_459_287_176_139L;
+
+ /**
+ * Email address to change to
+ */
+ @Basic (optional = false)
+ @Column (name = "email_address", length = 100, nullable = false, updatable = false)
+ private String emailAddress;
+
+ /**
+ * Timestamp when this change has been added
+ */
+ @Basic (optional = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "email_change_created", nullable = false, updatable = false)
+ private Calendar emailChangeCreated;
+
+ /**
+ * Timestamp when this change has been done or undone
+ */
+ @Basic (optional = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "email_change_done", nullable = false, updatable = false)
+ private Calendar emailChangeDone;
+
+ /**
+ * Email change id
+ */
+ @Id
+ @GeneratedValue (strategy = GenerationType.IDENTITY)
+ @Column (name = "email_change_id", length = 20, nullable = false, updatable = false)
+ private Long emailChangeId;
+
+ /**
+ * Email change status
+ */
+ @Basic (optional = false)
+ @Column (name = "email_change_status", nullable = false, updatable = false)
+ @Enumerated (EnumType.STRING)
+ private EmailChangeStatus emailChangeStatus;
+
+ /**
+ * User initiating the email change
+ */
+ @Basic (optional = false)
+ @Column (name = "email_change_user_id", length = 20, nullable = false, updatable = false)
+ @OneToOne (targetEntity = LoginUser.class, optional = false, cascade = CascadeType.REFRESH)
+ private User emailChangeUser;
+
+ /**
+ * Default constructor
+ */
+ public EmailAddressChange () {
+ // Set default email change status
+ this.emailChangeStatus = EmailChangeStatus.NEW;
+ }
+
+ @Override
+ public int compareTo (final ChangeableEmailAddress emailAddress) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public boolean equals (final Object object) {
+ if (this == object) {
+ return true;
+ } else if (object == null) {
+ return false;
+ } else if (this.getClass() != object.getClass()) {
+ return false;
+ }
+
+ final ChangeableEmailAddress otherEmail = (ChangeableEmailAddress) object;
+
+ if (!Objects.equals(this.getEmailChangeId(), otherEmail.getEmailChangeId())) {
+ return false;
+ }
+
+ return Objects.equals(this.getEmailChangeUser(), otherEmail.getEmailChangeUser());
+ }
+
+ @Override
+ public int hashCode () {
+ int hash = 5;
+ hash = 71 * hash + Objects.hashCode(this.emailChangeId);
+ hash = 71 * hash + Objects.hashCode(this.emailChangeUser);
+ return hash;
+ }
+
+ @Override
+ public String getEmailAddress () {
+ return this.emailAddress;
+ }
+
+ @Override
+ public void setEmailAddress (final String emailAddress) {
+ this.emailAddress = emailAddress;
+ }
+
+ @Override
+ public Calendar getEmailChangeCreated () {
+ return this.emailChangeCreated;
+ }
+
+ @Override
+ public void setEmailChangeCreated (final Calendar emailChangeCreated) {
+ this.emailChangeCreated = emailChangeCreated;
+ }
+
+ @Override
+ public Calendar getEmailChangeDone () {
+ return this.emailChangeDone;
+ }
+
+ @Override
+ public void setEmailChangeDone (final Calendar emailChangeDone) {
+ this.emailChangeDone = emailChangeDone;
+ }
+
+ @Override
+ public Long getEmailChangeId () {
+ return this.emailChangeId;
+ }
+
+ @Override
+ public void setEmailChangeId (final Long emailChangeId) {
+ this.emailChangeId = emailChangeId;
+ }
+
+ @Override
+ public EmailChangeStatus getEmailChangeStatus () {
+ return this.emailChangeStatus;
+ }
+
+ @Override
+ public void setEmailChangeStatus (final EmailChangeStatus emailChangeStatus) {
+ this.emailChangeStatus = emailChangeStatus;
+ }
+
+ @Override
+ public User getEmailChangeUser () {
+ return this.emailChangeUser;
+ }
+
+ @Override
+ public void setEmailChangeUser (final User emailChangeUser) {
+ this.emailChangeUser = emailChangeUser;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jusercore.model.email_address.status;
+
+import java.io.Serializable;
+
+/**
+ * An enumeration for email changing
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public enum EmailChangeStatus implements Serializable {
+
+ /**
+ * Newly added address (default)
+ *//**
+ * Newly added address (default)
+ */
+ NEW("EMAIL_CHANGE_STATUS_NEW"), //NOI18N
+
+ /**
+ * User changed to this address
+ */
+ CHANGED("EMAIL_CHANGE_STATUS_CHANGED"), //NOI18N
+
+ /**
+ * Has withdrawn the action
+ */
+ WITHDRAWN("EMAIL_CHANGE_STATUS_WITHDRAWN"), //NOI18N
+
+ /**
+ * User has "deleted" the entry. This is not done to keep a history of email changes.
+ */
+ DELETED("EMAIL_CHANGE_STATUS_DELETED"); //NOI18N
+
+ /**
+ * Message key
+ */
+ private final String messageKey;
+
+ /**
+ * Constructor with i18n translation key
+ * <p>
+ * @param messageKey Message key (i18n)
+ */
+ private EmailChangeStatus (final String messageKey) {
+ // Set it here
+ this.messageKey = messageKey;
+ }
+
+ /**
+ * Output value (for messages)
+ * <p>
+ * @return the messageKey
+ */
+ public String getMessageKey () {
+ return this.messageKey;
+ }
+
+}