private AgencyResultAggregate(AgencyResultBuilder builder) { this.agencyResultRootEntity = new AgencyResultRootEntity(builder.personId, builder.points); this.agencyResultRootEntity.addAllKoCriteria(builder.koCriteria); this.agencyResultRootEntity.addAllWarningMessage(builder.warningMessages); }
public int calculateScoringPoints() { return agencyResultRootEntity.calculateScoringPoints(); }
@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); }
public void scoreAgencyResult(String firstName, String lastName, String street, String postcode, String city, int agencyPoints ) { AgencyResultAggregate.AgencyResultBuilder agencyResultBuilder = new AgencyResultAggregate.AgencyResultBuilder() .forPerson(firstName, lastName, street, postcode, city) .withPoints(agencyPoints); AgencyResultAggregate agencyResultAggregate = agencyResultBuilder.build(); agencyResultRepository.save(agencyResultAggregate); ApplicantResultProjection applicantResultProjection = applicantResultRepository.retrieve(agencyResultAggregate.getPersonId()); applicationEventPublisher.publishEvent(new PartOfScoringPerformed(this, new ApplicationNumber(applicantResultProjection.getApplicationNumber()))); }
public void performFinalScoring(ApplicationNumber applicationNumber) { FinancialSituationResultProjection financialSituationResultProjection = financialSituationResultRepository.retrieve(applicationNumber); ApplicantResultProjection applicantResultProjection = applicantResultRepository.retrieve(applicationNumber); AgencyResultProjection agencyResultProjection = agencyResultRepository.retrieve(new PersonId(applicantResultProjection.getPersonId())); if(financialSituationResultProjection != null && applicantResultProjection !=null && agencyResultProjection != null) { log.info("everything is complete for " + applicationNumber.toString()); ScoringResultAggregate scoringResultAggregate = new ScoringResultAggregate.Builder(applicationNumber) .noGoCriteria(agencyResultProjection.isNoGoPresent()) .agencyScoring(agencyResultProjection.getPoints()) .financialSituationScoring(financialSituationResultProjection.getPoints()) .applicantScoring(applicantResultProjection.getPoints()) .build(); scoringResultRepository.save(scoringResultAggregate); } else { log.info("NOT everything is complete for " + applicationNumber.toString()); } }
public boolean isAcceptable() { return agencyResultRootEntity.isAcceptable(); }
public AgencyResultBuilder withWarning(String key, String message) { this.warningMessages.add(new WarningMessage(key, message)); return this; }
public AgencyResultBuilder withKoCriteria(String key, String message) { this.koCriteria.add(new KoCriteria(key, message)); return this; }
public AgencyResultAggregate build() { if(this.points <= 0) { throw new IllegalStateException("Please set points > 0 with the withPoints mehtod"); } if(this.personId == null) { throw new IllegalStateException("Please set a person with the forPerson method"); } return new AgencyResultAggregate(this); }
@Override public AgencyResultProjection retrieve(PersonId personId) { return dao.findByPersonId(personId.toString()); } }