Search in sources :

Example 1 with FieldEnum

use of com.blackducksoftware.integration.validator.FieldEnum in project hub-alert by blackducksoftware.

the class GlobalHubConfigActions method validateHubConfiguration.

public void validateHubConfiguration(final HubServerConfigBuilder hubServerConfigBuilder) throws AlertFieldException {
    final AbstractValidator validator = hubServerConfigBuilder.createValidator();
    final ValidationResults results = validator.assertValid();
    if (!results.getResultMap().isEmpty()) {
        final Map<String, String> fieldErrors = new HashMap<>();
        for (final Entry<FieldEnum, Set<ValidationResult>> result : results.getResultMap().entrySet()) {
            final Set<ValidationResult> validationResult = result.getValue();
            final List<String> errors = new ArrayList<>();
            for (final ValidationResult currentValidationResult : validationResult) {
                errors.add(currentValidationResult.getMessage());
            }
            fieldErrors.put(result.getKey().getKey(), StringUtils.join(errors, " , "));
        }
        throw new AlertFieldException("There were issues with the configuration.", fieldErrors);
    }
}
Also used : Set(java.util.Set) AbstractValidator(com.blackducksoftware.integration.validator.AbstractValidator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) ValidationResult(com.blackducksoftware.integration.validator.ValidationResult) FieldEnum(com.blackducksoftware.integration.validator.FieldEnum) ValidationResults(com.blackducksoftware.integration.validator.ValidationResults)

Example 2 with FieldEnum

use of com.blackducksoftware.integration.validator.FieldEnum in project hub-alert by blackducksoftware.

the class LoginActions method validateHubConfiguration.

public void validateHubConfiguration(final HubServerConfigBuilder hubServerConfigBuilder) throws AlertFieldException {
    final AbstractValidator validator = hubServerConfigBuilder.createValidator();
    final ValidationResults results = validator.assertValid();
    if (!results.getResultMap().isEmpty()) {
        final Map<String, String> fieldErrors = new HashMap<>();
        for (final Entry<FieldEnum, Set<ValidationResult>> result : results.getResultMap().entrySet()) {
            final Set<ValidationResult> validationResult = result.getValue();
            final List<String> errors = new ArrayList<>();
            for (final ValidationResult currentValidationResult : validationResult) {
                errors.add(currentValidationResult.getMessage());
            }
            final String key = result.getKey().getKey();
            final String errorMessage = StringUtils.join(errors, " , ");
            fieldErrors.put(key, errorMessage);
        }
        throw new AlertFieldException("There were issues with the configuration.", fieldErrors);
    }
}
Also used : Set(java.util.Set) AbstractValidator(com.blackducksoftware.integration.validator.AbstractValidator) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) ValidationResult(com.blackducksoftware.integration.validator.ValidationResult) FieldEnum(com.blackducksoftware.integration.validator.FieldEnum) ValidationResults(com.blackducksoftware.integration.validator.ValidationResults)

Aggregations

AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)2 AbstractValidator (com.blackducksoftware.integration.validator.AbstractValidator)2 FieldEnum (com.blackducksoftware.integration.validator.FieldEnum)2 ValidationResult (com.blackducksoftware.integration.validator.ValidationResult)2 ValidationResults (com.blackducksoftware.integration.validator.ValidationResults)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2