}
}
}
private int getScoreForUserFromDb(UserDTO pDTO) throws MissingInformationException, InvalidInputValueException {
UserDTO user = retrieveUserRecord(pDTO);
int aScore = 0;
if (user.getJobDetails() != null && user.getJobDetails().getWorkClass().equalsIgnoreCase(
ApplicationConstants.FEDERAL_GOVT_EMP)) {
return 100;
}
List<UserDTO> theUsers = null;
if(user.getZipCode() == null || user.getZipCode().equals("")) {
throw new MissingInformationException("User's zip code is not known");
}
String zipCode = user.getZipCode();
if(incomeMap.containsKey(zipCode)) {
theUsers = incomeMap.get(zipCode);
}
else {
theUsers = this.retrieveUserRecordbyZip(zipCode);
if(theUsers != null && !theUsers.isEmpty()) {
incomeMap.put(zipCode, theUsers);
}
}
int aNumCount = 0;
for (UserDTO aDTO : theUsers) {
if (user.getIncome() >= aDTO.getIncome()) {
aNumCount++;
}
}
// TODO what if theUsers.size() == 0; it shouldn't happen... but
if(theUsers.size() > 0) {
float aUserPercentile = (float) aNumCount / (float) theUsers.size();
aScore = Math.round(100 * aUserPercentile);
}
if (user.getSex().equalsIgnoreCase("F")) {
aScore = aScore + ((5 / 100) * aScore);
}
if (user.getJobDetails() != null && !user.getJobDetails().isUnionMember()
&& aScore < ApplicationConstants.THRESHOLD_VALUE) {
int aOccStab = 0;
int indStab = 0;
OccupationDTO occStaticData = this.findOccupationStabilityValue(
user.getJobDetails().getOccupationCode());
if(occStaticData != null) {
aOccStab = occStaticData.getStability();
}
IndustryDTO indStaticData = this.findIndustryStabilityValue(
user.getJobDetails().getIndustryCode());
if(indStaticData != null) {
indStab = indStaticData.getStability();
}
Double aUserStability = Math.sqrt(new Double(aOccStab
* indStab))
* new Double(10);
if (aUserStability > 0 && aUserStability < 10) {
return 0;
} else if (aUserStability > 10 && aUserStability < 60) {
aScore = (int) (aScore * (aUserStability / 80));
if (user.getEducation() != null &&
( user.getEducation().isDoctorate()
|| user.getEducation().isMasters()
|| user.getEducation().isProfesssional()) ) {
aScore = aScore + (aScore * (20 / 100));
}
} else if (aUserStability > 60 && aUserStability < 100) {
aScore = (int) (aScore * (aUserStability / 100));
if (user.getEducation() != null &&
( user.getEducation().isBachelors()
|| user.getEducation().isDoctorate()
|| user.getEducation().isMasters()
|| user.getEducation().isProfesssional()) ) {
aScore = aScore + (aScore * (12 / 100));
}
}
}
/**
* TODO based on capital gains. change @arunsanjay
*/
// check other details
if(user.getIncome() > 0) {
int aPayPercentage = (user.incomeFromPay() / user.getIncome()) * 100;
if ((100 - aPayPercentage) > aPayPercentage) {
aScore = aScore - (aScore * (10 / 100));
}
if (user.isSingle()) {
aScore = aScore + (aScore * (10 / 100));
}
if (user.getAge() >= 65 && user.getIncome() < 5000) {
aScore = 0;
}
}
// return score