Search in sources :

Example 1 with AuditEntryStatus

use of com.synopsys.integration.alert.common.enumeration.AuditEntryStatus in project hub-alert by blackducksoftware.

the class DefaultRestApiAuditAccessorTest method findFirstByJobIdNotNullTest.

@Test
public void findFirstByJobIdNotNullTest() {
    OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime timeCreated = timeLastSent.minusMinutes(10L);
    AuditEntryStatus status = AuditEntryStatus.PENDING;
    UUID testUUID = UUID.randomUUID();
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(testUUID, timeCreated, timeLastSent, status.name(), null, null);
    Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, null);
    AuditJobStatusModel auditJobStatusModel = auditUtility.findFirstByJobId(testUUID).get();
    String testTimeAuditCreated = auditJobStatusModel.getTimeAuditCreated();
    String testTimeLastSent = auditJobStatusModel.getTimeLastSent();
    String testStatus = auditJobStatusModel.getStatus();
    assertTrue(auditUtility.findFirstByJobId(testUUID).isPresent());
    assertEquals(DateUtils.formatDate(timeCreated, DateUtils.AUDIT_DATE_FORMAT), testTimeAuditCreated);
    assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testTimeLastSent);
    assertEquals(status.getDisplayName(), testStatus);
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) OffsetDateTime(java.time.OffsetDateTime) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 2 with AuditEntryStatus

use of com.synopsys.integration.alert.common.enumeration.AuditEntryStatus in project hub-alert by blackducksoftware.

the class DefaultRestApiAuditAccessor method convertToAuditEntryModelFromNotification.

@Override
@Transactional
public AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry) {
    List<AuditNotificationRelation> relations = auditNotificationRepository.findByNotificationId(notificationContentEntry.getId());
    List<Long> auditEntryIds = relations.stream().map(AuditNotificationRelation::getAuditEntryId).collect(Collectors.toList());
    List<AuditEntryEntity> auditEntryEntities = auditEntryRepository.findAllById(auditEntryIds);
    AuditEntryStatus overallStatus = null;
    String timeLastSent = null;
    OffsetDateTime timeLastSentOffsetDateTime = null;
    List<JobAuditModel> jobAuditModels = new ArrayList<>();
    for (AuditEntryEntity auditEntryEntity : auditEntryEntities) {
        UUID jobId = auditEntryEntity.getCommonConfigId();
        if (null != auditEntryEntity.getTimeLastSent() && (null == timeLastSentOffsetDateTime || timeLastSentOffsetDateTime.isBefore(auditEntryEntity.getTimeLastSent()))) {
            timeLastSentOffsetDateTime = auditEntryEntity.getTimeLastSent();
            timeLastSent = formatAuditDate(timeLastSentOffsetDateTime);
        }
        String id = contentConverter.getStringValue(auditEntryEntity.getId());
        String configId = contentConverter.getStringValue(jobId);
        String timeCreated = formatAuditDate(auditEntryEntity.getTimeCreated());
        AuditEntryStatus status = null;
        if (auditEntryEntity.getStatus() != null) {
            status = AuditEntryStatus.valueOf(auditEntryEntity.getStatus());
            overallStatus = getWorstStatus(overallStatus, status);
        }
        String errorMessage = auditEntryEntity.getErrorMessage();
        String errorStackTrace = auditEntryEntity.getErrorStackTrace();
        Optional<DistributionJobModel> distributionJobModel = jobAccessor.getJobById(jobId);
        String distributionConfigName = distributionJobModel.map(DistributionJobModelData::getName).orElse(null);
        String eventType = distributionJobModel.map(DistributionJobModelData::getChannelDescriptorName).orElse(null);
        String statusDisplayName = null;
        if (null != status) {
            statusDisplayName = status.getDisplayName();
        }
        AuditJobStatusModel auditJobStatusModel = new AuditJobStatusModel(jobId, timeCreated, timeLastSent, statusDisplayName);
        jobAuditModels.add(new JobAuditModel(id, configId, distributionConfigName, eventType, auditJobStatusModel, errorMessage, errorStackTrace));
    }
    String id = contentConverter.getStringValue(notificationContentEntry.getId());
    NotificationConfig notificationConfig = populateConfigFromEntity(notificationContentEntry);
    String overallStatusDisplayName = null;
    if (null != overallStatus) {
        overallStatusDisplayName = overallStatus.getDisplayName();
    }
    return new AuditEntryModel(id, notificationConfig, jobAuditModels, overallStatusDisplayName, timeLastSent);
}
Also used : ArrayList(java.util.ArrayList) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) OffsetDateTime(java.time.OffsetDateTime) AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) NotificationConfig(com.synopsys.integration.alert.common.rest.model.NotificationConfig) AuditEntryStatus(com.synopsys.integration.alert.common.enumeration.AuditEntryStatus) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) UUID(java.util.UUID) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AuditEntryStatus (com.synopsys.integration.alert.common.enumeration.AuditEntryStatus)2 AuditJobStatusModel (com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel)2 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)2 OffsetDateTime (java.time.OffsetDateTime)2 UUID (java.util.UUID)2 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)1 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)1 JobAuditModel (com.synopsys.integration.alert.common.rest.model.JobAuditModel)1 NotificationConfig (com.synopsys.integration.alert.common.rest.model.NotificationConfig)1 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)1 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1