public void addValidationError( ValidationMessage message ) { getValidationErrors().add( message ); this.valid = false; }
protected void handleInvalidConfigurationException(InvalidConfigurationException e) throws PlexusResourceException { getLogger().debug("Configuration error!", e); ErrorResponse nexusErrorResponse; ValidationResponse vr = e.getValidationResponse(); if (vr != null && vr.getValidationErrors().size() > 0) { org.sonatype.configuration.validation.ValidationMessage vm = vr.getValidationErrors().get(0); nexusErrorResponse = getNexusErrorResponse(vm.getKey(), vm.getShortMessage()); } else { nexusErrorResponse = getNexusErrorResponse("*", e.getMessage()); } throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", nexusErrorResponse); }
@Override protected List<ValidationErrorXO> getValidationErrors(final InvalidConfigurationException exception) { final ValidationResponse validationResponse = exception.getValidationResponse(); if (validationResponse != null) { final List<ValidationMessage> validationErrors = validationResponse.getValidationErrors(); if (validationErrors != null && !validationErrors.isEmpty()) { return Lists.transform(validationErrors, new Function<ValidationMessage, ValidationErrorXO>() { @Nullable @Override public ValidationErrorXO apply(@Nullable final ValidationMessage validationMessage) { if (validationMessage != null) { return new ValidationErrorXO(validationMessage.getKey(), validationMessage.getMessage()); } return null; } }); } } return Lists.newArrayList(new ValidationErrorXO(exception.getMessage())); }
protected void handleInvalidConfigurationException(InvalidConfigurationException e) throws PlexusResourceException { getLogger().debug("Configuration error!", e); ErrorResponse errorResponse; ValidationResponse vr = e.getValidationResponse(); if (vr != null && vr.getValidationErrors().size() > 0) { ValidationMessage vm = vr.getValidationErrors().get(0); errorResponse = getErrorResponse(vm.getKey(), vm.getShortMessage()); } else { errorResponse = getErrorResponse("*", e.getMessage()); } throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", errorResponse); }
public String getMessage() { StringWriter sw = new StringWriter(); sw.append( super.getMessage() ); if ( getValidationResponse() != null ) { if ( getValidationResponse().getValidationErrors().size() > 0 ) { sw.append( "\nValidation errors follows:\n" ); for ( ValidationMessage error : getValidationResponse().getValidationErrors() ) { sw.append( error.toString() ); } sw.append( "\n" ); } if ( getValidationResponse().getValidationWarnings().size() > 0 ) { sw.append( "\nValidation warnings follows:\n" ); for ( ValidationMessage warning : getValidationResponse().getValidationWarnings() ) { sw.append( warning.toString() ); } sw.append( "\n" ); } } return sw.toString(); }
protected void handleInvalidConfigurationException( InvalidConfigurationException e ) throws PlexusResourceException { getLogger().warn( "Configuration error!", e ); ErrorResponse errorResponse; ValidationResponse vr = e.getValidationResponse(); if ( vr != null && vr.getValidationErrors().size() > 0 ) { ValidationMessage vm = vr.getValidationErrors().get( 0 ); errorResponse = getErrorResponse( vm.getKey(), vm.getShortMessage() ); } else { errorResponse = getErrorResponse( "*", e.getMessage() ); } throw new PlexusResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", errorResponse ); }
protected void dumpValidationErrors( final ValidationResponse response ) if ( response.getValidationErrors().size() > 0 || response.getValidationWarnings().size() > 0 ) if ( response.getValidationErrors().size() > 0 ) for ( ValidationMessage msg : response.getValidationErrors() )
protected void handleConfigurationException(ConfigurationException e) throws PlexusResourceException { getLogger().debug("Configuration error!", e); ErrorResponse nexusErrorResponse; if (InvalidConfigurationException.class.isAssignableFrom(e.getClass())) { ValidationResponse vr = ((InvalidConfigurationException) e).getValidationResponse(); if (vr != null && vr.getValidationErrors().size() > 0) { ValidationMessage vm = vr.getValidationErrors().get(0); nexusErrorResponse = getNexusErrorResponse(vm.getKey(), vm.getShortMessage()); } else { nexusErrorResponse = getNexusErrorResponse("*", e.getMessage()); } } else { nexusErrorResponse = getNexusErrorResponse("*", e.getMessage()); } throw new PlexusResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", nexusErrorResponse); }
protected void handleInvalidConfigurationException( InvalidConfigurationException e ) throws PlexusResourceException { getLogger().warn( "Configuration error!", e ); ErrorResponse nexusErrorResponse; ValidationResponse vr = e.getValidationResponse(); if ( vr != null && vr.getValidationErrors().size() > 0 ) { org.sonatype.configuration.validation.ValidationMessage vm = vr.getValidationErrors().get( 0 ); nexusErrorResponse = getNexusErrorResponse( vm.getKey(), vm.getShortMessage() ); } else { nexusErrorResponse = getNexusErrorResponse( "*", e.getMessage() ); } throw new PlexusResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", nexusErrorResponse ); }
protected void handleConfigurationException( ConfigurationException e ) throws PlexusResourceException { getLogger().warn( "Configuration error!", e ); ErrorResponse nexusErrorResponse; if ( InvalidConfigurationException.class.isAssignableFrom( e.getClass() ) ) { ValidationResponse vr = ( (InvalidConfigurationException) e ).getValidationResponse(); if ( vr != null && vr.getValidationErrors().size() > 0 ) { ValidationMessage vm = vr.getValidationErrors().get( 0 ); nexusErrorResponse = getNexusErrorResponse( vm.getKey(), vm.getShortMessage() ); } else { nexusErrorResponse = getNexusErrorResponse( "*", e.getMessage() ); } } else { nexusErrorResponse = getNexusErrorResponse( "*", e.getMessage() ); } throw new PlexusResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Configuration error.", nexusErrorResponse ); }
if ( vr.getValidationErrors().size() > 0 )
public void createUserRoleMapping( CUserRoleMapping userRoleMapping, SecurityValidationContext context ) throws InvalidConfigurationException { if ( context == null ) { context = this.initializeContext(); } try { // this will throw a NoSuchRoleMappingException, if there isn't one readUserRoleMapping( userRoleMapping.getUserId(), userRoleMapping.getSource() ); ValidationResponse vr = new ValidationResponse(); vr.addValidationError( new ValidationMessage( "*", "User Role Mapping for user '" + userRoleMapping.getUserId() + "' already exists." ) ); throw new InvalidConfigurationException( vr ); } catch ( NoSuchRoleMappingException e ) { // expected } ValidationResponse vr = validator.validateUserRoleMapping( context, userRoleMapping, false ); if ( vr.getValidationErrors().size() > 0 ) { throw new InvalidConfigurationException( vr ); } getConfiguration().addUserRoleMapping( userRoleMapping ); logValidationWarnings( vr ); }
public void updateUserRoleMapping( CUserRoleMapping userRoleMapping, SecurityValidationContext context ) throws InvalidConfigurationException, NoSuchRoleMappingException { if ( context == null ) { context = initializeContext(); } if ( readUserRoleMapping( userRoleMapping.getUserId(), userRoleMapping.getSource() ) == null ) { ValidationResponse vr = new ValidationResponse(); vr.addValidationError( new ValidationMessage( "*", "No User Role Mapping found for user '" + userRoleMapping.getUserId() + "'." ) ); throw new InvalidConfigurationException( vr ); } ValidationResponse vr = validator.validateUserRoleMapping( context, userRoleMapping, true ); if ( vr.getValidationErrors().size() > 0 ) { throw new InvalidConfigurationException( vr ); } deleteUserRoleMapping( userRoleMapping.getUserId(), userRoleMapping.getSource() ); getConfiguration().addUserRoleMapping( userRoleMapping ); }
/** * A method to append a validation response to this validation response. The errors list and warnings list are * simply appended, and the isValid is logically AND-ed and isModified is logically OR-ed. * * @param validationResponse */ public void append( ValidationResponse validationResponse ) { for ( ValidationMessage msg : validationResponse.getValidationErrors() ) { if ( getValidationError( msg.getKey() ) != null ) { msg.setKey( msg.getKey() + "(" + key++ + ")" ); } addValidationError( msg ); } for ( ValidationMessage msg : validationResponse.getValidationWarnings() ) { if ( getValidationWarning( msg.getKey() ) != null ) { msg.setKey( msg.getKey() + "(" + key++ + ")" ); } addValidationWarning( msg ); } setValid( isValid() && validationResponse.isValid() ); setModified( isModified() || validationResponse.isModified() ); }