use of com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus in project blackduck-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.api.common.model.errors.AlertFieldStatus in project blackduck-alert by blackducksoftware.
the class ProxySettingsEnvironmentHandlerFactory method updateFunction.
private EnvironmentProcessingResult updateFunction() {
EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(PROXY_CONFIGURATION_KEYSET);
SettingsProxyModel configModel = new SettingsProxyModel();
configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
configureProxySettings(configModel);
// TODO: Refactor and remove duplicate code after 6.10.0 model package refactor
ValidationResponseModel validationResponseModel = validator.validate(configModel);
if (validationResponseModel.hasErrors()) {
logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
Map<String, AlertFieldStatus> errors = validationResponseModel.getErrors();
for (Map.Entry<String, AlertFieldStatus> error : errors.entrySet()) {
AlertFieldStatus status = error.getValue();
logger.error("Field: '{}' failed with the error: {}", status.getFieldName(), status.getFieldMessage());
}
return EnvironmentProcessingResult.empty();
}
SettingsProxyModel obfuscatedModel = configModel.obfuscate();
obfuscatedModel.getProxyHost().ifPresent(value -> builder.addVariableValue(PROXY_HOST_KEY, value));
obfuscatedModel.getProxyPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_PORT_KEY, value));
obfuscatedModel.getProxyUsername().ifPresent(value -> builder.addVariableValue(PROXY_USERNAME_KEY, value));
obfuscatedModel.getNonProxyHosts().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_NON_PROXY_HOSTS_KEY, value));
if (Boolean.TRUE.equals(obfuscatedModel.getIsProxyPasswordSet())) {
builder.addVariableValue(PROXY_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
}
EnvironmentProcessingResult result = builder.build();
if (result.hasValues()) {
try {
configAccessor.createConfiguration(configModel);
} catch (AlertConfigurationException ex) {
logger.error("Error creating the configuration: {}", ex.getMessage());
}
}
return result;
}
use of com.synopsys.integration.alert.api.common.model.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.");
}
}
use of com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationValidatorTest method verifyMissingAuth.
@Test
void verifyMissingAuth() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, "from", "host");
model.setSmtpAuth(true);
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(2, alertFieldStatuses.size(), "Validation found more or fewer errors than expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals(EmailGlobalConfigurationValidator.REQUIRED_BECAUSE_AUTH, status.getFieldMessage(), "Validation had unexpected field message.");
}
}
use of com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class ResponseBodyBuilder method putErrors.
public ResponseBodyBuilder putErrors(List<AlertFieldStatus> errors) {
JsonObject element = new JsonObject();
for (AlertFieldStatus alertFieldStatus : errors) {
JsonObject statusObject = new JsonObject();
statusObject.addProperty(PROPERTY_KEY_SEVERITY, alertFieldStatus.getSeverity().name());
statusObject.addProperty(PROPERTY_KEY_FIELD_MESSAGE, alertFieldStatus.getFieldMessage());
element.add(alertFieldStatus.getFieldName(), statusObject);
}
map.add(PROPERTY_KEY_ERRORS, element);
return this;
}
Aggregations