]> source.dussan.org Git - archiva.git/commitdiff
[MRM-494] leaving repository ID blank on the add repository page goes to the edit...
authorJoakim Erdfelt <joakime@apache.org>
Mon, 24 Sep 2007 23:16:50 +0000 (23:16 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Mon, 24 Sep 2007 23:16:50 +0000 (23:16 +0000)
Spliting webwork definition of INPUT into ADD/EDIT, and correcting validations.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@579016 13f79535-47bb-0310-9956-ffa450edef68

archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java
archiva-web/archiva-webapp/src/main/resources/xwork.xml

index d09f762fcbc7f1170e9904caa4ef0b9245a58fba..d004cdd82b5494cfd6ecc97eea9c0b469b3d4224 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.maven.archiva.web.action.admin.repositories;
  */
 
 import com.opensymphony.xwork.Preparable;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.configuration.Configuration;
@@ -32,9 +33,11 @@ import org.codehaus.plexus.scheduler.CronExpressionValidator;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
- * Configures the application repositories.
+ * Configures the managed repositories.
  *
  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRepositoryAction"
  */
@@ -52,6 +55,15 @@ public class ConfigureRepositoryAction
      */
     protected RoleManager roleManager;
 
+    private static final List<String> VALID_MODES;
+
+    static
+    {
+        VALID_MODES = new ArrayList<String>();
+        VALID_MODES.add( "add" );
+        VALID_MODES.add( "edit" );
+    }
+
     public String add()
     {
         this.mode = "add";
@@ -59,7 +71,7 @@ public class ConfigureRepositoryAction
         this.repository.setReleases( true );
         this.repository.setScanned( true );
 
-        return INPUT;
+        return this.mode;
     }
 
     public String delete()
@@ -92,22 +104,22 @@ public class ConfigureRepositoryAction
             catch ( IOException e )
             {
                 addActionError( "Unable to delete repository: " + e.getMessage() );
-                result = INPUT;
+                result = ERROR;
             }
             catch ( RoleManagerException e )
             {
                 addActionError( "Unable to delete repository: " + e.getMessage() );
-                result = INPUT;
+                result = ERROR;
             }
             catch ( InvalidConfigurationException e )
             {
                 addActionError( "Unable to delete repository: " + e.getMessage() );
-                result = INPUT;
+                result = ERROR;
             }
             catch ( RegistryException e )
             {
                 addActionError( "Unable to delete repository: " + e.getMessage() );
-                result = INPUT;
+                result = ERROR;
             }
         }
 
@@ -136,25 +148,35 @@ public class ConfigureRepositoryAction
 
     public String save()
     {
-        String repoId = repository.getId();
+        // Ensure a proper mode is set.
+        if ( StringUtils.isBlank( this.mode ) )
+        {
+            addActionError( "Unable to process save request. edit mode undefined. " );
+            return ERROR;
+        }
+
+        if ( !VALID_MODES.contains( this.mode.toLowerCase() ) )
+        {
+            addActionError( "Unable to process save request. edit mode is invalid." );
+            return ERROR;
+        }
 
+        // Ensure that the fields are valid.
         Configuration configuration = archivaConfiguration.getConfiguration();
         boolean containsError = validateFields( configuration );
 
-        if ( containsError && StringUtils.equalsIgnoreCase( "add", mode ) )
-        {
-            return INPUT;
-        }
-        else if ( containsError && StringUtils.equalsIgnoreCase( "edit", this.mode ) )
+        if ( containsError )
         {
-            return ERROR;
+            return this.mode.toLowerCase();
         }
 
+        // If we are in edit mode, then remove the old repository configuration.
         if ( StringUtils.equalsIgnoreCase( "edit", this.mode ) )
         {
-            removeRepository( repoId, configuration );
+            removeRepository( repository.getId(), configuration );
         }
 
+        // Save the repository configuration.
         String result;
         try
         {
@@ -164,22 +186,22 @@ public class ConfigureRepositoryAction
         catch ( IOException e )
         {
             addActionError( "I/O Exception: " + e.getMessage() );
-            result = INPUT;
+            result = ERROR;
         }
         catch ( RoleManagerException e )
         {
             addActionError( "Role Manager Exception: " + e.getMessage() );
-            result = INPUT;
+            result = ERROR;
         }
         catch ( InvalidConfigurationException e )
         {
             addActionError( "Invalid Configuration Exception: " + e.getMessage() );
-            result = INPUT;
+            result = ERROR;
         }
         catch ( RegistryException e )
         {
             addActionError( "Configuration Registry Exception: " + e.getMessage() );
-            result = INPUT;
+            result = ERROR;
         }
 
         return result;
@@ -196,14 +218,22 @@ public class ConfigureRepositoryAction
             addFieldError( "repository.id", "You must enter a repository identifier." );
             containsError = true;
         }
-        //if edit mode, do not validate existence of repoId
-        else if ( ( config.getManagedRepositoriesAsMap().containsKey( repoId ) ||
-            config.getRemoteRepositoriesAsMap().containsKey( repoId ) ) &&
-            !StringUtils.equalsIgnoreCase( mode, "edit" ) )
+        // Validate the existance of the repository id, but not in edit mode.
+        else if ( !StringUtils.equalsIgnoreCase( mode, "edit" ) )
         {
-            addFieldError( "repository.id",
-                           "Unable to add new repository with id [" + repoId + "], that id already exists." );
-            containsError = true;
+            if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
+            {
+                addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
+                    + "], that id already exists as a managed repository." );
+                containsError = true;
+            }
+
+            if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
+            {
+                addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
+                    + "], that id already exists as a remote repository." );
+                containsError = true;
+            }
         }
 
         if ( StringUtils.isBlank( repository.getLocation() ) )
index 556120b192c58e53ca0a5123f3b35b2a1347bbb0..11df48425aea68a5960a5c4c5e763fdcf479f9a7 100644 (file)
 
     <action name="saveRepository" class="configureRepositoryAction" method="save">
       <result name="success" type="redirect-action">repositories</result>
+      <result name="add">/WEB-INF/jsp/admin/addRepository.jsp</result>
+      <result name="edit">/WEB-INF/jsp/admin/editRepository.jsp</result>
       <result name="input">/WEB-INF/jsp/admin/editRepository.jsp</result>
-      <result name="error">/WEB-INF/jsp/admin/editRepository.jsp</result>
+      <result name="success" type="redirect-action">repositories</result>
       <interceptor-ref name="configuredPrepareParamsStack"/>
     </action>