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);
}
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);
}
Aggregations