From: Roland Haeder Date: Fri, 11 Mar 2016 21:03:46 +0000 (+0100) Subject: added new email change entity with enumeration for change status X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d0aafcfbfaf88801888e1e6ea00c67d0cbceebc9;p=juser-login-core.git added new email change entity with enumeration for change status --- diff --git a/src/org/mxchange/jusercore/model/email_address/ChangeableEmailAddress.java b/src/org/mxchange/jusercore/model/email_address/ChangeableEmailAddress.java new file mode 100644 index 0000000..a672c2b --- /dev/null +++ b/src/org/mxchange/jusercore/model/email_address/ChangeableEmailAddress.java @@ -0,0 +1,121 @@ +/* + * 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 . + */ +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). + *

+ * @author Roland Haeder + */ +public interface ChangeableEmailAddress extends Serializable { + + /** + * Getter for email change id + *

+ * @return Email change id + */ + Long getEmailChangeId (); + + /** + * Setter for email change id + *

+ * @param emailChangeId Email change id + */ + void setEmailChangeId (final Long emailChangeId); + + /** + * Getter for email address to change to + *

+ * @return Email address to change to + */ + String getEmailAddress (); + + /** + * Setter for email address to change to + *

+ * @param emailAddress Email address to change to + */ + void setEmailAddress (final String emailAddress); + + /** + * Getter for created "email change" timestamp + *

+ * @return Created "email change" timestamp + */ + Calendar getEmailChangeCreated (); + + /** + * Setter for created "email change" timestamp + *

+ * @param emailChangeCreated Created "email change" timestamp + */ + void setEmailChangeCreated (final Calendar emailChangeCreated); + + /** + * Getter for user initiating the email change + *

+ * @return User initiating the email change + */ + User getEmailChangeUser (); + + /** + * Setter for user initiating the email change + *

+ * @param emailChangeUser User initiating the email change + */ + void setEmailChangeUser (final User emailChangeUser); + + /** + * Getter for email change done/undone + *

+ * @return Email change done/undone + */ + Calendar getEmailChangeDone (); + + /** + * Setter for email change done/undone + *

+ * @param emailChangeDone Email change done/undone + */ + void setEmailChangeDone (final Calendar emailChangeDone); + + /** + * Getter for email change status + *

+ * @return Email change status + */ + EmailChangeStatus getEmailChangeStatus (); + + /** + * Setter for email change status + *

+ * @param emailChangeStatus Email change status + */ + void setEmailChangeStatus (final EmailChangeStatus emailChangeStatus); + + @Override + boolean equals (final Object object); + + @Override + int hashCode (); +} diff --git a/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java b/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java new file mode 100644 index 0000000..e039b2c --- /dev/null +++ b/src/org/mxchange/jusercore/model/email_address/EmailAddressChange.java @@ -0,0 +1,205 @@ +/* + * 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 . + */ +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. + *

+ * @author Roland Haeder + */ +@Entity (name = "email_changes") +@Table ( + name = "email_changes", + indexes = { + @Index (name = "email_change_user", columnList = "email_change_user") + } +) +public class EmailAddressChange implements ChangeableEmailAddress, Comparable { + + /** + * 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; + } + +} diff --git a/src/org/mxchange/jusercore/model/email_address/status/EmailChangeStatus.java b/src/org/mxchange/jusercore/model/email_address/status/EmailChangeStatus.java new file mode 100644 index 0000000..5322ded --- /dev/null +++ b/src/org/mxchange/jusercore/model/email_address/status/EmailChangeStatus.java @@ -0,0 +1,74 @@ +/* + * 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 . + */ +package org.mxchange.jusercore.model.email_address.status; + +import java.io.Serializable; + +/** + * An enumeration for email changing + *

+ * @author Roland Haeder + */ +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 + *

+ * @param messageKey Message key (i18n) + */ + private EmailChangeStatus (final String messageKey) { + // Set it here + this.messageKey = messageKey; + } + + /** + * Output value (for messages) + *

+ * @return the messageKey + */ + public String getMessageKey () { + return this.messageKey; + } + +} diff --git a/src/org/mxchange/jusercore/model/user/User.java b/src/org/mxchange/jusercore/model/user/User.java index 5a6ec78..4956567 100644 --- a/src/org/mxchange/jusercore/model/user/User.java +++ b/src/org/mxchange/jusercore/model/user/User.java @@ -23,7 +23,7 @@ import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; /** - * A customer interface + * A user POPJI *

* @author Roland Haeder */ diff --git a/src/org/mxchange/jusercore/model/user/status/UserAccountStatus.java b/src/org/mxchange/jusercore/model/user/status/UserAccountStatus.java index 46cbe10..328f124 100644 --- a/src/org/mxchange/jusercore/model/user/status/UserAccountStatus.java +++ b/src/org/mxchange/jusercore/model/user/status/UserAccountStatus.java @@ -19,7 +19,7 @@ package org.mxchange.jusercore.model.user.status; import java.io.Serializable; /** - * An enum for user's account status like confirmed, locked, etc. + * An enumeration for user's account status like confirmed, locked, etc. *

* @author Roland Haeder */ @@ -36,7 +36,7 @@ public enum UserAccountStatus implements Serializable { CONFIRMED("USER_ACCOUNT_STATUS_CONFIRMED"), //NOI18N /** - * Locked (maybe violeted T&C) + * Locked (maybe violated T&C) */ LOCKED("USER_ACCOUNT_STATUS_LOCKED"); //NOI18N