DataLoadCensus.java 3.4 KB

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