when possible rest error must return the field with issue to map it in the ui

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1231992 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-01-16 13:27:37 +00:00
parent 3f44b97372
commit c86c62cd2d
5 changed files with 85 additions and 5 deletions

View File

@ -26,13 +26,43 @@ package org.apache.archiva.admin.model;
public class RepositoryAdminException
extends Exception
{
/**
* can return the field name of bean with issue
* can be <code>null</code>
* @since 1.4-M3
*/
private String fieldName;
public RepositoryAdminException( String s )
{
super( s );
}
public RepositoryAdminException( String s, String fieldName )
{
this( s );
this.fieldName = fieldName;
}
public RepositoryAdminException( String message, Throwable cause )
{
super( message, cause );
}
public RepositoryAdminException( String message, Throwable cause, String fieldName )
{
super( message, cause );
this.fieldName = fieldName;
}
public String getFieldName()
{
return fieldName;
}
public void setFieldName( String fieldName )
{
this.fieldName = fieldName;
}
}

View File

@ -132,7 +132,7 @@ public class RepositoryCommonValidator
if ( !validator.validate( cronExpression ) )
{
throw new RepositoryAdminException( "Invalid cron expression." );
throw new RepositoryAdminException( "Invalid cron expression.", "cronExpression" );
}
}
else
@ -147,7 +147,8 @@ public class RepositoryCommonValidator
{
throw new RepositoryAdminException(
"Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), "
+ "exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
+ "exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).",
"location" );
}
}

View File

@ -30,18 +30,38 @@ public class ArchivaRestServiceException
private String errorKey;
/**
* can return the field name of bean with issue
* can be <code>null</code>
*
* @since 1.4-M3
*/
private String fieldName;
public ArchivaRestServiceException( String message )
{
super( message );
}
public ArchivaRestServiceException( String message, String fieldName )
{
this( message );
this.fieldName = fieldName;
}
public ArchivaRestServiceException( String s, int httpErrorCode )
{
super( s );
this.httpErrorCode = httpErrorCode;
}
public ArchivaRestServiceException( String s, int httpErrorCode, String fieldName )
{
this( s, httpErrorCode );
this.fieldName = fieldName;
}
public int getHttpErrorCode()
{
return httpErrorCode;
@ -61,4 +81,14 @@ public class ArchivaRestServiceException
{
this.errorKey = errorKey;
}
public String getFieldName()
{
return fieldName;
}
public void setFieldName( String fieldName )
{
this.fieldName = fieldName;
}
}

View File

@ -34,6 +34,14 @@ public class ArchivaRestError
private String errorMessage;
/**
* can return the field name of bean with issue
* can be <code>null</code>
*
* @since 1.4-M3
*/
private String fieldName;
public ArchivaRestError()
{
// no op
@ -43,6 +51,7 @@ public class ArchivaRestError
{
errorKey = e.getErrorKey();
errorMessage = e.getMessage();
fieldName = e.getFieldName();
}
public String getErrorKey()
@ -64,4 +73,14 @@ public class ArchivaRestError
{
this.errorMessage = errorMessage;
}
public String getFieldName()
{
return fieldName;
}
public void setFieldName( String fieldName )
{
this.fieldName = fieldName;
}
}

View File

@ -89,7 +89,7 @@ public class DefaultManagedRepositoriesService
catch ( RepositoryAdminException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage() );
throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName() );
}
}
@ -105,7 +105,7 @@ public class DefaultManagedRepositoriesService
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage() );
throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName() );
}
}
@ -123,7 +123,7 @@ public class DefaultManagedRepositoriesService
}
catch ( RepositoryAdminException e )
{
throw new ArchivaRestServiceException( e.getMessage() );
throw new ArchivaRestServiceException( e.getMessage(), e.getFieldName() );
}
}