use of com.synopsys.integration.alert.database.job.DistributionJobEntity in project hub-alert by blackducksoftware.
the class StaticJobAccessor method getPageOfJobs.
@Override
@Transactional(readOnly = true)
public AlertPagedModel<DistributionJobModel> getPageOfJobs(int pageNumber, int pageLimit, String searchTerm, Collection<String> descriptorsNamesToInclude) {
if (!descriptorsNamesToInclude.contains(blackDuckProviderKey.getUniversalKey())) {
return new AlertPagedModel<>(0, pageNumber, pageLimit, List.of());
}
PageRequest pageRequest = PageRequest.of(pageNumber, pageLimit);
Page<DistributionJobEntity> pageOfJobsWithDescriptorNames;
if (StringUtils.isBlank(searchTerm)) {
pageOfJobsWithDescriptorNames = distributionJobRepository.findByChannelDescriptorNameIn(descriptorsNamesToInclude, pageRequest);
} else {
pageOfJobsWithDescriptorNames = distributionJobRepository.findByChannelDescriptorNamesAndSearchTerm(descriptorsNamesToInclude, searchTerm, pageRequest);
}
List<DistributionJobModel> configurationJobModels = pageOfJobsWithDescriptorNames.map(this::convertToDistributionJobModelFromEntity).getContent();
return new AlertPagedModel<>(pageOfJobsWithDescriptorNames.getTotalPages(), pageNumber, pageLimit, configurationJobModels);
}
use of com.synopsys.integration.alert.database.job.DistributionJobEntity in project hub-alert by blackducksoftware.
the class StaticJobAccessor method updateJob.
@Override
@Transactional
public DistributionJobModel updateJob(UUID jobId, DistributionJobRequestModel requestModel) throws AlertConfigurationException {
DistributionJobEntity jobEntity = distributionJobRepository.findById(jobId).orElseThrow(() -> new AlertConfigurationException(String.format("No job exists with the id [%s]", jobId)));
OffsetDateTime createdAt = jobEntity.getCreatedAt();
if (!jobEntity.getChannelDescriptorName().equals(requestModel.getChannelDescriptorName())) {
// Deleting a Job will affect all tables with foreign keys referencing it.
// Only delete a job if the channel for which it is configured changes.
deleteJob(jobId);
}
return createJobWithId(jobId, requestModel, createdAt, DateUtils.createCurrentDateTimestamp());
}
use of com.synopsys.integration.alert.database.job.DistributionJobEntity in project hub-alert by blackducksoftware.
the class StaticJobAccessor method createJobWithId.
private DistributionJobModel createJobWithId(UUID jobId, DistributionJobRequestModel requestModel, OffsetDateTime createdAt, @Nullable OffsetDateTime lastUpdated) {
String channelDescriptorName = requestModel.getChannelDescriptorName();
DistributionJobEntity jobToSave = new DistributionJobEntity(jobId, requestModel.getName(), requestModel.isEnabled(), requestModel.getDistributionFrequency().name(), requestModel.getProcessingType().name(), channelDescriptorName, requestModel.getChannelGlobalConfigId(), createdAt, lastUpdated);
DistributionJobEntity savedJobEntity = distributionJobRepository.save(jobToSave);
UUID savedJobId = savedJobEntity.getJobId();
BlackDuckJobDetailsEntity savedBlackDuckJobDetails = blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(savedJobId, requestModel);
savedJobEntity.setBlackDuckJobDetails(savedBlackDuckJobDetails);
DistributionJobDetailsModel distributionJobDetails = requestModel.getDistributionJobDetails();
if (distributionJobDetails.isA(ChannelKeys.AZURE_BOARDS)) {
AzureBoardsJobDetailsEntity savedAzureBoardsJobDetails = azureBoardsJobDetailsAccessor.saveAzureBoardsJobDetails(savedJobId, distributionJobDetails.getAs(DistributionJobDetailsModel.AZURE));
savedJobEntity.setAzureBoardsJobDetails(savedAzureBoardsJobDetails);
} else if (distributionJobDetails.isA(ChannelKeys.JIRA_CLOUD)) {
JiraCloudJobDetailsEntity savedJiraCloudJobDetails = jiraCloudJobDetailsAccessor.saveJiraCloudJobDetails(savedJobId, distributionJobDetails.getAs(DistributionJobDetailsModel.JIRA_CLOUD));
savedJobEntity.setJiraCloudJobDetails(savedJiraCloudJobDetails);
} else if (distributionJobDetails.isA(ChannelKeys.MS_TEAMS)) {
MSTeamsJobDetailsEntity savedMSTeamsJobDetails = msTeamsJobDetailsAccessor.saveMSTeamsJobDetails(savedJobId, distributionJobDetails.getAs(DistributionJobDetailsModel.MS_TEAMS));
savedJobEntity.setMsTeamsJobDetails(savedMSTeamsJobDetails);
} else if (distributionJobDetails.isA(ChannelKeys.SLACK)) {
SlackJobDetailsEntity savedSlackJobDetails = slackJobDetailsAccessor.saveSlackJobDetails(savedJobId, distributionJobDetails.getAs(DistributionJobDetailsModel.SLACK));
savedJobEntity.setSlackJobDetails(savedSlackJobDetails);
} else {
// In the future the contents of this else case should be the complete implementation of this method
ChannelKey channelKey = ChannelKeys.getChannelKey(channelDescriptorName);
if (jobDetailsAccessorMap.containsKey(channelKey) && distributionJobDetails.isA(channelKey)) {
JobDetailsAccessor2<? extends DistributionJobDetailsModel> accessor = jobDetailsAccessorMap.get(channelKey);
DistributionJobDetailsModel savedJobDetails = accessor.saveJobDetails(savedJobId, distributionJobDetails);
return convertToDistributionJobModel(savedJobEntity, savedJobDetails);
}
}
return convertToDistributionJobModel(savedJobEntity);
}
use of com.synopsys.integration.alert.database.job.DistributionJobEntity in project hub-alert by blackducksoftware.
the class DefaultProcessingJobAccessor method getMatchingEnabledJobsByFilteredNotifications.
@Override
public AlertPagedModel<FilteredDistributionJobResponseModel> getMatchingEnabledJobsByFilteredNotifications(FilteredDistributionJobRequestModel filteredDistributionJobRequestModel, int pageNumber, int pageLimit) {
List<String> frequencyTypes = filteredDistributionJobRequestModel.getFrequencyTypes().stream().map(Enum::name).collect(Collectors.toList());
Set<String> projectNames = filteredDistributionJobRequestModel.getProjectName();
Set<String> notificationTypes = filteredDistributionJobRequestModel.getNotificationTypes();
// If no policies and/or vulnerabilitySeverities exist the repository query expects a null to be passed
Set<String> policyNames = filteredDistributionJobRequestModel.getPolicyNames().isEmpty() ? null : filteredDistributionJobRequestModel.getPolicyNames();
Set<String> vulnerabilitySeverities = filteredDistributionJobRequestModel.getVulnerabilitySeverities().isEmpty() ? null : filteredDistributionJobRequestModel.getVulnerabilitySeverities();
PageRequest pageRequest = PageRequest.of(pageNumber, pageLimit);
Page<DistributionJobEntity> pageOfDistributionJobEntities = distributionJobRepository.findAndSortMatchingEnabledJobsByFilteredNotifications(filteredDistributionJobRequestModel.getProviderConfigId(), frequencyTypes, notificationTypes, projectNames, policyNames, vulnerabilitySeverities, pageRequest);
List<FilteredDistributionJobResponseModel> distributionJobResponseModels = pageOfDistributionJobEntities.getContent().stream().map(this::convertToFilteredDistributionJobResponseModel).collect(Collectors.toList());
return new AlertPagedModel<>(pageOfDistributionJobEntities.getTotalPages(), pageNumber, pageLimit, distributionJobResponseModels);
}
use of com.synopsys.integration.alert.database.job.DistributionJobEntity in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method getPageOfJobsTest.
@Test
void getPageOfJobsTest() {
UUID jobId = UUID.randomUUID();
DistributionJobEntity distributionJobEntity = createSlackDistributionJobEntity(jobId);
distributionJobEntity.setBlackDuckJobDetails(new BlackDuckJobDetailsEntity(jobId, 3L, true, "*", "*"));
Page<DistributionJobEntity> page = new PageImpl<>(List.of(distributionJobEntity));
Mockito.when(distributionJobRepository.findAll(Mockito.any(PageRequest.class))).thenReturn(page);
AlertPagedModel<DistributionJobModel> pageOfJobs = jobAccessor.getPageOfJobs(0, 10);
assertEquals(1, pageOfJobs.getTotalPages());
List<DistributionJobModel> models = pageOfJobs.getModels();
assertEquals(1, models.size());
DistributionJobModel distributionJobModel = models.get(0);
assertEquals(jobId, distributionJobModel.getJobId());
assertEquals(jobName, distributionJobModel.getName());
}
Aggregations