use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class JobConfigActions method validateJobsById.
public ActionResponse<List<JobFieldStatuses>> validateJobsById(JobIdsRequestModel jobIdsValidationModel) {
List<PermissionKey> keys = gatherPermissionKeys();
if (!getAuthorizationManager().anyReadPermission(keys)) {
return ActionResponse.createForbiddenResponse();
}
List<UUID> jobIdsToValidate = jobIdsValidationModel.getJobIds();
if (null == jobIdsToValidate || jobIdsToValidate.isEmpty()) {
return new ActionResponse<>(HttpStatus.OK, List.of());
}
List<DistributionJobModel> distributionJobModels = jobAccessor.getJobsById(jobIdsToValidate);
List<JobFieldModel> jobFieldModels = new LinkedList<>();
for (DistributionJobModel distributionJobModel : distributionJobModels) {
JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
jobFieldModels.add(jobFieldModel);
}
return validateJobFieldModels(jobFieldModels);
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class JobConfigActions method createDistributionJobRequestModel.
private DistributionJobRequestModel createDistributionJobRequestModel(Collection<ConfigurationFieldModel> configFieldModels, List<JobProviderProjectFieldModel> jobProjects, OffsetDateTime createdAt, @Nullable OffsetDateTime lastUpdated) throws AlertException {
List<BlackDuckProjectDetailsModel> projectFilterDetails = jobProjects.stream().map(jobProject -> new BlackDuckProjectDetailsModel(jobProject.getName(), jobProject.getHref())).collect(Collectors.toList());
Map<String, ConfigurationFieldModel> configuredFieldsMap = DataStructureUtils.mapToValues(configFieldModels, ConfigurationFieldModel::getFieldKey);
DistributionJobModel fromResource = distributionJobModelExtractor.convertToJobModel(null, configuredFieldsMap, createdAt, lastUpdated, projectFilterDetails);
return new DistributionJobRequestModel(fromResource.isEnabled(), fromResource.getName(), fromResource.getDistributionFrequency(), fromResource.getProcessingType(), fromResource.getChannelDescriptorName(), fromResource.getChannelGlobalConfigId(), fromResource.getBlackDuckGlobalConfigId(), fromResource.isFilterByProject(), fromResource.getProjectNamePattern().orElse(null), fromResource.getProjectVersionNamePattern().orElse(null), fromResource.getNotificationTypes(), projectFilterDetails, fromResource.getPolicyFilterPolicyNames(), fromResource.getVulnerabilityFilterSeverityNames(), fromResource.getDistributionJobDetails());
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class JobConfigControllerTestIT method testGetValidationResultsForJobs.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetValidationResultsForJobs() throws Exception {
final String urlPath = REQUEST_URL + "/validateJobsById";
DistributionJobModel distributionJobModel = createAndSaveMockDistributionJob(-1L);
JobIdsRequestModel jobIdsRequestModel = new JobIdsRequestModel(List.of(distributionJobModel.getJobId()));
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(jobIdsRequestModel)).contentType(MEDIA_TYPE);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class JobConfigControllerTestIT method testGetConfigById.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetConfigById() throws Exception {
DistributionJobModel distributionJobModel = createAndSaveMockDistributionJob(-1L);
String configId = String.valueOf(distributionJobModel.getJobId());
String urlPath = REQUEST_URL + "/" + configId;
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class DistributionChannelMessageFieldModelTestActionTest method testConfigTest.
@Test
public void testConfigTest() throws AlertException {
String expectedStatusMessage = "Test Result";
DistributionChannelMessageTestAction<MockDistributionJobDetailsModel> testAction = createTestAction(expectedStatusMessage);
DistributionJobModel distributionJobModel = createDistributionJobModel();
MessageResult messageResult = testAction.testConfig(distributionJobModel, "jobName", "Test Topic", "Test Message");
assertEquals(expectedStatusMessage, messageResult.getStatusMessage());
}
Aggregations