use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class BlackDuckDistributionFieldModelTestAction method validatePatternMatchesProjectVersion.
private Optional<AlertFieldStatus> validatePatternMatchesProjectVersion(Long providerConfigId, String projectVersionNamePattern, String projectNamePattern, Collection<String> configuredProjects) {
if (StringUtils.isNotBlank(projectVersionNamePattern)) {
Pattern compiledProjectVersionPattern = Pattern.compile(projectVersionNamePattern);
Pattern compiledProjectNamePattern = StringUtils.isNotBlank(projectNamePattern) ? Pattern.compile(projectNamePattern) : null;
int currentPage = AlertPagedModel.DEFAULT_PAGE_NUMBER;
AlertPagedModel<String> projectsByProviderConfigId = filterAndMapHrefs(providerConfigId, currentPage, configuredProjects, compiledProjectNamePattern);
boolean foundResult = false;
while (!foundResult && currentPage < projectsByProviderConfigId.getTotalPages()) {
List<String> providerProjects = projectsByProviderConfigId.getModels();
foundResult = providerProjects.stream().anyMatch(href -> iteratePagesAndCheck(versionCurrentPage -> blackDuckDataAccessor.getProjectVersionNamesByHref(providerConfigId, href, versionCurrentPage), versionNames -> versionNames.stream().anyMatch(versionName -> compiledProjectVersionPattern.matcher(versionName).matches()), Boolean.FALSE).isEmpty());
currentPage++;
projectsByProviderConfigId = filterAndMapHrefs(providerConfigId, currentPage, configuredProjects, compiledProjectNamePattern);
}
if (!foundResult) {
return Optional.of(AlertFieldStatus.warning(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN, "Does not match any of the project versions."));
}
}
return Optional.empty();
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class BlackDuckDistributionFieldModelTestAction method testConfig.
@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
ArrayList<AlertFieldStatus> fieldStatuses = new ArrayList<>();
Optional<Long> optionalProviderConfigId = registeredFieldValues.getLong(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
if (optionalProviderConfigId.isPresent()) {
Long providerConfigId = optionalProviderConfigId.get();
boolean filterByProjects = registeredFieldValues.getBoolean(ProviderDescriptor.KEY_FILTER_BY_PROJECT).orElse(false);
if (filterByProjects) {
Collection<String> configuredProjects = registeredFieldValues.getAllStrings(ProviderDescriptor.KEY_CONFIGURED_PROJECT);
validateSelectedProjectExists(providerConfigId, configuredProjects).ifPresent(fieldStatuses::add);
Optional<String> optionalProjectNamePattern = registeredFieldValues.getString(ProviderDescriptor.KEY_PROJECT_NAME_PATTERN);
optionalProjectNamePattern.flatMap(projectNamePattern -> validatePatternMatchesProject(providerConfigId, projectNamePattern)).ifPresent(fieldStatuses::add);
registeredFieldValues.getString(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN).flatMap(projectVersionNamePattern -> validatePatternMatchesProjectVersion(providerConfigId, projectVersionNamePattern, optionalProjectNamePattern.orElse(null), configuredProjects)).ifPresent(fieldStatuses::add);
}
BlackDuckProperties blackDuckProperties = null;
Optional<ConfigurationModel> providerConfigurationOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigurationOptional.isPresent()) {
ConfigurationModel providerConfiguration = providerConfigurationOptional.get();
StatefulProvider statefulProvider = blackDuckProvider.createStatefulProvider(providerConfiguration);
blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
}
if (null != blackDuckProperties) {
BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
if (!blackDuckAPITokenValidator.isApiTokenValid()) {
fieldStatuses.add(AlertFieldStatus.error(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, "User permission failed, cannot read notifications from Black Duck."));
}
}
} else {
fieldStatuses.add(AlertFieldStatus.error(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, "A provider configuration is required"));
}
if (MessageResult.hasFieldStatusBySeverity(fieldStatuses, FieldStatusSeverity.ERROR)) {
return new MessageResult("There were errors with the BlackDuck provider fields", fieldStatuses);
}
return new MessageResult("Successfully tested BlackDuck provider fields", fieldStatuses);
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class AuthenticationConfigurationValidatorTest method hasSamlMetadataFile.
@Test
public void hasSamlMetadataFile() {
Map<String, FieldValueModel> keyToValues = createValidSamlValues();
keyToValues.remove(AuthenticationDescriptor.KEY_SAML_METADATA_URL);
keyToValues.remove(AuthenticationDescriptor.KEY_SAML_ENTITY_BASE_URL);
FilePersistenceUtil filePersistenceUtil = Mockito.mock(FilePersistenceUtil.class);
Mockito.when(filePersistenceUtil.uploadFileExists(Mockito.anyString())).thenReturn(true);
AuthenticationConfigurationFieldModelValidator authenticationConfigurationValidator = new AuthenticationConfigurationFieldModelValidator(filePersistenceUtil);
Set<AlertFieldStatus> alertFieldStatuses = authenticationConfigurationValidator.validate(new FieldModel(new AuthenticationDescriptorKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), keyToValues));
assertEquals(1, alertFieldStatuses.size());
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class RoleActions method validateWithoutChecks.
@Override
protected ValidationActionResponse validateWithoutChecks(RolePermissionModel resource) {
ValidationResponseModel responseModel;
List<AlertFieldStatus> alertFieldStatus = fullyValidateRoleNameField(resource);
if (alertFieldStatus.isEmpty()) {
responseModel = ValidationResponseModel.success("The role name is valid");
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
responseModel = ValidationResponseModel.fromStatusCollection("There were problems with the role configuration", alertFieldStatus);
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationValidatorTest method verifyEmptyConfig.
@Test
void verifyEmptyConfig() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(3, alertFieldStatuses.size(), "Validation found more or fewer errors than expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals(ConfigurationFieldValidator.REQUIRED_FIELD_MISSING_MESSAGE, status.getFieldMessage(), "Validation had unexpected field message.");
}
}
Aggregations