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 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()))); }