use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryControllerTestIT method testGetConfigWithId.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetConfigWithId() throws Exception {
AuditEntryEntity entity = mockAuditEntryEntity.createEntity();
entity = auditEntryRepository.save(entity);
NotificationEntity notificationContent = mockNotificationContent.createEntity();
notificationContent = notificationRepository.save(notificationContent);
auditNotificationRepository.save(new AuditNotificationRelation(entity.getId(), notificationContent.getId()));
String getUrl = auditUrl + "/" + notificationContent.getId();
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(getUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryControllerTestIT method testGetAuditInfoForJob.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetAuditInfoForJob() throws Exception {
AuditEntryEntity entity = mockAuditEntryEntity.createEntity();
entity = auditEntryRepository.save(entity);
String getUrl = auditUrl + "/job/" + entity.getCommonConfigId();
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(getUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity 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);
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity 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);
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class NotificationAccessorTestIT method testFindAllWithSearchByFieldValue.
@Test
public void testFindAllWithSearchByFieldValue() {
NotificationEntity notificationContent = createNotificationContent();
notificationContent = notificationContentRepository.save(notificationContent);
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
DistributionJobEntity distributionJobEntity = new DistributionJobEntity(null, "job_name", true, FrequencyType.REAL_TIME.name(), ProcessingType.DEFAULT.name(), ChannelKeys.EMAIL.getUniversalKey(), UUID.randomUUID(), currentTime, null);
DistributionJobEntity savedJob = distributionJobRepository.save(distributionJobEntity);
final String auditStatus = "audit status thing";
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(savedJob.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), auditStatus, "", "");
auditEntryEntity = auditEntryRepository.save(auditEntryEntity);
AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryEntity.getId(), notificationContent.getId());
auditNotificationRepository.save(auditNotificationRelation);
PageRequest pageRequest = PageRequest.of(0, 10);
Page<AlertNotificationModel> all = notificationManager.findAllWithSearch(ChannelKeys.EMAIL.getUniversalKey(), pageRequest, false);
// Search term should match the channel name
assertFalse(all.isEmpty());
}
Aggregations