@Test public void createAuditEntryNullEntryIdTest() throws Exception { AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class); AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class); DefaultAuditAccessor auditUtility = new DefaultAuditAccessor(auditEntryRepository, auditNotificationRepository, null, null, null); ProviderMessageContent content = createMessageContent(); UUID commonConfigUUID = UUID.randomUUID(); AuditEntryEntity savedAuditEntryEntity = new AuditEntryEntity(commonConfigUUID, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null); savedAuditEntryEntity.setId(10L); mockAuditRepositorySave(auditEntryRepository, savedAuditEntryEntity); Map<Long, Long> savedNotificationIdToAuditId = auditUtility.createAuditEntry(null, commonConfigUUID, MessageContentGroup.singleton(content)); assertFalse(savedNotificationIdToAuditId.isEmpty()); assertEquals(2, savedNotificationIdToAuditId.size()); assertEquals(savedAuditEntryEntity.getId(), savedNotificationIdToAuditId.values().iterator().next()); assertEquals(AuditEntryStatus.PENDING.toString(), savedAuditEntryEntity.getStatus()); Mockito.verify(auditEntryRepository, Mockito.times(0)).findById(Mockito.anyLong()); Mockito.verify(auditNotificationRepository, Mockito.times(2)).save(Mockito.any(AuditNotificationRelation.class)); }
@Override @Transactional public Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup) { Map<Long, Long> notificationIdToAuditId = new HashMap<>(); List<ProviderMessageContent> subContent = contentGroup.getSubContent(); Set<Long> componentNotificationIds = subContent .stream() .map(ProviderMessageContent::getComponentItems) .flatMap(Collection::stream) .map(ComponentItem::getNotificationIds) .flatMap(Set::stream) .collect(Collectors.toSet()); Set<Long> topLevelActionNotificationIds = subContent .stream() .filter(ProviderMessageContent::isTopLevelActionOnly) .map(ProviderMessageContent::getNotificationId) .flatMap(Optional::stream) .collect(Collectors.toSet()); Set<Long> allMessageNotificationIds = Stream .concat(componentNotificationIds.stream(), topLevelActionNotificationIds.stream()) .collect(Collectors.toSet()); for (Long notificationId : allMessageNotificationIds) { AuditEntryEntity auditEntryEntity = new AuditEntryEntity(jobId, DateUtils.createCurrentDateTimestamp(), null, null, null, null); boolean didAuditEntryExist = false; if (null != existingNotificationIdToAuditId && !existingNotificationIdToAuditId.isEmpty()) { Long auditEntryId = existingNotificationIdToAuditId.get(notificationId); didAuditEntryExist = null != auditEntryId; if (didAuditEntryExist) { auditEntryEntity = auditEntryRepository.findById(auditEntryId).orElse(auditEntryEntity); } } auditEntryEntity.setStatus(AuditEntryStatus.PENDING.toString()); AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity); notificationIdToAuditId.put(notificationId, savedAuditEntryEntity.getId()); if (!didAuditEntryExist) { AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId); auditNotificationRepository.save(auditNotificationRelation); } } return notificationIdToAuditId; }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup) { Map<Long, Long> notificationIdToAuditId = new HashMap<>(); List<ProviderMessageContent> subContent = contentGroup.getSubContent(); Set<Long> componentNotificationIds = subContent .stream() .map(ProviderMessageContent::getComponentItems) .flatMap(Collection::stream) .map(ComponentItem::getNotificationIds) .flatMap(Set::stream) .collect(Collectors.toSet()); Set<Long> topLevelActionNotificationIds = subContent .stream() .filter(ProviderMessageContent::isTopLevelActionOnly) .map(ProviderMessageContent::getNotificationId) .flatMap(Optional::stream) .collect(Collectors.toSet()); Set<Long> allMessageNotificationIds = Stream .concat(componentNotificationIds.stream(), topLevelActionNotificationIds.stream()) .collect(Collectors.toSet()); for (Long notificationId : allMessageNotificationIds) { AuditEntryEntity auditEntryEntity = new AuditEntryEntity(jobId, DateUtils.createCurrentDateTimestamp(), null, null, null, null); boolean didAuditEntryExist = false; if (null != existingNotificationIdToAuditId && !existingNotificationIdToAuditId.isEmpty()) { Long auditEntryId = existingNotificationIdToAuditId.get(notificationId); didAuditEntryExist = null != auditEntryId; if (didAuditEntryExist) { auditEntryEntity = auditEntryRepository.findById(auditEntryId).orElse(auditEntryEntity); } } auditEntryEntity.setStatus(AuditEntryStatus.PENDING.toString()); AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity); notificationIdToAuditId.put(notificationId, savedAuditEntryEntity.getId()); if (!didAuditEntryExist) { AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId); auditNotificationRepository.save(auditNotificationRelation); } } return notificationIdToAuditId; } }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup) { Map<Long, Long> notificationIdToAuditId = new HashMap<>(); List<ProviderMessageContent> subContent = contentGroup.getSubContent(); Set<Long> componentNotificationIds = subContent .stream() .map(ProviderMessageContent::getComponentItems) .flatMap(Collection::stream) .map(ComponentItem::getNotificationIds) .flatMap(Set::stream) .collect(Collectors.toSet()); Set<Long> topLevelActionNotificationIds = subContent .stream() .filter(ProviderMessageContent::isTopLevelActionOnly) .map(ProviderMessageContent::getNotificationId) .flatMap(Optional::stream) .collect(Collectors.toSet()); Set<Long> allMessageNotificationIds = Stream .concat(componentNotificationIds.stream(), topLevelActionNotificationIds.stream()) .collect(Collectors.toSet()); for (Long notificationId : allMessageNotificationIds) { AuditEntryEntity auditEntryEntity = new AuditEntryEntity(jobId, DateUtils.createCurrentDateTimestamp(), null, null, null, null); boolean didAuditEntryExist = false; if (null != existingNotificationIdToAuditId && !existingNotificationIdToAuditId.isEmpty()) { Long auditEntryId = existingNotificationIdToAuditId.get(notificationId); didAuditEntryExist = null != auditEntryId; if (didAuditEntryExist) { auditEntryEntity = auditEntryRepository.findById(auditEntryId).orElse(auditEntryEntity); } } auditEntryEntity.setStatus(AuditEntryStatus.PENDING.toString()); AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity); notificationIdToAuditId.put(notificationId, savedAuditEntryEntity.getId()); if (!didAuditEntryExist) { AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId); auditNotificationRepository.save(auditNotificationRelation); } } return notificationIdToAuditId; } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup) { Map<Long, Long> notificationIdToAuditId = new HashMap<>(); List<ProviderMessageContent> subContent = contentGroup.getSubContent(); Set<Long> componentNotificationIds = subContent .stream() .map(ProviderMessageContent::getComponentItems) .flatMap(Collection::stream) .map(ComponentItem::getNotificationIds) .flatMap(Set::stream) .collect(Collectors.toSet()); Set<Long> topLevelActionNotificationIds = subContent .stream() .filter(ProviderMessageContent::isTopLevelActionOnly) .map(ProviderMessageContent::getNotificationId) .flatMap(Optional::stream) .collect(Collectors.toSet()); Set<Long> allMessageNotificationIds = Stream .concat(componentNotificationIds.stream(), topLevelActionNotificationIds.stream()) .collect(Collectors.toSet()); for (Long notificationId : allMessageNotificationIds) { AuditEntryEntity auditEntryEntity = new AuditEntryEntity(jobId, DateUtils.createCurrentDateTimestamp(), null, null, null, null); boolean didAuditEntryExist = false; if (null != existingNotificationIdToAuditId && !existingNotificationIdToAuditId.isEmpty()) { Long auditEntryId = existingNotificationIdToAuditId.get(notificationId); didAuditEntryExist = null != auditEntryId; if (didAuditEntryExist) { auditEntryEntity = auditEntryRepository.findById(auditEntryId).orElse(auditEntryEntity); } } auditEntryEntity.setStatus(AuditEntryStatus.PENDING.toString()); AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity); notificationIdToAuditId.put(notificationId, savedAuditEntryEntity.getId()); if (!didAuditEntryExist) { AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId); auditNotificationRepository.save(auditNotificationRelation); } } return notificationIdToAuditId; } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); @Override Optional<Long> findMatchingAuditId(Long notificationId, UUID commonDistributionId); @Override @Transactional Optional<AuditJobStatusModel> findFirstByJobId(UUID jobId); @Override @Transactional AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications,
        Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter); @Override @Transactional Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup); @Override @Transactional void setAuditEntrySuccess(Collection<Long> auditEntryIds); @Override @Transactional void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t); @Override @Transactional AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry); }
