Search in sources :

Example 1 with DistributionJobEntity

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);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DistributionJobEntity

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());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) OffsetDateTime(java.time.OffsetDateTime) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DistributionJobEntity

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);
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JiraCloudJobDetailsEntity(com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity) MSTeamsJobDetailsEntity(com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity) JobDetailsAccessor2(com.synopsys.integration.alert.common.persistence.accessor.JobDetailsAccessor2) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) AzureBoardsJobDetailsEntity(com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) UUID(java.util.UUID) SlackJobDetailsEntity(com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)

Example 4 with DistributionJobEntity

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);
}
Also used : FilteredDistributionJobResponseModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel) PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel)

Example 5 with DistributionJobEntity

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());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) UUID(java.util.UUID) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Aggregations

DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)21 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)15 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)15 UUID (java.util.UUID)15 Test (org.junit.jupiter.api.Test)15 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)7 PageRequest (org.springframework.data.domain.PageRequest)5 SlackJobDetailsEntity (com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity)4 PageImpl (org.springframework.data.domain.PageImpl)4 EmailJobDetailsEntity (com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity)2 EmailJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel)2 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)2 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)2 AzureBoardsJobDetailsEntity (com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity)2 JiraCloudJobDetailsEntity (com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity)2 MSTeamsJobDetailsEntity (com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity)2 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)2 ProviderKey (com.synopsys.integration.alert.descriptor.api.model.ProviderKey)2 OffsetDateTime (java.time.OffsetDateTime)2 Transactional (org.springframework.transaction.annotation.Transactional)2