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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations