use of com.synopsys.integration.alert.database.audit.AuditEntryNotificationView in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessor method updateAuditEntries.
private void updateAuditEntries(UUID jobId, Set<Long> notificationIds, Consumer<AuditEntryEntity> auditFieldSetter) {
if (notificationIds.isEmpty()) {
return;
}
List<AuditEntryNotificationView> auditEntryNotificationViews = auditEntryRepository.findByJobIdAndNotificationIds(jobId, notificationIds);
List<AuditEntryEntity> updatedAuditEntries = new ArrayList<>(auditEntryNotificationViews.size());
for (AuditEntryNotificationView view : auditEntryNotificationViews) {
AuditEntryEntity auditEntryToSave = fromView(view);
auditEntryToSave.setTimeLastSent(DateUtils.createCurrentDateTimestamp());
auditFieldSetter.accept(auditEntryToSave);
updatedAuditEntries.add(auditEntryToSave);
logger.trace("Updated audit entry: {}.", auditEntryToSave.getId());
}
auditEntryRepository.saveAll(updatedAuditEntries);
}
use of com.synopsys.integration.alert.database.audit.AuditEntryNotificationView in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessorTest method setAuditEntryStatusTest.
private AuditEntryEntity setAuditEntryStatusTest(AuditEntryStatus expectedStatus, AuditAccessorStatusSetter statusSetter) {
UUID testJobId = UUID.randomUUID();
Long testNotificationId = 99L;
Set<Long> testNotificationIds = Set.of(testNotificationId);
AuditEntryNotificationView testView = new AuditEntryNotificationView(0L, testJobId, testNotificationId, null, null, null, null, null);
AtomicReference<AuditEntryEntity> savedEntry = new AtomicReference<>();
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
Mockito.when(auditEntryRepository.findByJobIdAndNotificationIds(testJobId, testNotificationIds)).thenReturn(List.of(testView));
Mockito.when(auditEntryRepository.saveAll(Mockito.anyList())).then(invocation -> {
List<AuditEntryEntity> savedEntries = invocation.getArgument(0);
if (!savedEntries.isEmpty()) {
savedEntry.set(savedEntries.get(0));
}
return List.of();
});
DefaultProcessingAuditAccessor processingAuditAccessor = new DefaultProcessingAuditAccessor(auditEntryRepository, null);
statusSetter.setStatus(processingAuditAccessor, testJobId, testNotificationIds);
AuditEntryEntity auditEntryEntity = savedEntry.get();
assertNotNull(auditEntryEntity, "Expected an audit entry to have been saved");
assertEquals(testView.getId(), auditEntryEntity.getId());
assertEquals(testView.getJobId(), auditEntryEntity.getCommonConfigId());
assertEquals(expectedStatus.name(), auditEntryEntity.getStatus());
assertNotNull(auditEntryEntity.getTimeLastSent(), "Expected time last sent to be set");
return auditEntryEntity;
}
use of com.synopsys.integration.alert.database.audit.AuditEntryNotificationView in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessor method createOrUpdatePendingAuditEntryForJob.
@Override
@Transactional
public void createOrUpdatePendingAuditEntryForJob(UUID jobId, Set<Long> notificationIds) {
if (notificationIds.isEmpty()) {
return;
}
Map<Long, AuditEntryNotificationView> notificationIdToView = auditEntryRepository.findByJobIdAndNotificationIds(jobId, notificationIds).stream().collect(Collectors.toMap(AuditEntryNotificationView::getNotificationId, Function.identity()));
Set<AuditNotificationRelation> relationsToUpdate = new HashSet<>();
for (Long notificationId : notificationIds) {
AuditEntryEntity auditEntryToSave;
AuditEntryNotificationView view = notificationIdToView.get(notificationId);
if (null != view) {
auditEntryToSave = fromView(view);
} else {
auditEntryToSave = new AuditEntryEntity(jobId, DateUtils.createCurrentDateTimestamp(), null, AuditEntryStatus.PENDING.name(), null, null);
}
AuditEntryEntity savedAuditEntry = auditEntryRepository.save(auditEntryToSave);
logger.trace("Created audit entry: {}. For notification: {}", savedAuditEntry.getId(), notificationId);
AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(savedAuditEntry.getId(), notificationId);
relationsToUpdate.add(auditNotificationRelation);
}
auditNotificationRepository.saveAll(relationsToUpdate);
}
Aggregations