use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class AuditEntryHandlerTestIT method getGetAuditInfoForJobIT.
@Test
public void getGetAuditInfoForJobIT() {
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel job = jobAccessor.createJob(jobRequestModel);
AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(job.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasReadPermission(Mockito.eq(ConfigContextEnum.GLOBAL), Mockito.eq(auditDescriptorKey))).thenReturn(true);
AuditEntryActions auditEntryController = createAuditActions(authorizationManager);
AuditJobStatusModel jobStatusModel = auditEntryController.getAuditInfoForJob(savedAuditEntryEntity.getCommonConfigId()).getContent().orElse(null);
assertNotNull(jobStatusModel);
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class JobConfigActions method createWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> createWithoutChecks(JobFieldModel resource) {
try {
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeSaveEventFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
Collection<ConfigurationFieldModel> savedFieldsModels = modelConverter.convertToConfigurationFieldModelMap(beforeSaveEventFieldModel).values();
configurationFieldModels.addAll(savedFieldsModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, DateUtils.createCurrentDateTimestamp(), null);
DistributionJobModel savedJob = jobAccessor.createJob(jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel updatedModel = fieldModelProcessor.performAfterSaveAction(fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} catch (AlertException ex) {
logger.error("Error creating job", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class JobConfigActions method updateWithoutChecks.
@Override
protected ActionResponse<JobFieldModel> updateWithoutChecks(UUID id, JobFieldModel resource) {
try {
Optional<DistributionJobModel> jobModel = jobAccessor.getJobById(id);
if (jobModel.isPresent()) {
DistributionJobModel previousJob = jobModel.get();
JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(previousJob);
Map<String, FieldModel> descriptorAndContextToPreviousFieldModel = new HashMap<>();
for (FieldModel previousJobFieldModel : jobFieldModel.getFieldModels()) {
descriptorAndContextToPreviousFieldModel.put(previousJobFieldModel.getDescriptorName() + previousJobFieldModel.getContext(), previousJobFieldModel);
}
Set<ConfigurationFieldModel> configurationFieldModels = new HashSet<>();
for (FieldModel fieldModel : resource.getFieldModels()) {
FieldModel beforeUpdateEventFieldModel = fieldModelProcessor.performBeforeUpdateAction(fieldModel);
String beforeFieldModelId = beforeUpdateEventFieldModel.getId();
Long fieldModelId = (StringUtils.isNotBlank(beforeFieldModelId)) ? Long.parseLong(beforeFieldModelId) : null;
Collection<ConfigurationFieldModel> updatedFieldModels = fieldModelProcessor.fillFieldModelWithExistingData(fieldModelId, beforeUpdateEventFieldModel);
configurationFieldModels.addAll(updatedFieldModels);
}
List<JobProviderProjectFieldModel> configuredProviderProjects = Optional.ofNullable(resource.getConfiguredProviderProjects()).orElse(List.of());
DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(configurationFieldModels, configuredProviderProjects, previousJob.getCreatedAt(), DateUtils.createCurrentDateTimestamp());
DistributionJobModel savedJob = jobAccessor.updateJob(previousJob.getJobId(), jobRequestModel);
JobFieldModel savedJobFieldModel = JobFieldModelPopulationUtils.createJobFieldModel(savedJob, configuredProviderProjects);
Set<FieldModel> updatedFieldModels = new HashSet<>();
for (FieldModel fieldModel : savedJobFieldModel.getFieldModels()) {
FieldModel previousFieldModel = descriptorAndContextToPreviousFieldModel.get(fieldModel.getDescriptorName() + fieldModel.getContext());
FieldModel updatedModel = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, fieldModel);
updatedFieldModels.add(updatedModel);
}
savedJobFieldModel.setFieldModels(updatedFieldModels);
return new ActionResponse<>(HttpStatus.OK, savedJobFieldModel);
} else {
return new ActionResponse<>(HttpStatus.NOT_FOUND);
}
} catch (AlertException ex) {
logger.error("Error creating job", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class BlackDuckJobDetailsAccessorTest method saveBlackDuckJobDetailsTest.
@Test
public void saveBlackDuckJobDetailsTest() {
UUID jobId = UUID.randomUUID();
DistributionJobRequestModel distributionJobRequestModel = new DistributionJobRequestModel(true, jobName, FrequencyType.DAILY, ProcessingType.DEFAULT, null, UUID.randomUUID(), 3L, true, "*", "*", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null);
BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = new BlackDuckJobDetailsEntity(jobId, distributionJobRequestModel.getBlackDuckGlobalConfigId(), distributionJobRequestModel.isFilterByProject(), distributionJobRequestModel.getProjectNamePattern().orElse(null), distributionJobRequestModel.getProjectVersionNamePattern().orElse(null));
BlackDuckJobNotificationTypeEntity blackDuckJobNotificationTypeEntity = new BlackDuckJobNotificationTypeEntity(jobId, "testNotificationType");
BlackDuckJobProjectEntity blackDuckJobProjectEntity = new BlackDuckJobProjectEntity();
BlackDuckJobPolicyFilterEntity blackDuckJobPolicyFilterEntity = new BlackDuckJobPolicyFilterEntity();
BlackDuckJobVulnerabilitySeverityFilterEntity blackDuckJobVulnerabilitySeverityFilterEntity = new BlackDuckJobVulnerabilitySeverityFilterEntity();
Mockito.when(blackDuckJobDetailsRepository.save(Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
Mockito.when(blackDuckJobNotificationTypeRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobNotificationTypeEntity));
Mockito.when(blackDuckJobProjectRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobProjectEntity));
Mockito.when(blackDuckJobPolicyFilterRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobPolicyFilterEntity));
Mockito.when(blackDuckJobVulnerabilitySeverityFilterRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobVulnerabilitySeverityFilterEntity));
BlackDuckJobDetailsEntity createdBlackDuckJobDetailsEntity = blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(jobId, distributionJobRequestModel);
Mockito.verify(blackDuckJobNotificationTypeRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
Mockito.verify(blackDuckJobProjectRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
Mockito.verify(blackDuckJobPolicyFilterRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
Mockito.verify(blackDuckJobVulnerabilitySeverityFilterRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
assertEquals(jobId, createdBlackDuckJobDetailsEntity.getJobId());
assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobNotificationTypes().size());
assertEquals(blackDuckJobNotificationTypeEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobNotificationTypes().get(0));
assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobProjects().size());
assertEquals(blackDuckJobProjectEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobProjects().get(0));
assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobPolicyFilters().size());
assertEquals(blackDuckJobPolicyFilterEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobPolicyFilters().get(0));
assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobVulnerabilitySeverityFilters().size());
assertEquals(blackDuckJobVulnerabilitySeverityFilterEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobVulnerabilitySeverityFilters().get(0));
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class JobNotificationMapperTestIT method extractJobsWithMatchingProjectNamePatternFilter.
@Test
public void extractJobsWithMatchingProjectNamePatternFilter() {
createJobs(List.of(new DistributionJobRequestModel(true, "name", FrequencyType.REAL_TIME, ProcessingType.DIGEST, ChannelKeys.SLACK.getUniversalKey(), UUID.randomUUID(), 0L, true, // Regex to verify we retrieve notifications without a number in the name (PROJECT_NAME_1)
"^([^0-9]*)$", null, List.of(NotificationType.VULNERABILITY.name()), List.of(), List.of(), List.of(), new SlackJobDetailsModel(null, "webhook", "channelName", "username"))));
testProjectJob();
}
Aggregations