]> source.dussan.org Git - archiva.git/commitdiff
when possible rest error must return the field with issue to map it in the ui
authorOlivier Lamy <olamy@apache.org>
Mon, 16 Jan 2012 13:27:37 +0000 (13:27 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 16 Jan 2012 13:27:37 +0000 (13:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1231992 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/RepositoryAdminException.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/RepositoryCommonValidator.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ArchivaRestServiceException.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/ArchivaRestError.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultManagedRepositoriesService.java

index 207e41af429baa093fb9b3f8ee743cc7cccf7607..80f77701502d4d4dd1238905b3ed6c50e5b54c35 100644 (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;
+    }
 }
index 2ffc2bfd57750eb1e9e4c396590eec10bc4f7c3c..05756fd481927c6a109369eab8b0d691dfe09370 100644 (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" );
         }
     }
 
index 6e4997ca51a706111612034b307451b96af86b5f..895ac14a0df7ccd193aecda180e0b2ad8e8fac3c 100644 (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;
+    }
 }
index 173077373e19a175c4f2fd21a1d7674654234692..bdfd314ac971bcd9ac5ef26f3f637aae325f322d 100644 (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;
+    }
 }
index 7de4cc5c6d60e90eb2b39f4a2a0816f9d2ea106d..9903a8e3bb871bafdc2269f32f1de272ce4ab480 100644 (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() );
         }
     }