public void addValidationError( String message ) { ValidationMessage e = new ValidationMessage( String.valueOf( key++ ), message ); addValidationError( e ); }
public String toString() { StringWriter sw = new StringWriter(); sw.append( " o " ).append( getKey() ).append( " - " ).append( getMessage() ); if ( getCause() != null ) { sw.append( "\n" ); sw.append( " Cause:\n" ); getCause().printStackTrace( new PrintWriter( sw ) ); } return sw.toString(); } }
private void logValidationWarnings( final ValidationResponse vr ) { final List<ValidationMessage> validationWarnings = vr.getValidationWarnings(); if ( validationWarnings != null && validationWarnings.size() > 0 ) { final StringBuilder sb = new StringBuilder(); for ( ValidationMessage msg : validationWarnings ) { if ( sb.length() >= 0 ) { sb.append( "," ); } sb.append( " " ).append( msg.toString() ); } logger.warn( "Security configuration has validation warnings:" + sb.toString() ); } }
@Nullable @Override public ValidationErrorXO apply(@Nullable final ValidationMessage validationMessage) { if (validationMessage != null) { return new ValidationErrorXO(validationMessage.getKey(), validationMessage.getMessage()); } return null; } });
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 ValidationMessage getValidationWarning( String key ) { if ( validationWarnings != null ) { for ( ValidationMessage vm : validationWarnings ) { if ( vm.getKey().equals( key ) ) { return vm; } } } return null; }
/** * 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() ); }
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); }
public ValidationMessage getValidationError( String key ) { if ( validationErrors != null ) { for ( ValidationMessage vm : validationErrors ) { if ( vm.getKey().equals( key ) ) { return vm; } } } return null; }
public void addValidationError( String message, Throwable t ) { ValidationMessage e = new ValidationMessage( String.valueOf( key++ ), message, t ); addValidationError( e ); }
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 ); }
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(); }
public void addValidationWarning( String message ) { ValidationMessage e = new ValidationMessage( String.valueOf( key++ ), message ); addValidationWarning( e ); }
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); }
public void validateTime(String key, Date date) throws InvalidConfigurationException { if (date.before(new Date())) { ValidationResponse vr = new ApplicationValidationResponse(); ValidationMessage vm = new ValidationMessage(key, "Time cannot be in the past."); vr.addValidationError(vm); throw new InvalidConfigurationException(vr); } }
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 ); }
public void validateTime( String key, Date date ) throws InvalidConfigurationException { if ( date.before( new Date() ) ) { ValidationResponse vr = new ApplicationValidationResponse(); ValidationMessage vm = new ValidationMessage( key, "Time cannot be in the past." ); vr.addValidationError( vm ); throw new InvalidConfigurationException( vr ); } }
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 ); }
public void validateStartDate(String date) throws InvalidConfigurationException { Calendar cal = Calendar.getInstance(); Date startDate = new Date(Long.parseLong(date)); cal.setTime(startDate); Calendar nowCal = Calendar.getInstance(); nowCal.add(Calendar.DAY_OF_YEAR, -1); nowCal.set(Calendar.HOUR, 0); nowCal.set(Calendar.MINUTE, 0); nowCal.set(Calendar.SECOND, 0); nowCal.set(Calendar.MILLISECOND, 0); // This is checking just the year/month/day, time isn't of concern right now // basic check that the day timestamp is roughly in the correct range if (cal.before(nowCal)) { if (getLogger().isDebugEnabled()) { getLogger().debug("Validation error for startDate: " + startDate.toString()); } ValidationResponse vr = new ApplicationValidationResponse(); ValidationMessage vm = new ValidationMessage("startDate", "Date cannot be in the past."); vr.addValidationError(vm); throw new InvalidConfigurationException(vr); } }