public void removeAsGuarantor(Investorindividual oldGuarantor) { if (oldGuarantor.getRole().equals(Constants.GUARANTOR)) { if (logger.isDebugEnabled()) { logger.debug("Guarantor to remove is external, so deleting ..."); } Individual individual = oldGuarantor.getIndividual(); individual.getInvestorindividuals().remove(oldGuarantor); // throws lazy error. oldGuarantor.setIndividual(null); this.individualDAO.delete(individual); FinancialInformation financialInformation = oldGuarantor.getFinancialInformation(); financialInformation.setInvestorindividual(null); oldGuarantor.setFinancialInformation(null); this.financialInformationDao.delete(financialInformation); Application application = oldGuarantor.getApplication(); oldGuarantor.setApplication(null); application.getInvestorindividuals().remove(oldGuarantor); this.investorindividualDAO.delete(oldGuarantor); this.applicationDAO.update(application); } else { if (logger.isDebugEnabled()) { logger.debug("Guarantor to remove is internal, so updating flags ..."); } oldGuarantor.setIsguarantor(Constants.FALSE); this.investorindividualDAO.update(oldGuarantor); FinancialInformation financialInformation = oldGuarantor.getFinancialInformation(); financialInformation.setInvestorindividual(null); oldGuarantor.setFinancialInformation(null); this.financialInformationDao.delete(financialInformation); } }
public Set<Application> getApplicationsToDisplay(Advisor advisor) { this.advisorDAO.refresh(advisor); Set<Application> filteredApplications = new TreeSet<Application>( new Comparator<Application>() { public int compare(Application o1, Application o2) { int res = o1.getAccountdesignation().compareToIgnoreCase(o2.getAccountdesignation()); // this is to see all applications even with the same acccount // designation. if (res == 0) { res = new Long(o1.getId()).compareTo(o2.getId()); } return res; } }); Set<Application> applications = advisor.getApplications(); for (Application application : applications) { if (application.getStatus() != Constants.CANCELLED_STATUS) { filteredApplications.add(application); } } return filteredApplications; }
public void updateDirectCreditDetails( Application application, ApplicationDirectCreditDetails directCreditDetails) throws IncorrectRelationshipException { // Since one-to-one associations are preloaded (ie - not lazy), we don't // need to refresh. Refreshing will cause errors because we'll then // have two ApplicationDirectCreditDetails objects with the same id // being updated. // this.applicationDAO.refresh(application); if (application.getDirectCreditDetails() != null && application.getDirectCreditDetails().getId() != null && directCreditDetails.getId() != null && !application.getDirectCreditDetails().getId().equals(directCreditDetails.getId())) { throw new IncorrectRelationshipException( "Application " + application + " already has directCreditDetails: " + directCreditDetails + ". Cannot replace with " + directCreditDetails + "."); } directCreditDetails.setApplication(application); application.setDirectCreditDetails(directCreditDetails); this.applicationDAO.updateDirectCreditDetails(application); }
public void removeAdditionalGuarantor(Application application) { this.applicationDAO.refresh(application); if (application.getExternalGuarantor() != null) { this.removeAsGuarantor(application.getExternalGuarantor()); } else if (application.getInternalGuarantor() != null) { this.removeAsGuarantor(application.getInternalGuarantor()); } }
public void associateAsGuarantor( Application application, Investorindividual transientGuarantor, Individual transientIndividual, FinancialInformation transientFinancialInformation) { Investorindividual chosenGuarantor; this.applicationDAO.refresh(application); if (application.getExternalGuarantor() != null) { // external guarantor exists. if (transientGuarantor.getId().longValue() == application.getExternalGuarantor().getId().longValue()) { // updating existing exernal guarantor chosenGuarantor = application.getExternalGuarantor(); this.updateGuarantorDetails( chosenGuarantor, transientGuarantor, transientGuarantor.getIndividual()); } else { // switched to internal guarantor - delete external guarantor Investorindividual oldGuarantor = application.getExternalGuarantor(); this.removeAsGuarantor(oldGuarantor); chosenGuarantor = application.findInvestorIndividualById(transientGuarantor.getId()); this.setAsInternalGuarantor(application, chosenGuarantor); } } else if (application.getInternalGuarantor() != null) { // internal guarantor exists. Investorindividual oldGuarantor = application.getInternalGuarantor(); chosenGuarantor = application.findInvestorIndividualById(transientGuarantor.getId()); if (chosenGuarantor == null) { // switching to new external guarantor. this.removeAsGuarantor(oldGuarantor); chosenGuarantor = this.createExternalGuarantor( application, transientGuarantor, transientGuarantor.getIndividual()); } else if (oldGuarantor.getId().equals(chosenGuarantor.getId())) { // same internal guarantor - update // nothing to update here ... } else { // different internal guarantor - remove old associationship and create new one this.removeAsGuarantor(oldGuarantor); this.setAsInternalGuarantor(application, chosenGuarantor); } } else { // assume new external guarantor. chosenGuarantor = this.createExternalGuarantor( application, transientGuarantor, transientGuarantor.getIndividual()); } if (logger.isDebugEnabled()) { logger.debug("Saving guarantor's finaicial information ..."); } this.updateGuarantorFinancialInformation(chosenGuarantor, transientFinancialInformation); }
public Investorindividual createExternalGuarantor( Application application, Investorindividual transientInvestorindividual, Individual transientIndividual) { if (logger.isDebugEnabled()) { logger.debug("Creating new external guarantor individual ..."); } Individual individual = new Individual(); // Column 1: individual.setTitle(transientIndividual.getTitle()); individual.setFirstname(transientIndividual.getFirstname()); individual.setMiddlename(transientIndividual.getMiddlename()); individual.setLastname(transientIndividual.getLastname()); individual.setAddress1(transientIndividual.getAddress1()); individual.setSuburb(transientIndividual.getSuburb()); individual.setState(transientIndividual.getState()); individual.setPostcode(transientIndividual.getPostcode()); individual.setCountry(transientIndividual.getCountry()); // Column 2: individual.setPassportno(transientIndividual.getPassportno()); individual.setNationality(transientIndividual.getNationality()); individual.setDriverslicenceno(transientIndividual.getDriverslicenceno()); individual.setOccupation(transientIndividual.getOccupation()); individual.setEmployer(transientIndividual.getEmployer()); individual.setDateofbirth(transientIndividual.getDateofbirth()); individual.setTownofbirth(transientIndividual.getTownofbirth()); individual.setCountryofbirth(transientIndividual.getCountryofbirth()); individual.setTfn(transientIndividual.getTfn()); this.individualDAO.save(individual); if (logger.isDebugEnabled()) { logger.debug("Linking new external guarantor individual to application ..."); } Investorindividual investorindividual = new Investorindividual(); investorindividual.setApplication(application); application.getInvestorindividuals().add(investorindividual); investorindividual.setIndividual(individual); individual.getInvestorindividuals().add(investorindividual); investorindividual.setRole(Constants.GUARANTOR); investorindividual.setIsguarantor(Constants.TRUE); investorindividual.setWealthbyemployment(transientInvestorindividual.getWealthbyemployment()); investorindividual.setWealthbyinvestments(transientInvestorindividual.getWealthbyinvestments()); investorindividual.setWealthbyother(transientInvestorindividual.getWealthbyother()); investorindividual.setWealthbyotherinfo(transientInvestorindividual.getWealthbyotherinfo()); this.investorindividualDAO.save(investorindividual); return investorindividual; }