DataLoadCensus.java 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.commands.census.CensusCommand;
  11. import scot.carricksoftware.grants.commands.census.CensusCommandImpl;
  12. import scot.carricksoftware.grants.commands.census.CensusEntryCommand;
  13. import scot.carricksoftware.grants.commands.census.CensusEntryCommandImpl;
  14. import scot.carricksoftware.grants.domains.places.Place;
  15. import scot.carricksoftware.grants.enums.censusentry.CensusEntryCondition;
  16. import scot.carricksoftware.grants.enums.censusentry.CensusEntryGaelic;
  17. import scot.carricksoftware.grants.enums.censusentry.CensusEntryRelationship;
  18. import scot.carricksoftware.grants.enums.censusentry.CensusEntryWorker;
  19. import scot.carricksoftware.grants.services.census.CensusEntryService;
  20. import scot.carricksoftware.grants.services.census.CensusService;
  21. import scot.carricksoftware.grants.services.people.PersonService;
  22. import scot.carricksoftware.grants.services.places.places.PlaceService;
  23. import java.time.LocalDate;
  24. @Component
  25. @Profile("dev")
  26. public class DataLoadCensus {
  27. private static final Logger logger = LogManager.getLogger(DataLoadCensus.class);
  28. private final CensusService censusService;
  29. private final CensusEntryService censusEntryService;
  30. private final PlaceService placeService;
  31. private final PersonService personService;
  32. public DataLoadCensus(CensusService censusService,
  33. CensusEntryService censusEntryService,
  34. PlaceService placeService,
  35. PersonService personService) {
  36. this.censusService = censusService;
  37. this.censusEntryService = censusEntryService;
  38. this.placeService = placeService;
  39. this.personService = personService;
  40. }
  41. public void load() {
  42. logger.debug("DataLoadCensus::load");
  43. loadCensus();
  44. loadCensusEntry();
  45. }
  46. private void loadCensus() {
  47. logger.debug("DataLoadCensus::loadCensus");
  48. CensusCommand censusCommand = new CensusCommandImpl();
  49. Place place = placeService.findById(1L);
  50. censusCommand.setDate(LocalDate.now());
  51. censusCommand.setPlace(place);
  52. censusService.saveCensusCommand(censusCommand);
  53. }
  54. private void loadCensusEntry() {
  55. logger.debug("DataLoadCensus::loadCensusEntry");
  56. CensusEntryCommand censusEntryCommand = new CensusEntryCommandImpl();
  57. censusEntryCommand.setName("Archie Grant");
  58. censusEntryCommand.setCensus(censusService.findById(1L));
  59. censusEntryCommand.setPerson(personService.findById(1L));
  60. censusEntryCommand.setRelationship(CensusEntryRelationship.COUSIN);
  61. censusEntryCommand.setCondition(CensusEntryCondition.MARRIED);
  62. censusEntryCommand.setGaelic(CensusEntryGaelic.GAELIC);
  63. censusEntryCommand.setWorker(CensusEntryWorker.WORKER);
  64. censusEntryCommand.setAge("72");
  65. censusEntryCommand.setWhereBorn("Edinburgh");
  66. censusEntryService.saveCensusEntryCommand(censusEntryCommand);
  67. }
  68. }