Search in sources :

Example 1 with JobAuditModel

use of com.synopsys.integration.alert.common.rest.model.JobAuditModel in project hub-alert by blackducksoftware.

the class DefaultRestApiAuditAccessorTest method convertToAuditEntryModelFromNotificationTest.

@Test
public void convertToAuditEntryModelFromNotificationTest() throws Exception {
    Long id = 1L;
    Long providerConfigId = 2L;
    String provider = "provider-test";
    String providerConfigName = "providerConfigName-test";
    String notificationType = "notificationType-test";
    String content = "content-test";
    OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime timeCreated = timeLastSent.minusSeconds(10);
    Long auditEntryId = 3L;
    String channelName = "test-channel.common.name-value";
    String eventType = "test-channel.common.channel.name-value";
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
    AlertNotificationModel alertNotificationModel = new AlertNotificationModel(id, providerConfigId, provider, providerConfigName, notificationType, content, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
    AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryId, alertNotificationModel.getId());
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(UUID.randomUUID(), timeCreated, timeLastSent, AuditEntryStatus.SUCCESS.name(), null, null);
    Mockito.when(auditNotificationRepository.findByNotificationId(Mockito.any())).thenReturn(List.of(auditNotificationRelation));
    Mockito.when(auditEntryRepository.findAllById(Mockito.any())).thenReturn(List.of(auditEntryEntity));
    DistributionJobModel distributionJob = DistributionJobModel.builder().jobId(UUID.randomUUID()).enabled(true).blackDuckGlobalConfigId(2L).channelDescriptorName("test-channel.common.channel.name-value").name("test-channel.common.name-value").distributionFrequency(FrequencyType.REAL_TIME).filterByProject(false).notificationTypes(List.of(NotificationType.LICENSE_LIMIT.name())).processingType(ProcessingType.DEFAULT).createdAt(DateUtils.createCurrentDateTimestamp()).build();
    Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(Optional.of(distributionJob));
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, configurationModelConfigurationAccessor, null, contentConverter);
    AuditEntryModel testAuditEntryModel = auditUtility.convertToAuditEntryModelFromNotification(alertNotificationModel);
    assertEquals(id, Long.valueOf(testAuditEntryModel.getId()));
    assertNotNull(testAuditEntryModel.getNotification());
    assertFalse(testAuditEntryModel.getJobs().isEmpty());
    assertEquals(1, testAuditEntryModel.getJobs().size());
    JobAuditModel testJob = testAuditEntryModel.getJobs().get(0);
    assertEquals(channelName, testJob.getName());
    assertEquals(eventType, testJob.getEventType());
    assertEquals(AuditEntryStatus.SUCCESS.getDisplayName(), testAuditEntryModel.getOverallStatus());
    assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testAuditEntryModel.getLastSent());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) OffsetDateTime(java.time.OffsetDateTime) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Test(org.junit.jupiter.api.Test)

Example 2 with JobAuditModel

use of com.synopsys.integration.alert.common.rest.model.JobAuditModel in project hub-alert by blackducksoftware.

the class JobAuditModelTest method testModel.

@Test
public void testModel() {
    String id = "1";
    String configId = "22";
    String name = "name";
    String eventType = "eventType";
    String timeAuditCreated = new Date(400).toString();
    String timeLastSent = new Date(500).toString();
    String status = AuditEntryStatus.SUCCESS.name();
    String errorMessage = "errorMessage";
    String errorStackTrace = "errorStackTrace";
    AuditJobStatusModel auditJobStatusModel = new AuditJobStatusModel(UUID.randomUUID(), timeAuditCreated, timeLastSent, status);
    JobAuditModel restModel = new JobAuditModel(id, configId, name, eventType, auditJobStatusModel, errorMessage, errorStackTrace);
    assertEquals(errorMessage, restModel.getErrorMessage());
    assertEquals(errorStackTrace, restModel.getErrorStackTrace());
    assertEquals(eventType, restModel.getEventType());
    assertEquals(name, restModel.getName());
    assertEquals(status, restModel.getAuditJobStatusModel().getStatus());
    assertEquals(timeAuditCreated, restModel.getAuditJobStatusModel().getTimeAuditCreated());
    assertEquals(timeLastSent, restModel.getAuditJobStatusModel().getTimeLastSent());
    assertEquals(configId, restModel.getConfigId());
    assertEquals(id, restModel.getId());
}
Also used : AuditJobStatusModel(com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with JobAuditModel

use of com.synopsys.integration.alert.common.rest.model.JobAuditModel in project hub-alert by blackducksoftware.

the class AuditEntryRestModelTest method testRestModel.

@Test
public void testRestModel() {
    String id = "1";
    String timeLastSent = new Date(500).toString();
    String overallStatus = AuditEntryStatus.SUCCESS.name();
    NotificationConfig notification = new NotificationConfig();
    List<JobAuditModel> jobAuditModels = Collections.singletonList(new JobAuditModel());
    AuditEntryModel restModel = new AuditEntryModel(id, notification, jobAuditModels, overallStatus, timeLastSent);
    assertEquals(notification, restModel.getNotification());
    assertEquals(jobAuditModels, restModel.getJobs());
    assertEquals(overallStatus, restModel.getOverallStatus());
    assertEquals(timeLastSent, restModel.getLastSent());
    assertEquals(id, restModel.getId());
}
Also used : NotificationConfig(com.synopsys.integration.alert.common.rest.model.NotificationConfig) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) Date(java.util.Date) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Test(org.junit.jupiter.api.Test)

Example 4 with JobAuditModel

use of com.synopsys.integration.alert.common.rest.model.JobAuditModel 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

JobAuditModel (com.synopsys.integration.alert.common.rest.model.JobAuditModel)4 AuditEntryModel (com.synopsys.integration.alert.common.persistence.model.AuditEntryModel)3 Test (org.junit.jupiter.api.Test)3 AuditJobStatusModel (com.synopsys.integration.alert.common.persistence.model.AuditJobStatusModel)2 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 NotificationConfig (com.synopsys.integration.alert.common.rest.model.NotificationConfig)2 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)2 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)2 OffsetDateTime (java.time.OffsetDateTime)2 Date (java.util.Date)2 ContentConverter (com.synopsys.integration.alert.common.ContentConverter)1 AuditEntryStatus (com.synopsys.integration.alert.common.enumeration.AuditEntryStatus)1 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)1 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)1 AuditEntryRepository (com.synopsys.integration.alert.database.audit.AuditEntryRepository)1 AuditNotificationRepository (com.synopsys.integration.alert.database.audit.AuditNotificationRepository)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)1