/**
*
*/
package com.cin.dto;
import java.io.Serializable;
import com.cin.entity.Userrecord;
/**
* @author arunsanjay
*
*/
public class UserDTO implements Comparable<UserDTO>, Serializable {
private static final long serialVersionUID = 8600954622968931085L;
private int age;
private String birthCountry;
private String citizenship;
private String detail;
private EducationDTO education;
private EmploymentStatusDTO employmentStatus;
private String fatherOrigin;
private String householdDetail;
private InvestmentDTO investmentDetails;
private JobDTO jobDetails;
private String marital;
private MigrationDTO migration;
private String motherOrigin;
private String name;
private String race;
private YouthDTO youth;
private boolean likelinessFactor;
/**
* @return the likelinessFactor
*/
public boolean isLikelinessFactor() {
return likelinessFactor;
}
/**
* @param likelinessFactor the likelinessFactor to set
*/
public void setLikelinessFactor(boolean likelinessFactor) {
this.likelinessFactor = likelinessFactor;
}
private String sex;
private int ssn;
private String taxStatus;
private String zipCode;
private int score;
private int income;
public UserDTO() {
}
public UserDTO(int ssn){
setSsn( ssn );
}
public UserDTO(Userrecord entity) {
setAge( entity.getAge() );
setBirthCountry( entity.getBirthcountry() );
setCitizenship( entity.getCitizenship() );
setDetail( entity.getDetail() );
if(entity.getEducation() != null) {
setEducation( new EducationDTO(entity.getEducation()) );
}
if(entity.getEmploymentstat() != null) {
setEmploymentStatus( new EmploymentStatusDTO(entity.getEmploymentstat()) );
}
setFatherOrigin( entity.getFatherorigin() );
setHouseholdDetail( entity.getHouseholddetail() );
if(entity.getInvestment() != null) {
setInvestmentDetails( new InvestmentDTO(entity.getInvestment()) );
}
if(entity.getJob() != null) {
setJobDetails( new JobDTO(entity.getJob()) );
}
setMarital( entity.getMarital() );
if(entity.getMigration() != null) {
setMigration( new MigrationDTO(entity.getMigration()) );
}
setMotherOrigin( entity.getMotherorigin() );
setName( entity.getName() );
setRace( entity.getRace() );
setSex( entity.getSex() );
setSsn( entity.getSsn() );
setTaxStatus( entity.getTaxstat() );
if(entity.getYouth() != null ){
setYouth( new YouthDTO(entity.getYouth()) );
}
setZipCode( entity.getZip() );
this.calculateIncome();
}
public int incomeFromPay() {
int aSalary = 0;
if(this.jobDetails != null) {
aSalary = this.jobDetails.getWeekWage() * this.jobDetails.getWorkWeeks();
}
return aSalary;
}
public int incomeFromInvestment() {
int anInvestmentIncome = 0;
if(this.investmentDetails != null) {
anInvestmentIncome = this.investmentDetails.getCapitalGains() -
this.investmentDetails.getCapitalLosses();
}
return anInvestmentIncome;
}
public void calculateIncome(){
this.income = this.incomeFromPay() + this.incomeFromInvestment();
}
public boolean isSingle() {
if(this.getMarital().equalsIgnoreCase("Never Married")) {
return true;
}
return false;
}
public boolean isUnemployed() {
if(this.getEmploymentStatus()!= null) {
String aStatus = this.getEmploymentStatus().getEmploymentStatus().toUpperCase();
return aStatus.contains("UNEMPLOYED");
}
return false;
}
/**
* @return the income
*/
public int getIncome() {
return income;
}
/**
* @param income the income to set
*/
public void setIncome(int income) {
if(income >= 0)
this.income = income;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @return the birthCountry
*/
public String getBirthCountry() {
return birthCountry;
}
/**
* @return the citizenship
*/
public String getCitizenship() {
return citizenship;
}
/**
* @return the detail
*/
public String getDetail() {
return detail;
}
/**
* @return the education
*/
public EducationDTO getEducation() {
return education;
}
/**
* @return the employmentStatus
*/
public EmploymentStatusDTO getEmploymentStatus() {
return employmentStatus;
}
/**
* @return the fatherOrigin
*/
public String getFatherOrigin() {
return fatherOrigin;
}
/**
* @return the householdDetail
*/
public String getHouseholdDetail() {
return householdDetail;
}
/**
* @return the investmentDetails
*/
public InvestmentDTO getInvestmentDetails() {
return investmentDetails;
}
/**
* @return the jobDetails
*/
public JobDTO getJobDetails() {
return jobDetails;
}
/**
* @return the marital
*/
public String getMarital() {
return marital;
}
/**
* @return the migration
*/
public MigrationDTO getMigration() {
return migration;
}
/**
* @return the motherOrigin
*/
public String getMotherOrigin() {
return motherOrigin;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the race
*/
public String getRace() {
return race;
}
/**
* @return the sex
*/
public String getSex() {
return sex;
}
/**
* @return the ssn
*/
public int getSsn() {
return ssn;
}
/**
* @return the taxStatus
*/
public String getTaxStatus() {
return taxStatus;
}
/**
* @return the zipCode
*/
public String getZipCode() {
return zipCode;
}
/**
* @param age
* the age to set
*/
public void setAge(final int age) {
this.age = age;
}
/**
* @param birthCountry
* the birthCountry to set
*/
public void setBirthCountry(final String birthCountry) {
if( birthCountry == null ){
this.birthCountry = null;
} else {
this.birthCountry = birthCountry.trim();
}
}
/**
* @param citizenship
* the citizenship to set
*/
public void setCitizenship(final String citizenship) {
if( citizenship == null ){
this.citizenship = null;
} else {
this.citizenship = citizenship.trim();
}
}
/**
* @param detail
* the detail to set
*/
public void setDetail(final String detail) {
if( detail == null ){
this.detail = null;
} else {
this.detail = detail.trim();
}
}
/**
* @param education
* the education to set
*/
public void setEducation(final EducationDTO education) {
this.education = education;
}
/**
* @param employmentStatus
* the employmentStatus to set
*/
public void setEmploymentStatus(final EmploymentStatusDTO employmentStatus) {
this.employmentStatus = employmentStatus;
}
/**
* @param fatherOrigin
* the fatherOrigin to set
*/
public void setFatherOrigin(final String fatherOrigin) {
if( fatherOrigin == null ){
this.fatherOrigin = null;
} else {
this.fatherOrigin = fatherOrigin.trim();
}
}
/**
* @param householdDetail
* the householdDetail to set
*/
public void setHouseholdDetail(final String householdDetail) {
if( householdDetail == null ){
this.householdDetail = null;
} else {
this.householdDetail = householdDetail.trim();
}
}
/**
* @param investmentDetails
* the investmentDetails to set
*/
public void setInvestmentDetails(final InvestmentDTO investmentDetails) {
this.investmentDetails = investmentDetails;
}
/**
* @param jobDetails
* the jobDetails to set
*/
public void setJobDetails(final JobDTO jobDetails) {
this.jobDetails = jobDetails;
}
/**
* @param marital
* the marital to set
*/
public void setMarital(final String marital) {
if( marital == null ){
this.marital = null;
} else {
this.marital = marital.trim();
}
}
/**
* @param migration
* the migration to set
*/
public void setMigration(final MigrationDTO migration) {
this.migration = migration;
}
/**
* @param motherOrigin
* the motherOrigin to set
*/
public void setMotherOrigin(final String motherOrigin) {
if( motherOrigin == null ){
this.motherOrigin = null;
} else {
this.motherOrigin = motherOrigin.trim();
}
}
/**
* @param name
* the name to set
*/
public void setName(final String name) {
if( name == null ){
this.name = null;
} else {
this.name = name.trim();
}
}
/**
* @param race
* the race to set
*/
public void setRace(final String race) {
if( race == null ){
this.race = null;
} else {
this.race = race.trim();
}
}
/**
* @param sex
* the sex to set
*/
public void setSex(final String sex) {
if( sex == null ){
this.sex = null;
} else {
this.sex = sex.trim();
}
}
/**
* @param ssn
* the ssn to set
*/
public void setSsn(final int ssn) {
this.ssn = ssn;
}
/**
* @param taxStatus
* the taxStatus to set
*/
public void setTaxStatus(final String taxStatus) {
if( taxStatus == null ){
this.taxStatus = null;
} else {
this.taxStatus = taxStatus.trim();
}
}
/**
* @param zipCode
* the zipCode to set
*/
public void setZipCode(final String zipCode) {
if( zipCode == null ){
this.zipCode = null;
} else {
this.zipCode = zipCode.trim();
}
}
/**
* @return the score
*/
public int getScore() {
return score;
}
/**
* @param score the score to set
*/
public void setScore(int score) {
if(score >= 0)
this.score = score;
}
public boolean isMaterialized() {
if(this.education == null) {
return false;
}
if(this.jobDetails == null) {
return false;
}
if(this.employmentStatus == null) {
return false;
}
if(this.investmentDetails == null) {
return false;
}
if(this.migration == null) {
return false;
}
if(this.youth == null){
return false;
}
return true;
}
public YouthDTO getYouth(){
return youth;
}
public void setYouth(YouthDTO youth){
this.youth = youth;
}
public int compareTo(UserDTO other) {
if( this.ssn > other.ssn){
return 1;
} else if( this.ssn == other.ssn ){
return 0;
} else if( this.ssn < other.ssn ){
return -1;
} else {
assert false;
return 0;
}
}
public Userrecord toEJB(){
Userrecord ejb = new Userrecord();
ejb.setAge(age);
ejb.setBirthcountry(birthCountry);
ejb.setCitizenship(citizenship);
ejb.setDetail(detail);
if( education != null ){
ejb.setEducation(education.toEJB(ssn));
}
if( employmentStatus != null ){
ejb.setEmploymentstat(employmentStatus.toEJB(ssn));
}
ejb.setFatherorigin(fatherOrigin);
ejb.setHouseholddetail(householdDetail);
if( investmentDetails != null){
ejb.setInvestment(investmentDetails.toEJB(ssn));
}
if( jobDetails != null ){
ejb.setJob(jobDetails.toEJB(ssn));
}
ejb.setMarital(marital);
if( migration != null ){
ejb.setMigration(migration.toEJB(ssn));
}
ejb.setMotherorigin(motherOrigin);
ejb.setName(name);
ejb.setRace(race);
ejb.setSex(sex);
ejb.setSsn(ssn);
ejb.setTaxstat(taxStatus);
if( youth != null ){
ejb.setYouth(youth.toEJB(ssn));
}
ejb.setZip(zipCode);
return ejb;
}
}