Search in sources :

Example 21 with JobFieldModel

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);
}
Also used : PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) LinkedList(java.util.LinkedList) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 22 with JobFieldModel

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) DatabaseConfiguredFieldTest(com.synopsys.integration.alert.util.DatabaseConfiguredFieldTest)

Example 23 with JobFieldModel

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) DatabaseConfiguredFieldTest(com.synopsys.integration.alert.util.DatabaseConfiguredFieldTest)

Example 24 with JobFieldModel

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;
}
Also used : HashSet(java.util.HashSet) CommonChannelDistributionValidator(com.synopsys.integration.alert.api.channel.CommonChannelDistributionValidator) JiraCloudDescriptor(com.synopsys.integration.alert.channel.jira.cloud.descriptor.JiraCloudDescriptor) Component(org.springframework.stereotype.Component) JiraCloudChannelKey(com.synopsys.integration.alert.descriptor.api.JiraCloudChannelKey) JiraFieldMappingValidator(com.synopsys.integration.alert.api.channel.jira.validation.JiraFieldMappingValidator) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) DistributionConfigurationValidator(com.synopsys.integration.alert.common.descriptor.validator.DistributionConfigurationValidator) ConfigurationFieldValidator(com.synopsys.integration.alert.common.descriptor.validator.ConfigurationFieldValidator) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) ConfigurationFieldValidator(com.synopsys.integration.alert.common.descriptor.validator.ConfigurationFieldValidator) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) HashSet(java.util.HashSet)

Example 25 with JobFieldModel

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);
}
Also used : CommonChannelDistributionValidator(com.synopsys.integration.alert.api.channel.CommonChannelDistributionValidator) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)32 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)13 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)13 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)12 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)12 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)12 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)11 Test (org.junit.jupiter.api.Test)11 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)9 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)7 JobPagedModel (com.synopsys.integration.alert.common.rest.model.JobPagedModel)7 HashMap (java.util.HashMap)7 Set (java.util.Set)7 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)6 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)6 GlobalConfigExistsValidator (com.synopsys.integration.alert.common.descriptor.config.GlobalConfigExistsValidator)6 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)6