private Repository createRepository( final String role, final String hint ) throws InvalidConfigurationException { try { return Repository.class.cast( plexusContainer.lookup( role, hint ) ); } catch ( ComponentLookupException e ) { throw new InvalidConfigurationException( "Could not lookup a new instance of Repository!", e ); } } }
@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())); }
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 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 checkValidationResponse( ValidationResponse response ) throws ConfigurationException { if ( response != null && !response.isValid() ) { throw new InvalidConfigurationException( response ); } }
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); }
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 ); }
protected LocalRepositoryStorage getLocalRepositoryStorage( String repoId, String provider ) throws InvalidConfigurationException { try { return getPlexusContainer().lookup( LocalRepositoryStorage.class, provider ); } catch ( ComponentLookupException e ) { throw new InvalidConfigurationException( "Repository " + repoId + " have local storage with unsupported provider: " + provider, e ); } }
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); }
protected RemoteRepositoryStorage getRemoteRepositoryStorage( final String repoId, final String remoteUrl, final String provider ) throws InvalidConfigurationException { try { final String mungledHint = remoteProviderHintFactory.getRoleHint( remoteUrl, provider ); return getPlexusContainer().lookup( RemoteRepositoryStorage.class, mungledHint ); } catch ( ComponentLookupException e ) { throw new InvalidConfigurationException( "Repository " + repoId + " have remote storage with unsupported provider: " + provider, e ); } catch ( IllegalArgumentException e ) { throw new InvalidConfigurationException( "Repository " + repoId + " have remote storage with unsupported provider: " + provider, 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 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 validate( CRepositoryTarget target ) throws InvalidConfigurationException { ValidationResponse response = validator.validateRepositoryTarget( null, target ); if ( !response.isValid() ) { throw new InvalidConfigurationException( response ); } }
protected void validate( CPathMappingItem pathItem ) throws InvalidConfigurationException { ValidationResponse response = this.validator.validateGroupsSettingPathMappingItem( null, pathItem ); if ( !response.isValid() ) { throw new InvalidConfigurationException( response ); } }
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); } }
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 ); } }
public void updateConfiguration( Configuration newConfig ) throws ConfigurationException { try { lock.lock(); newConfig.setVersion( Configuration.MODEL_VERSION ); ValidationResponse validationResponse = this.validateConfig( newConfig ); if ( !validationResponse.isValid() ) { throw new InvalidConfigurationException( validationResponse ); } this.configuration = newConfig; this.save(); } finally { lock.unlock(); } }
protected void validateRepository( CRepository settings, boolean create ) throws ConfigurationException { ApplicationValidationContext ctx = getRepositoryValidationContext(); if ( !create && !StringUtils.isEmpty( settings.getId() ) ) { // remove "itself" from the list to avoid hitting "duplicate repo" problem ctx.getExistingRepositoryIds().remove( settings.getId() ); } ValidationResponse vr = configurationValidator.validateRepository( ctx, settings ); if ( !vr.isValid() ) { throw new InvalidConfigurationException( vr ); } }