use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class DistributionChannelMessageFieldModelTestActionTest method testConfigWithNullParamsTest.
@Test
public void testConfigWithNullParamsTest() throws AlertException {
String expectedStatusMessage = "Test Result for null test";
DistributionChannelMessageTestAction<MockDistributionJobDetailsModel> testAction = createTestAction(expectedStatusMessage);
DistributionJobModel distributionJobModel = createDistributionJobModel();
MessageResult messageResult = testAction.testConfig(distributionJobModel, "jobName", null, null);
assertEquals(expectedStatusMessage, messageResult.getStatusMessage());
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class EmailTestActionHelperTest method verifyAllProjectsProperlyRetrieved.
@Test
public void verifyAllProjectsProperlyRetrieved() throws AlertException {
ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
List<ProviderProject> providerProjects = createProviderProjects();
Mockito.when(providerDataAccessor.getProjectsByProviderConfigId(Mockito.anyLong())).thenReturn(providerProjects);
Mockito.when(providerDataAccessor.getEmailAddressesForProjectHref(Mockito.anyLong(), Mockito.anyString())).thenAnswer(i -> Set.of(UUID.randomUUID().toString()));
EmailTestActionHelper emailTestActionHelper = new EmailTestActionHelper(providerDataAccessor);
DistributionJobModel distributionJobModel = createDefaultDistributionJobModel();
Set<String> emailAddresses = emailTestActionHelper.createUpdatedEmailAddresses(distributionJobModel);
assertEquals(providerProjects.size(), emailAddresses.size());
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class AuditEntryActions method resendNotification.
public ActionResponse<AuditEntryPageModel> resendNotification(Long notificationId, @Nullable UUID requestedJobId) {
if (!authorizationManager.hasExecutePermission(ConfigContextEnum.GLOBAL, descriptorKey)) {
return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
}
Optional<AlertNotificationModel> notification = notificationAccessor.findById(notificationId);
if (notification.isEmpty()) {
return new ActionResponse<>(HttpStatus.GONE, "No notification with this id exists.");
}
AlertNotificationModel notificationContent = notification.get();
if (null != requestedJobId) {
Optional<DistributionJobModel> optionalDistributionJob = jobAccessor.getJobById(requestedJobId);
if (optionalDistributionJob.isEmpty()) {
String message = String.format("The Distribution Job with this id could not be found. %s", requestedJobId.toString());
return new ActionResponse<>(HttpStatus.GONE, message);
}
DistributionJobModel distributionJob = optionalDistributionJob.get();
if (distributionJob.isEnabled()) {
ProcessedNotificationDetails processedNotificationDetails = ProcessedNotificationDetails.fromDistributionJob(distributionJob);
jobNotificationProcessor.processNotificationForJob(processedNotificationDetails, distributionJob.getProcessingType(), List.of(notificationContent));
} else {
UUID jobConfigId = distributionJob.getJobId();
logger.warn("The Distribution Job with Id {} was disabled. This notification could not be sent", jobConfigId);
String message = String.format("The Distribution Job is currently disabled. %s", jobConfigId);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, message);
}
} else {
notificationProcessor.processNotifications(List.of(notificationContent), List.of(FrequencyType.DAILY, FrequencyType.REAL_TIME));
}
return get();
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class JobConfigActionsTest method getPageTest.
@Test
public void getPageTest() throws Exception {
int totalPages = 1;
int pageNumber = 0;
int pageSize = 10;
RegisteredDescriptorModel registeredDescriptorModel = new RegisteredDescriptorModel(1L, "descriptorName", DESCRIPTOR_TYPE.name());
AlertPagedModel<DistributionJobModel> pageOfJobs = new AlertPagedModel<>(totalPages, pageNumber, pageSize, List.of(distributionJobModel));
Mockito.when(mockedDescriptorAccessor.getRegisteredDescriptors()).thenReturn(List.of(registeredDescriptorModel));
Mockito.when(mockedJobAccessor.getPageOfJobs(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString(), Mockito.anyCollection())).thenReturn(pageOfJobs);
Mockito.when(mockedConfigurationFieldModelConverter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
ActionResponse<JobPagedModel> jobPagedModelActionResponse = defaultJobConfigActions.getPage(pageNumber, pageSize, "");
assertTrue(jobPagedModelActionResponse.isSuccessful());
assertTrue(jobPagedModelActionResponse.hasContent());
assertEquals(HttpStatus.OK, jobPagedModelActionResponse.getHttpStatus());
}
Aggregations