/******************************************************************************* * Open Behavioral Health Information Technology Architecture (OBHITA.org) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package gov.samhsa.consent2share.domain.staff; import flexjson.JSONDeserializer; import flexjson.JSONSerializer; import gov.samhsa.consent2share.domain.reference.AdministrativeGenderCode; import java.util.Collection; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.Version; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.hibernate.envers.Audited; import org.hibernate.envers.RelationTargetAuditMode; /** * The Class Patient. */ @Entity @Audited public class Staff { /** The first name. */ @NotNull @Size(min = 2, max = 30) private String firstName; /** The last name. */ @NotNull @Size(min = 2, max = 30) private String lastName; /** The email. */ @Pattern(regexp = "^[\\w-]+(\\.[\\w-]+)*@([a-z0-9-]+(\\.[a-z0-9-]+)*?\\.[a-z]{2,6}|(\\d{1,3}\\.){3}\\d{1,3})(:\\d{4})?$") private String email; /** The username. */ @Size(min = 3, max = 30) private String username; /** The employee id. */ private String employeeID; /** The administrative gender code. */ @ManyToOne @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) private AdministrativeGenderCode administrativeGenderCode; /** The id. */ @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; /** The version. */ @Version @Column(name = "version") private Integer version; /** * To string. * * @return the string */ public String toString() { return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE); } /** * To json. * * @return the string */ public String toJson() { return new JSONSerializer().exclude("*.class").deepSerialize(this); } /** * From json to patient. * * @param json * the json * @return the patient */ public static Staff fromJsonToAdministrator(String json) { return new JSONDeserializer<Staff>().use(null, Staff.class) .deserialize(json); } /** * To json array. * * @param collection * the collection * @return the string */ public static String toJsonArray(Collection<Staff> collection) { return new JSONSerializer().exclude("*.class") .deepSerialize(collection); } /** * Gets the first name. * * @return the first name */ public String getFirstName() { return firstName; } /** * Sets the first name. * * @param firstName the new first name */ public void setFirstName(String firstName) { this.firstName = firstName; } /** * Gets the last name. * * @return the last name */ public String getLastName() { return lastName; } /** * Sets the last name. * * @param lastName the new last name */ public void setLastName(String lastName) { this.lastName = lastName; } /** * Gets the email. * * @return the email */ public String getEmail() { return email; } /** * Sets the email. * * @param email the new email */ public void setEmail(String email) { this.email = email; } /** * Gets the username. * * @return the username */ public String getUsername() { return username; } /** * Sets the username. * * @param username the new username */ public void setUsername(String username) { this.username = username; } /** * Gets the employee id. * * @return the employee id */ public String getEmployeeID() { return employeeID; } /** * Sets the employee id. * * @param employeeID the new employee id */ public void setEmployeeID(String employeeID) { this.employeeID = employeeID; } /** * Gets the administrative gender code. * * @return the administrative gender code */ public AdministrativeGenderCode getAdministrativeGenderCode() { return administrativeGenderCode; } /** * Sets the administrative gender code. * * @param administrativeGenderCode the new administrative gender code */ public void setAdministrativeGenderCode( AdministrativeGenderCode administrativeGenderCode) { this.administrativeGenderCode = administrativeGenderCode; } /** * Gets the id. * * @return the id */ public Long getId() { return id; } /** * Sets the id. * * @param id the new id */ public void setId(Long id) { this.id = id; } /** * Gets the version. * * @return the version */ public Integer getVersion() { return version; } /** * Sets the version. * * @param version the new version */ public void setVersion(Integer version) { this.version = version; } /** * Hash code. * * @return the int */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } /** * Equals. * * @param obj * the obj * @return true, if successful */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Staff other = (Staff) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } }