use of com.synopsys.integration.alert.common.rest.model.JobFieldModel 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.rest.model.JobFieldModel in project hub-alert by blackducksoftware.
the class JobConfigControllerTestIT method testTestConfig.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testTestConfig() throws Exception {
final String urlPath = REQUEST_URL + "/test";
ConfigurationModel providerGlobalConfig = addGlobalConfiguration(blackDuckProviderKey, Map.of(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, List.of(DEFAULT_BLACK_DUCK_CONFIG), BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of("BLACKDUCK_URL"), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of("BLACKDUCK_API")));
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
JobFieldModel fieldModel = createTestJobFieldModel(null, null, providerGlobalConfig);
request.content(gson.toJson(fieldModel));
request.contentType(MEDIA_TYPE);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
use of com.synopsys.integration.alert.common.rest.model.JobFieldModel in project hub-alert by blackducksoftware.
the class JobConfigControllerTestIT method testSaveConfig.
@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testSaveConfig() throws Exception {
ConfigurationModel providerGlobalConfig = addGlobalConfiguration(blackDuckProviderKey, Map.of(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, List.of(DEFAULT_BLACK_DUCK_CONFIG), BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of(testProperties.getBlackDuckURL()), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of(testProperties.getBlackDuckAPIToken())));
MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(REQUEST_URL).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
JobFieldModel fieldModel = createTestJobFieldModel(null, null, providerGlobalConfig);
request.content(gson.toJson(fieldModel));
request.contentType(MEDIA_TYPE);
mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isCreated());
}
use of com.synopsys.integration.alert.common.rest.model.JobFieldModel in project hub-alert by blackducksoftware.
the class JiraCloudDistributionConfigurationValidator method validate.
@Override
public Set<AlertFieldStatus> validate(JobFieldModel jobFieldModel) {
HashSet<AlertFieldStatus> validationResults = new HashSet<>();
ConfigurationFieldValidator configurationFieldValidator = ConfigurationFieldValidator.fromJobFieldModel(jobFieldModel);
commonChannelDistributionValidator.validate(configurationFieldValidator);
configurationFieldValidator.validateRequiredFieldsAreNotBlank(JiraCloudDescriptor.KEY_JIRA_PROJECT_NAME, JiraCloudDescriptor.KEY_ISSUE_TYPE);
configurationFieldValidator.validateRequiredRelatedSet(JiraCloudDescriptor.KEY_OPEN_WORKFLOW_TRANSITION, JiraCloudDescriptor.LABEL_OPEN_WORKFLOW_TRANSITION, JiraCloudDescriptor.KEY_RESOLVE_WORKFLOW_TRANSITION);
// Validate custom field mappings
jobFieldModel.getFieldModels().stream().filter(fieldModel -> jiraCloudChannelKey.getUniversalKey().equals(fieldModel.getDescriptorName())).findFirst().flatMap(fieldModel -> fieldModel.getFieldValueModel(JiraCloudDescriptor.KEY_FIELD_MAPPING)).flatMap(fieldValueModel -> jiraFieldMappingValidator.validateFieldMappings(JiraCloudDescriptor.KEY_FIELD_MAPPING, fieldValueModel)).ifPresent(validationResults::add);
validationResults.addAll(configurationFieldValidator.getValidationResults());
return validationResults;
}
use of com.synopsys.integration.alert.common.rest.model.JobFieldModel in project hub-alert by blackducksoftware.
the class SlackDistributionConfigurationValidatorTest method testValidate.
@MethodSource("getFieldsAndExpectedErrors")
@ParameterizedTest()
public void testValidate(Map<String, FieldValueModel> fieldModelMap, Set<AlertFieldStatus> expectedValidationErrors) {
JobFieldModel testJobFieldModel = FieldModelUtils.createJobFieldModel(ValidationConstants.COMMON_CHANNEL_FIELDS, fieldModelMap);
CommonChannelDistributionValidator commonChannelDistributionValidator = new CommonChannelDistributionValidator();
SlackDistributionConfigurationValidator validator = new SlackDistributionConfigurationValidator(commonChannelDistributionValidator);
Set<AlertFieldStatus> validationErrors = validator.validate(testJobFieldModel);
Assertions.assertEquals(expectedValidationErrors, validationErrors);
}
Aggregations