public PartOfScoringPerformed(Object source, String applicationNumber, PersonId personId) { super(source); this.applicationNumber = new ApplicationNumber(applicationNumber); this.personId = personId; }
Money sum() { return salary.add(otherIncome); } }
public PersonId build() { return new PersonId(this); } }
@Override public void save(ApplicantAggregate applicantAggregate) { ApplicantResultProjection projection = new ApplicantResultProjection(); projection.setApplicationNumber(applicantAggregate.applicantRootEntity.applicationNumber.toString()); projection.setPersonId(applicantAggregate.applicantRootEntity.personId.toString()); projection.setPoints(applicantAggregate.calculateScoringPoints()); this.dao.save(projection); }
@Override public void save(AgencyResultAggregate agencyResultAggregate) { AgencyResultProjection agencyResultProjection = new AgencyResultProjection(); agencyResultProjection.setNoGoPresent(!agencyResultAggregate.isAcceptable()); agencyResultProjection.setPersonId(agencyResultAggregate.getAgencyResultRootEntity().id.toString()); agencyResultProjection.setPoints(agencyResultAggregate.calculateScoringPoints()); dao.save(agencyResultProjection); }
private ApplicantAggregate(ApplicantAggregateBuilder builder) { PersonId personId = new PersonId.PersonIdBuilder(builder.firstName, builder.lastName) .postCode(builder.postCode) .city(builder.city) .street(builder.street) .build(); Address address = new Address(builder.street, builder.postCode, builder.city); this.applicantRootEntity = new ApplicantRootEntity(personId, builder.applicationNumber, builder.firstName, builder.lastName, address, builder.accountBalance); }
public AgencyResultBuilder forPerson(String firstName, String lastName, String street, String postCode, String city) { if(this.personId != null) { throw new IllegalArgumentException("You have already set a person"); } this.personId = new PersonId.PersonIdBuilder(firstName, lastName) .city(city) .street(street) .postCode(postCode) .build(); return this; }
public ApplicantAggregate build() { if(this.accountBalance == null) { this.accountBalance = new AccountBalance(new Money()); } return new ApplicantAggregate(this); } }
public int calculateScoringPoints() { Money monthlyBalance = rootEntity.sum(); if(monthlyBalance.isGreaterThan(new Money(2000))) { return 20; } else if(monthlyBalance.isGreaterThan(new Money(1000))) { return 15; } else if(monthlyBalance.isGreaterThan(new Money(750))) { return 10; } else if(monthlyBalance.isGreaterThan(new Money(500))) { return 5; } else if (monthlyBalance.isGreaterThan(new Money(250))) { return 2; } else if( monthlyBalance.isGreaterThan(new Money(0))) { return 0; } else { return -20; } }
int calculateScoringPoints() { if(balance.isGreaterThan(new Money(8000))) { return 10; } else { return 0; } } }
public ApplicantAggregateBuilder accountBalance(int balance) { this.accountBalance = new AccountBalance(new Money(balance)); return this; }
@Override public ApplicantResultProjection retrieve(ApplicationNumber applicationNumber) { return dao.findByApplicationNumber(applicationNumber.toString()); }
@Override public FinancialSituationResultProjection retrieve(ApplicationNumber applicationNumber) { return dao.findByApplicationNumber(applicationNumber.toString()); }
@Override public AgencyResultProjection retrieve(PersonId personId) { return dao.findByPersonId(personId.toString()); } }
@Override public ApplicantResultProjection retrieve(PersonId personId) { return dao.findByPersonId(personId.toString()); } }
private PersonId(PersonIdBuilder builder) { try { MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); byte[] shaHash = messageDigest.digest(builder.toString().getBytes()); this.personId = convertByteArrayToHexString(shaHash); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } }
Money sum() { return rent.add(costOfLiving); } }