Search in sources :

Example 1 with BlackDuckJobDetailsEntity

use of com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity 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 2 with BlackDuckJobDetailsEntity

use of com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity 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)

Example 3 with BlackDuckJobDetailsEntity

use of com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity in project hub-alert by blackducksoftware.

the class StaticJobAccessorTest method createJiraServerJobTest.

@Test
void createJiraServerJobTest() {
    UUID jobId = UUID.randomUUID();
    JiraServerJobDetailsModel jiraServerJobDetailsModel = new JiraServerJobDetailsModel(jobId, false, null, null, null, null, null, List.of(), "issueSummary");
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.JIRA_SERVER.getUniversalKey(), jiraServerJobDetailsModel);
    JiraServerJobDetailsEntity jiraServerJobDetailsEntity = new JiraServerJobDetailsEntity(null, false, null, null, null, null, null, null);
    jiraServerJobDetailsEntity.setJobCustomFields(List.of());
    DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
    distributionJobEntity.setJiraServerJobDetails(jiraServerJobDetailsEntity);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
    Mockito.when(jiraServerJobDetailsAccessor.saveJobDetails(Mockito.any(), Mockito.any())).thenReturn(jiraServerJobDetailsModel);
    Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
    DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
    assertEquals(jobId, createdJob.getJobId());
    assertEquals(jobName, createdJob.getName());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) JiraServerJobDetailsEntity(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) JiraServerJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel) 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)

Example 4 with BlackDuckJobDetailsEntity

use of com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity in project hub-alert by blackducksoftware.

the class StaticJobAccessorTest method createJiraCloudJobTest.

@Test
void createJiraCloudJobTest() {
    UUID jobId = UUID.randomUUID();
    JiraCloudJobDetailsModel jiraCloudJobDetailsModel = new JiraCloudJobDetailsModel(jobId, false, null, null, null, null, null, List.of(), null);
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.JIRA_CLOUD.getUniversalKey(), jiraCloudJobDetailsModel);
    JiraCloudJobDetailsEntity jiraCloudJobDetailsEntity = new JiraCloudJobDetailsEntity(null, false, null, null, null, null, null, null);
    jiraCloudJobDetailsEntity.setJobCustomFields(List.of());
    DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
    distributionJobEntity.setJiraCloudJobDetails(jiraCloudJobDetailsEntity);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
    Mockito.when(jiraCloudJobDetailsAccessor.saveJiraCloudJobDetails(Mockito.any(), Mockito.any())).thenReturn(jiraCloudJobDetailsEntity);
    Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
    DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
    assertEquals(jobId, createdJob.getJobId());
    assertEquals(jobName, createdJob.getName());
}
Also used : JiraCloudJobDetailsEntity(com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) UUID(java.util.UUID) JiraCloudJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) 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)

Example 5 with BlackDuckJobDetailsEntity

use of com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity in project hub-alert by blackducksoftware.

the class StaticJobAccessorTest method createMSTeamsJobTest.

@Test
void createMSTeamsJobTest() {
    UUID jobId = UUID.randomUUID();
    MSTeamsJobDetailsModel msTeamsJobDetailsModel = new MSTeamsJobDetailsModel(jobId, null);
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.MS_TEAMS.getUniversalKey(), msTeamsJobDetailsModel);
    MSTeamsJobDetailsEntity msTeamsJobDetailsEntity = new MSTeamsJobDetailsEntity();
    DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
    distributionJobEntity.setMsTeamsJobDetails(msTeamsJobDetailsEntity);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
    Mockito.when(msTeamsJobDetailsAccessor.saveMSTeamsJobDetails(Mockito.any(), Mockito.any())).thenReturn(msTeamsJobDetailsEntity);
    Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
    DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
    assertEquals(jobId, createdJob.getJobId());
    assertEquals(jobName, createdJob.getName());
}
Also used : MSTeamsJobDetailsEntity(com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) 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

BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)17 UUID (java.util.UUID)17 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)15 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)14 Test (org.junit.jupiter.api.Test)14 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)7 PageImpl (org.springframework.data.domain.PageImpl)4 SlackJobDetailsEntity (com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity)3 BlackDuckProjectDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel)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 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 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)2 ProviderKey (com.synopsys.integration.alert.descriptor.api.model.ProviderKey)2 PageRequest (org.springframework.data.domain.PageRequest)2 EmailJobDetailsEntity (com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity)1 JiraServerJobDetailsEntity (com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity)1