@Test public void deleteUserInfoNoOlderUsers() { List<CustomerInfo> customerInfoList = new ArrayList<>(); CustomerInfo ci = new CustomerInfo(); ci.setCreatedAt(LocalDateTime.now()); customerInfoList.add(ci); when(customerInfoRepo.findAll()).thenReturn(customerInfoList); cronJob.deleteUserInfo(); }
@Scheduled(cron = "0 0 6 * * *") public void deleteUserInfo() { LOGGER.info("Running cron job to delete users"); Iterable<CustomerInfo> customerInfoList = customerInfoRepo.findAll(); List<CustomerInfoCronJobInfo> customersToDelete = new ArrayList<>(); if (customerInfoList == null) { LOGGER.info("No Customers to Delete"); return; } customerInfoList.forEach(c -> { customersToDelete.add(new CustomerInfoCronJobInfo(c)); }); LocalDateTime now = LocalDateTime.now(); for (CustomerInfoCronJobInfo c : customersToDelete) { if (c.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { List<PrintJob> pJobs = printJobRepo.findPrintJobsByCustomerIdNewestFirst(c.getId()); if (pJobs != null && pJobs.size() >= 1) { PrintJob p = pJobs.get(0); if (p != null) { if (p.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { printJobRepo.deleteAll(pJobs); customerInfoRepo.deleteById(c.getId()); } } } } } }
DeleteUserInfoCronJob { @Scheduled(cron = "0 0 6 * * *") public void deleteUserInfo() { LOGGER.info("Running cron job to delete users"); Iterable<CustomerInfo> customerInfoList = customerInfoRepo.findAll(); List<CustomerInfoCronJobInfo> customersToDelete = new ArrayList<>(); if (customerInfoList == null) { LOGGER.info("No Customers to Delete"); return; } customerInfoList.forEach(c -> { customersToDelete.add(new CustomerInfoCronJobInfo(c)); }); LocalDateTime now = LocalDateTime.now(); for (CustomerInfoCronJobInfo c : customersToDelete) { if (c.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { List<PrintJob> pJobs = printJobRepo.findPrintJobsByCustomerIdNewestFirst(c.getId()); if (pJobs != null && pJobs.size() >= 1) { PrintJob p = pJobs.get(0); if (p != null) { if (p.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { printJobRepo.deleteAll(pJobs); customerInfoRepo.deleteById(c.getId()); } } } } } } }
DeleteUserInfoCronJob { @Scheduled(cron = "0 0 6 * * *") public void deleteUserInfo() { LOGGER.info("Running cron job to delete users"); Iterable<CustomerInfo> customerInfoList = customerInfoRepo.findAll(); List<CustomerInfoCronJobInfo> customersToDelete = new ArrayList<>(); if (customerInfoList == null) { LOGGER.info("No Customers to Delete"); return; } customerInfoList.forEach(c -> { customersToDelete.add(new CustomerInfoCronJobInfo(c)); }); LocalDateTime now = LocalDateTime.now(); for (CustomerInfoCronJobInfo c : customersToDelete) { if (c.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { List<PrintJob> pJobs = printJobRepo.findPrintJobsByCustomerIdNewestFirst(c.getId()); if (pJobs != null && pJobs.size() >= 1) { PrintJob p = pJobs.get(0); if (p != null) { if (p.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { printJobRepo.deleteAll(pJobs); customerInfoRepo.deleteById(c.getId()); } } } } } } DeleteUserInfoCronJob(CustomerInfoRepo customerInfoRepo, PrintJobRepo printJobRepo); }
DeleteUserInfoCronJob { @Scheduled(cron = "0 0 6 * * *") public void deleteUserInfo() { LOGGER.info("Running cron job to delete users"); Iterable<CustomerInfo> customerInfoList = customerInfoRepo.findAll(); List<CustomerInfoCronJobInfo> customersToDelete = new ArrayList<>(); if (customerInfoList == null) { LOGGER.info("No Customers to Delete"); return; } customerInfoList.forEach(c -> { customersToDelete.add(new CustomerInfoCronJobInfo(c)); }); LocalDateTime now = LocalDateTime.now(); for (CustomerInfoCronJobInfo c : customersToDelete) { if (c.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { List<PrintJob> pJobs = printJobRepo.findPrintJobsByCustomerIdNewestFirst(c.getId()); if (pJobs != null && pJobs.size() >= 1) { PrintJob p = pJobs.get(0); if (p != null) { if (p.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { printJobRepo.deleteAll(pJobs); customerInfoRepo.deleteById(c.getId()); } } } } } } DeleteUserInfoCronJob(CustomerInfoRepo customerInfoRepo, PrintJobRepo printJobRepo); @Scheduled(cron = "0 0 6 * * *") void deleteUserInfo(); }
DeleteUserInfoCronJob { @Scheduled(cron = "0 0 6 * * *") public void deleteUserInfo() { LOGGER.info("Running cron job to delete users"); Iterable<CustomerInfo> customerInfoList = customerInfoRepo.findAll(); List<CustomerInfoCronJobInfo> customersToDelete = new ArrayList<>(); if (customerInfoList == null) { LOGGER.info("No Customers to Delete"); return; } customerInfoList.forEach(c -> { customersToDelete.add(new CustomerInfoCronJobInfo(c)); }); LocalDateTime now = LocalDateTime.now(); for (CustomerInfoCronJobInfo c : customersToDelete) { if (c.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { List<PrintJob> pJobs = printJobRepo.findPrintJobsByCustomerIdNewestFirst(c.getId()); if (pJobs != null && pJobs.size() >= 1) { PrintJob p = pJobs.get(0); if (p != null) { if (p.getCreatedAt().plus(NUM_DAYS_RETENTION, ChronoUnit.DAYS).isBefore(now)) { printJobRepo.deleteAll(pJobs); customerInfoRepo.deleteById(c.getId()); } } } } } } DeleteUserInfoCronJob(CustomerInfoRepo customerInfoRepo, PrintJobRepo printJobRepo); @Scheduled(cron = "0 0 6 * * *") void deleteUserInfo();  }