Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

/*
* User.java
* Copyright (c) 2017 Veterans Affairs.
*/
package gov.va.oneconsult.seoc.api.model;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

import gov.va.oneconsult.seoc.api.util.Constants;

/**
* User Entity stores user data.
* @author AbleVets
*
*/
@Entity
@Table(name = "seocuser")
@JsonPropertyOrder({ "id", "userName", "role", "vaNetworkId", "domain" })
public final class User
{
/**
* Id value. Guaranteed to be not null. Auto generated value.
*/
@Id
@Column(name = "id")
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonIgnore
private int id;

@Column(name = "username", unique = true)
@NotNull
@Size(min=1, max = 50, message = "User name should not be empty and not exceed 50 characters")
@JsonProperty(value = "userName")
private String userName;

/**
* VaUserId value. Guaranteed to be not null.
*/
@Column(name = "vauserid", unique = true)
@NotNull
@Size(min=1, max = 80, message = "VaUserId should not be empty and not exceed 80 characters")
@JsonIgnore
private String vaUserId;

/**
* Role value.
*/
@Column(name = "role")
@NotNull
@Size(min=1, max = 15, message = "Role should not be empty and not exceed 15 characters")
private String role;

/**
* Deactivated value.
*/
@Column(name = "deactivateddate")
@DateTimeFormat(pattern = "MM-dd-yyyy")
@JsonIgnore
private Date deactivatedDate;

/**
* Event Date. Date value.
*/
@Column(name = "createdate")
@DateTimeFormat(pattern = "MM-dd-yyyy")
@JsonIgnore
private Date createDate;

/**
* Modified Date. Date value.
*/
@Column(name = "modifieddate")
@DateTimeFormat(pattern = "MM-dd-yyyy")
@JsonIgnore
private Date modifiedDate;

/**
* Set {@link ChangeLog} of
*/
@OneToMany(mappedBy = "user", cascade = { CascadeType.DETACH, CascadeType.PERSIST,
CascadeType.REMOVE })
@JsonIgnore
private List<ChangeLog> changeLogs;

/**
* SequenceId used in JSON
*/
@JsonIgnore
@Transient
private int sequenceId;

/**
* Domain part of vaUserId
*/
@JsonIgnore
@Transient
@NotNull
@Size(min=1, max = 25, message = "domain should not be empty and not exceed 25 characters")
private String domain;

/**
* vaNetworkId part of vaUserId
*/
@JsonIgnore
@Transient
@NotNull
@Size(min=1, max = 25, message = "vaNetworkId should not be empty and not exceed 25 characters")
private String vaNetworkId;

/**
* Description:
*
* @return id
*/
public int getId()
{
return id;
}

/**
* Description:
*
* @param id
*/
public void setId(int id)
{
this.id = id;
}

/**
* Description:
* @return String
*/
public String getUserName()
{
return userName;
}

/**
* Description:
* @param userName
*/
public void setUserName(String userName)
{
this.userName = userName;
}

/**
* Description:
*
* @return vaUserId
*/
public String getVaUserId()
{
return vaUserId;
}

/**
* Description:
*
* @param vaUserId
*/
public void setVaUserId(String vaUserId)
{
this.vaUserId = vaUserId;
}

/**
* Description:
*
* @return role
*/
public String getRole()
{
return role;
}

/**
* Description:
*
* @param role
*/
public void setRole(String role)
{
this.role = role;
}

/**
* Description:
*
* @return deactivated
*/
public Date getDeactivatedDate()
{
return deactivatedDate;
}

/**
* Description:
*
* @param deactivated
*/
public void setDeactivatedDate(Date deactivatedDate)
{
this.deactivatedDate = deactivatedDate;
}

/**
* Description:
*
* @return createDate
*/
public Date getCreateDate()
{
return createDate;
}

/**
* Description:
*
* @param createDate
*/
public void setCreateDate(Date createDate)
{
this.createDate = createDate;
}

/**
* Description:
*
* @return modifiedDate
*/
public Date getModifiedDate()
{
return modifiedDate;
}

/**
* Description:
*
* @param modifiedDate
*/
public void setModifiedDate(Date modifiedDate)
{
this.modifiedDate = modifiedDate;
}

/**
* Description:
*
* @return changeLogs
*/
public List<ChangeLog> getChangeLogs()
{
return changeLogs;
}

/**
* Description:
*
* @param changeLogs
*/
public void setChangeLogs(List<ChangeLog> changeLogs)
{
this.changeLogs = changeLogs;
}

/**
* Description:
* @param domain
*/
@Transient
public void setDomain(String domain) {
this.domain = domain;
}

/**
* Description:
* @return String
*/
@Transient
public String getDomain()
{
return this.domain;
}

/**
* Description: Retrieves domain part from the VaUserId. String before '\'
* When '\' not found returns null.
* @return String
*/
@JsonProperty(value="domain")
@Transient
public String getDomainFromVaUserId()
{
String domain = null;

if(vaUserId==null || vaUserId.indexOf("\\")<0) {
return domain;
}

domain = vaUserId.substring(0, vaUserId.indexOf("\\"));

return domain;

}

/**
* Description:
* @param vaNetworkId
*/
@Transient
public void setVaNetworkId(String vaNetworkId)
{
this.vaNetworkId = vaNetworkId;
}

/**
* Description:
* @return String
*/
@Transient
public String getVaNetworkId()
{
return this.vaNetworkId;
}

/**
* Description: Retrieves VaNetworkId part from the VaUserId. String after '\'.
* When '\' not found returns complete vaUserId.
* @return String
*/
@JsonProperty(value="vaNetworkId")
@Transient
public String getVaNetworkIdFromVaUserId()
{
String vaNetworkId = null;

if(vaUserId==null){
return vaNetworkId;
}

if(vaUserId.indexOf("\\")<0){
return vaUserId;
}

vaNetworkId = vaUserId.substring(vaUserId.indexOf("\\")+1);

return vaNetworkId;

}
/**
* Description: Combines domain and vaNetworkId with separator '\'
* @return String
*/
@Transient
public String appendDomainToNetworkId()
{
String vaUserId = (this.domain==null?"":this.domain) + Constants.DOMAIN_SEPARATOR + (this.vaNetworkId==null?"":this.vaNetworkId);

return vaUserId;
}

/**
* Description: Splits vaUserId field of User and sets it in domain and vaNetworkId fields.
*/
@Transient
public void splitDomainAndNetworkId()
{
//Split domain from vaUserId. Set domain field.
setDomain(getDomainFromVaUserId());

//Split vaNetworkId from vaUserId. Set vaNetworkId field.
setVaNetworkId(getVaNetworkIdFromVaUserId());
}

/**
* Description:
* @param seqId
*/
@Transient
public void setSequenceId(int seqId) {
sequenceId = seqId;
}

/**
* Description:
* @return int
*/
@JsonProperty(value = "id")
@Transient
public int getSequenceId() {
return sequenceId;
}


/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((createDate == null) ? 0 : createDate.hashCode());
result = prime * result + ((deactivatedDate == null) ? 0 : deactivatedDate.hashCode());
result = prime * result + id;
result = prime * result + ((modifiedDate == null) ? 0 : modifiedDate.hashCode());
result = prime * result + ((role == null) ? 0 : role.hashCode());
result = prime * result + ((vaUserId == null) ? 0 : vaUserId.hashCode());
result = prime * result + ((userName == null) ? 0 : userName.hashCode());
return result;
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (createDate == null)
{
if (other.createDate != null)
return false;
} else if (!createDate.equals(other.createDate))
return false;
if (deactivatedDate == null)
{
if (other.deactivatedDate != null)
return false;
} else if (!deactivatedDate.equals(other.deactivatedDate))
return false;
if (id != other.id)
return false;
if (modifiedDate == null)
{
if (other.modifiedDate != null)
return false;
} else if (!modifiedDate.equals(other.modifiedDate))
return false;
if (role == null)
{
if (other.role != null)
return false;
} else if (!role.equals(other.role))
return false;
if (userName == null)
{
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
return false;
if (vaUserId == null)
{
if (other.vaUserId != null)
return false;
} else if (!vaUserId.equalsIgnoreCase(other.vaUserId))
return false;
return true;
}

/**
* {@inheritDoc}
*/
@Override
public String toString()
{
return "User [id=" + id + ", vaUserId=" + vaUserId + ", role=" + role + ", deactivatedDate="
+ deactivatedDate + ", createDate=" + createDate + ", modifiedDate=" + modifiedDate
+ "]";
}

}