Search in sources :

Example 1 with AuditEntryNotificationView

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);
}
Also used : ArrayList(java.util.ArrayList) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuditEntryNotificationView(com.synopsys.integration.alert.database.audit.AuditEntryNotificationView)

Example 2 with AuditEntryNotificationView

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;
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) AuditEntryNotificationView(com.synopsys.integration.alert.database.audit.AuditEntryNotificationView)

Example 3 with AuditEntryNotificationView

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);
}
Also used : AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuditEntryNotificationView(com.synopsys.integration.alert.database.audit.AuditEntryNotificationView) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)3 AuditEntryNotificationView (com.synopsys.integration.alert.database.audit.AuditEntryNotificationView)3 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)1 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Transactional (org.springframework.transaction.annotation.Transactional)1