in use-cases/employee-scheduling/src/main/java/org/acme/employeescheduling/bootstrap/DemoDataGenerator.java [78:124]
public void generateDemoData(@Observes StartupEvent startupEvent) {
final int INITIAL_ROSTER_LENGTH_IN_DAYS = 14;
final LocalDate START_DATE = LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.MONDAY));
ScheduleState scheduleState = new ScheduleState();
scheduleState.setFirstDraftDate(START_DATE);
scheduleState.setDraftLength(INITIAL_ROSTER_LENGTH_IN_DAYS);
scheduleState.setPublishLength(7);
scheduleState.setLastHistoricDate(START_DATE.minusDays(7));
scheduleState.setTenantId(EmployeeScheduleResource.SINGLETON_SCHEDULE_ID);
scheduleStateRepository.persist(scheduleState);
Random random = new Random(0);
int shiftTemplateIndex = 0;
for (String location : LOCATIONS) {
locationToShiftStartTimeListMap.put(location, List.of(SHIFT_START_TIMES_COMBOS[shiftTemplateIndex]));
shiftTemplateIndex = (shiftTemplateIndex + 1) % SHIFT_START_TIMES_COMBOS.length;
}
if (demoData == DemoData.NONE) {
return;
}
List<String> namePermutations = joinAllCombinations(FIRST_NAMES, LAST_NAMES);
Collections.shuffle(namePermutations, random);
List<Employee> employeeList = new ArrayList<>();
for (int i = 0; i < 15; i++) {
Set<String> skills = pickSubset(List.of(OPTIONAL_SKILLS), random, 3, 1);
skills.add(pickRandom(REQUIRED_SKILLS, random));
Employee employee = new Employee(namePermutations.get(i), skills);
employeeRepository.persist(employee);
employeeList.add(employee);
}
for (int i = 0; i < INITIAL_ROSTER_LENGTH_IN_DAYS; i++) {
Set<Employee> employeesWithAvailabitiesOnDay = pickSubset(employeeList, random, 4, 3, 2, 1);
LocalDate date = START_DATE.plusDays(i);
for (Employee employee : employeesWithAvailabitiesOnDay) {
AvailabilityType availabilityType = pickRandom(AvailabilityType.values(), random);
availabilityRepository.persist(new Availability(employee, date, availabilityType));
}
generateShiftsForDay(date, random);
}
}