DefaultAuditAccessor implements AuditAccessor { @Override @Transactional public Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup) { Map<Long, Long> notificationIdToAuditId = new HashMap<>(); List<ProviderMessageContent> subContent = contentGroup.getSubContent(); Set<Long> componentNotificationIds = subContent .stream() .map(ProviderMessageContent::getComponentItems) .flatMap(Collection::stream) .map(ComponentItem::getNotificationIds) .flatMap(Set::stream) .collect(Collectors.toSet()); Set<Long> topLevelActionNotificationIds = subContent .stream() .filter(ProviderMessageContent::isTopLevelActionOnly) .map(ProviderMessageContent::getNotificationId) .flatMap(Optional::stream) .collect(Collectors.toSet()); Set<Long> allMessageNotificationIds = Stream .concat(componentNotificationIds.stream(), topLevelActionNotificationIds.stream()) .collect(Collectors.toSet()); for (Long notificationId : allMessageNotificationIds) { AuditEntryEntity auditEntryEntity = new AuditEntryEntity(jobId, DateUtils.createCurrentDateTimestamp(), null, null, null, null); boolean didAuditEntryExist = false; if (null != existingNotificationIdToAuditId && !existingNotificationIdToAuditId.isEmpty()) { Long auditEntryId = existingNotificationIdToAuditId.get(notificationId); didAuditEntryExist = null != auditEntryId; if (didAuditEntryExist) { auditEntryEntity = auditEntryRepository.findById(auditEntryId).orElse(auditEntryEntity); } } auditEntryEntity.setStatus(AuditEntryStatus.PENDING.toString()); AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(auditEntryEntity); notificationIdToAuditId.put(notificationId, savedAuditEntryEntity.getId()); if (!didAuditEntryExist) { AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntryEntity.getId(), notificationId); auditNotificationRepository.save(auditNotificationRelation); } } return notificationIdToAuditId; } @Autowired  DefaultAuditAccessor(AuditEntryRepository auditEntryRepository, AuditNotificationRepository auditNotificationRepository, ConfigurationAccessor configurationAccessor,
        DefaultNotificationAccessor notificationAccessor, ContentConverter contentConverter); @Override Optional<Long> findMatchingAuditId(Long notificationId, UUID commonDistributionId); @Override @Transactional Optional<AuditJobStatusModel> findFirstByJobId(UUID jobId); @Override @Transactional AuditEntryPageModel getPageOfAuditEntries(Integer pageNumber, Integer pageSize, String searchTerm, String sortField, String sortOrder, boolean onlyShowSentNotifications,
        Function<AlertNotificationModel, AuditEntryModel> notificationToAuditEntryConverter); @Override @Transactional Map<Long, Long> createAuditEntry(Map<Long, Long> existingNotificationIdToAuditId, UUID jobId, MessageContentGroup contentGroup); @Override @Transactional void setAuditEntrySuccess(Collection<Long> auditEntryIds); @Override @Transactional void setAuditEntryFailure(Collection<Long> auditEntryIds, String errorMessage, Throwable t); @Override @Transactional AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry);  }