@Test public void saveAllNotificationsTest() throws Exception { OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp(); OffsetDateTime providerCreationTime = createdAt.minusSeconds(10); AlertNotificationModel alertNotificationModel = new AlertNotificationModel(null, providerConfigId, provider, providerConfigName, notificationType, content, createdAt, providerCreationTime); NotificationEntity notificationEntity = new NotificationEntity(id, createdAt, provider, providerConfigId, providerCreationTime, notificationType, content); ConfigurationModel configurationModel = createConfigurationModel(); NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class); ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class); EventManager eventManager = Mockito.mock(EventManager.class); Mockito.when(notificationContentRepository.saveAll(Mockito.any())).thenReturn(List.of(notificationEntity)); Mockito.when(configurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel)); DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, null, configurationAccessor, eventManager); List<AlertNotificationModel> alertNotificationModelList = notificationManager.saveAllNotifications(List.of(alertNotificationModel)); assertEquals(1, alertNotificationModelList.size()); AlertNotificationModel testAlertNotificationModel = alertNotificationModelList.get(0); testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel); }
@Override public List<AlertNotificationModel> saveAllNotifications(Collection<AlertNotificationModel> notifications) { List<NotificationEntity> entitiesToSave = notifications .stream() .map(this::fromModel) .collect(Collectors.toList()); List<AlertNotificationModel> savedModels = notificationContentRepository.saveAll(entitiesToSave) .stream() .map(this::toModel) .collect(Collectors.toList()); notificationContentRepository.flush(); if (!savedModels.isEmpty()) { List<Long> notificationIds = savedModels.stream() .map(AlertNotificationModel::getId) .collect(Collectors.toList()); eventManager.sendEvent(new NotificationEvent(notificationIds)); } return savedModels; }
DefaultNotificationAccessor implements NotificationAccessor { @Override public List<AlertNotificationModel> saveAllNotifications(Collection<AlertNotificationModel> notifications) { List<NotificationEntity> entitiesToSave = notifications .stream() .map(this::fromModel) .collect(Collectors.toList()); List<AlertNotificationModel> savedModels = notificationContentRepository.saveAll(entitiesToSave) .stream() .map(this::toModel) .collect(Collectors.toList()); notificationContentRepository.flush(); if (!savedModels.isEmpty()) { List<Long> notificationIds = savedModels.stream() .map(AlertNotificationModel::getId) .collect(Collectors.toList()); eventManager.sendEvent(new NotificationEvent(notificationIds)); } return savedModels; } }
DefaultNotificationAccessor implements NotificationAccessor { @Override public List<AlertNotificationModel> saveAllNotifications(Collection<AlertNotificationModel> notifications) { List<NotificationEntity> entitiesToSave = notifications .stream() .map(this::fromModel) .collect(Collectors.toList()); List<AlertNotificationModel> savedModels = notificationContentRepository.saveAll(entitiesToSave) .stream() .map(this::toModel) .collect(Collectors.toList()); notificationContentRepository.flush(); if (!savedModels.isEmpty()) { List<Long> notificationIds = savedModels.stream() .map(AlertNotificationModel::getId) .collect(Collectors.toList()); eventManager.sendEvent(new NotificationEvent(notificationIds)); } return savedModels; } @Autowired  DefaultNotificationAccessor(NotificationContentRepository notificationContentRepository, AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository,
        ConfigurationAccessor configurationAccessor, EventManager eventManager); }
DefaultNotificationAccessor implements NotificationAccessor { @Override public List<AlertNotificationModel> saveAllNotifications(Collection<AlertNotificationModel> notifications) { List<NotificationEntity> entitiesToSave = notifications .stream() .map(this::fromModel) .collect(Collectors.toList()); List<AlertNotificationModel> savedModels = notificationContentRepository.saveAll(entitiesToSave) .stream() .map(this::toModel) .collect(Collectors.toList()); notificationContentRepository.flush(); if (!savedModels.isEmpty()) { List<Long> notificationIds = savedModels.stream() .map(AlertNotificationModel::getId) .collect(Collectors.toList()); eventManager.sendEvent(new NotificationEvent(notificationIds)); } return savedModels; } @Autowired  DefaultNotificationAccessor(NotificationContentRepository notificationContentRepository, AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository,
        ConfigurationAccessor configurationAccessor, EventManager eventManager); @Override List<AlertNotificationModel> saveAllNotifications(Collection<AlertNotificationModel> notifications); @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Page<AlertNotificationModel> findAll(PageRequest pageRequest, boolean onlyShowSentNotifications); @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Page<AlertNotificationModel> findAllWithSearch(String searchTerm, PageRequest pageRequest, boolean onlyShowSentNotifications); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<AlertNotificationModel> findByIds(List<Long> notificationIds); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Optional<AlertNotificationModel> findById(Long notificationId); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<AlertNotificationModel> findByCreatedAtBetween(OffsetDateTime startDate, OffsetDateTime endDate); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<AlertNotificationModel> findByCreatedAtBefore(OffsetDateTime date); @Override List<AlertNotificationModel> findByCreatedAtBeforeDayOffset(int dayOffset); @Override void deleteNotificationList(List<AlertNotificationModel> notifications); @Override void deleteNotification(AlertNotificationModel notification); PageRequest getPageRequestForNotifications(Integer pageNumber, Integer pageSize, String sortField, String sortOrder); }
DefaultNotificationAccessor implements NotificationAccessor { @Override public List<AlertNotificationModel> saveAllNotifications(Collection<AlertNotificationModel> notifications) { List<NotificationEntity> entitiesToSave = notifications .stream() .map(this::fromModel) .collect(Collectors.toList()); List<AlertNotificationModel> savedModels = notificationContentRepository.saveAll(entitiesToSave) .stream() .map(this::toModel) .collect(Collectors.toList()); notificationContentRepository.flush(); if (!savedModels.isEmpty()) { List<Long> notificationIds = savedModels.stream() .map(AlertNotificationModel::getId) .collect(Collectors.toList()); eventManager.sendEvent(new NotificationEvent(notificationIds)); } return savedModels; } @Autowired  DefaultNotificationAccessor(NotificationContentRepository notificationContentRepository, AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository,
        ConfigurationAccessor configurationAccessor, EventManager eventManager); @Override List<AlertNotificationModel> saveAllNotifications(Collection<AlertNotificationModel> notifications); @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Page<AlertNotificationModel> findAll(PageRequest pageRequest, boolean onlyShowSentNotifications); @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Page<AlertNotificationModel> findAllWithSearch(String searchTerm, PageRequest pageRequest, boolean onlyShowSentNotifications); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<AlertNotificationModel> findByIds(List<Long> notificationIds); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) Optional<AlertNotificationModel> findById(Long notificationId); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<AlertNotificationModel> findByCreatedAtBetween(OffsetDateTime startDate, OffsetDateTime endDate); @Override @Transactional(readOnly = true, isolation = Isolation.READ_COMMITTED) List<AlertNotificationModel> findByCreatedAtBefore(OffsetDateTime date); @Override List<AlertNotificationModel> findByCreatedAtBeforeDayOffset(int dayOffset); @Override void deleteNotificationList(List<AlertNotificationModel> notifications); @Override void deleteNotification(AlertNotificationModel notification); PageRequest getPageRequestForNotifications(Integer pageNumber, Integer pageSize, String sortField, String sortOrder);  }