public UserDTO calculateLikelinessFactor(UserDTO pUser) throws MissingInformationException,PersistenceException {
UserDTO user = userFactory.findUserBySsn(pUser.getSsn());
StatisticsService aStatsService = new StatisticsService();
StatisticsDTO aUserStateStats = new StatisticsDTO();
if(user.getZipCode() == null || user.getZipCode().trim().length() > 0) {
throw new MissingInformationException("Location information is missing for user.Update the info and calculate the factor");
}
if(user.getJobDetails() != null) {
ZipDTO zip = aRemote.findStateForZip(Integer.parseInt(user.getZipCode()));
if(zip != null) {
aUserStateStats.setState(zip.getState());
}
aUserStateStats.setIndustryCode(user.getJobDetails().getIndustryCode());
aUserStateStats.setOccCode(user.getJobDetails().getOccupationCode());
}
GenericResponse aResponse = aStatsService.calculateWeeklyWage(aUserStateStats);
int userStateAvgWage = 0;
int numOfStates = 0;
if(aResponse != null && aResponse.getStatistics() != null
&& aResponse.isResponseStatus()) {
userStateAvgWage = aResponse.getStatistics().getAvgWeekWage();
}
List<StateAbbvDTO> theStates = aRemote.findAllStates();
StatisticsDTO otherStatesStats = new StatisticsDTO();
for(StateAbbvDTO aState : theStates) {
String aStateName = aState.getAbbv();
otherStatesStats.setIndustryCode(user.getJobDetails().getIndustryCode());
otherStatesStats.setOccCode(user.getJobDetails().getOccupationCode());
otherStatesStats.setState(aStateName);
aResponse = aStatsService.calculateWeeklyWage(aUserStateStats);
if(aResponse != null && aResponse.getStatistics() != null
&& aResponse.isResponseStatus()) {
if(userStateAvgWage < aResponse.getStatistics().getAvgWeekWage()) {
numOfStates++;
}
}
int aPercentage = 0;
if(theStates.size() > 0)
aPercentage = (numOfStates/theStates.size())*100;
if(aPercentage > ApplicationConstants.ACCEPTABLE_LIMIT_PERCENTAGE) {
user.setLikelinessFactor(true);
}
}
return user;
}