DataLoadCertificates.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 18 Feb 2025, Andrew Grant of Carrick Software .
  3. * All rights reserved.
  4. */
  5. package scot.carricksoftware.grants.bootstrap;
  6. import org.apache.logging.log4j.LogManager;
  7. import org.apache.logging.log4j.Logger;
  8. import org.springframework.context.annotation.Profile;
  9. import org.springframework.stereotype.Component;
  10. import scot.carricksoftware.grants.domains.certificates.BirthCertificate;
  11. import scot.carricksoftware.grants.domains.certificates.DeathCertificate;
  12. import scot.carricksoftware.grants.services.certificates.birthcertificates.BirthCertificateService;
  13. import scot.carricksoftware.grants.services.certificates.deathcertificates.DeathCertificateService;
  14. import scot.carricksoftware.grants.services.people.PersonService;
  15. @Component
  16. @Profile("dev")
  17. public class DataLoadCertificates {
  18. private static final Logger logger = LogManager.getLogger(DataLoadCertificates.class);
  19. private final BirthCertificateService birthCertificateService;
  20. private final DeathCertificateService deathCertificateService;
  21. private final PersonService personService;
  22. public DataLoadCertificates(BirthCertificateService birthCertificateService,
  23. DeathCertificateService deathCertificateService,
  24. PersonService personService) {
  25. this.birthCertificateService = birthCertificateService;
  26. this.deathCertificateService = deathCertificateService;
  27. this.personService = personService;
  28. }
  29. public void load() {
  30. logger.debug("DataLoadPlaces::load");
  31. loadBirthCertificates();
  32. loadDeathCertificates();
  33. }
  34. private void loadBirthCertificates() {
  35. BirthCertificate birthCertificate = new BirthCertificate();
  36. birthCertificate.setNewBorn(personService.findById(1L));
  37. birthCertificateService.save(birthCertificate);
  38. }
  39. private void loadDeathCertificates() {
  40. DeathCertificate deathCertificate = new DeathCertificate();
  41. deathCertificate.setDeceased(personService.findById(1L));
  42. deathCertificateService.save(deathCertificate);
  43. }
  44. }